# name: test/sql/vacuum/test_analyze.test # description: Test the ANALYZE statement. # group: [vacuum] # The distinct statistics sampling relies on the vector size. require vector_size 1024 require skip_reload # Distinct statistics sampling is different for different vector sizes. require no_vector_verification statement ok ANALYZE; statement ok VACUUM; statement error VACUUM test; ---- Table with name test does not exist statement error ANALYZE test; ---- Table with name test does not exist statement ok CREATE TABLE test (i INT, j INT); statement ok ANALYZE test; statement ok CREATE VIEW testview AS SELECT * FROM test; statement error ANALYZE testview; ---- Can only vacuum or analyze base tables statement ok INSERT INTO test SELECT range % 5000, range % 5000 FROM range(10000); # The approximate unique count is inaccurate due to sampling. query T SELECT stats(i) FROM test LIMIT 1; ---- [Min: 0, Max: 4999][Has Null: false, Has No Null: true][Approx Unique: 10000] query T SELECT stats(j) FROM test LIMIT 1; ---- [Min: 0, Max: 4999][Has Null: false, Has No Null: true][Approx Unique: 10000] statement ok PRAGMA verify_parallelism; statement ok ANALYZE test(i); statement ok VACUUM test(i); statement ok PRAGMA disable_verify_parallelism; # The approximate unique count for i is more accurate now. query T SELECT stats(i) FROM test LIMIT 1; ---- [Min: 0, Max: 4999][Has Null: false, Has No Null: true][Approx Unique: 5661] # The approximate unique count for j is not yet accurate. query T SELECT stats(j) FROM test LIMIT 1; ---- [Min: 0, Max: 4999][Has Null: false, Has No Null: true][Approx Unique: 10000] # Now we analyze the entire table. statement ok PRAGMA verify_parallelism; statement ok ANALYZE test; statement ok PRAGMA disable_verify_parallelism; # The approximate unique count for i and j is more accurate now. query T SELECT stats(i) FROM test LIMIT 1; ---- [Min: 0, Max: 4999][Has Null: false, Has No Null: true][Approx Unique: 5661] query T SELECT stats(j) FROM test LIMIT 1; ---- [Min: 0, Max: 4999][Has Null: false, Has No Null: true][Approx Unique: 5661]