limbo/testing/analyze.test
2025-12-09 20:02:07 -05:00

105 lines
3 KiB
Tcl
Executable file

#!/usr/bin/env tclsh
set testdir [file dirname $argv0]
source $testdir/tester.tcl
# Things that do work:
do_execsql_test_on_specific_db {:memory:} empty-table {
CREATE TABLE temp (a integer);
ANALYZE temp;
SELECT * FROM sqlite_stat1;
} {}
do_execsql_test_on_specific_db {:memory:} one-row-table {
CREATE TABLE temp (a integer);
INSERT INTO temp VALUES (1);
ANALYZE temp;
SELECT * FROM sqlite_stat1;
} {temp||1}
do_execsql_test_on_specific_db {:memory:} analyze-overwrites {
CREATE TABLE temp (a integer);
INSERT INTO temp VALUES (1);
ANALYZE temp;
INSERT INTO temp VALUES (2);
ANALYZE temp;
SELECT * FROM sqlite_stat1;
} {temp||2}
do_execsql_test_on_specific_db {:memory:} analyze-all {
create table t(a, b);
insert into t values(1, 2);
ANALYZE;
SELECT * FROM sqlite_stat1;
} {t||1}
do_execsql_test_on_specific_db {:memory:} analyze-table-with-pk {
CREATE TABLE temp (a integer primary key);
INSERT INTO temp VALUES (1);
ANALYZE temp;
SELECT * FROM sqlite_stat1;
} {temp||1}
do_execsql_test_on_specific_db {:memory:} analyze-one-database {
ANALYZE main;
} {}
do_execsql_test_on_specific_db {:memory:} analyze-index {
CREATE TABLE temp (a integer, b integer);
CREATE INDEX temp_b ON temp (b);
INSERT INTO temp select value, value + 1 from generate_series(1,100);
ANALYZE temp_b;
SELECT idx, stat FROM sqlite_stat1 where idx = 'temp_b';
} {{temp_b|100 1}}
do_execsql_test_on_specific_db {:memory:} analyze-multi-column-index {
CREATE TABLE t(a, b, c);
CREATE INDEX idx ON t(a, b);
INSERT INTO t VALUES (1, 'x', 100);
INSERT INTO t VALUES (1, 'x', 101);
INSERT INTO t VALUES (1, 'y', 102);
INSERT INTO t VALUES (2, 'x', 103);
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 where idx = 'idx';
} {{idx|4 2 2}}
do_execsql_test_on_specific_db {:memory:} analyze-three-column-index {
CREATE TABLE t(a, b, c, d);
CREATE INDEX idx ON t(a, b, c);
INSERT INTO t VALUES (1, 1, 1, 1);
INSERT INTO t VALUES (1, 1, 1, 2);
INSERT INTO t VALUES (1, 1, 2, 3);
INSERT INTO t VALUES (1, 2, 1, 4);
INSERT INTO t VALUES (2, 1, 1, 5);
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 where idx = 'idx';
} {{idx|5 3 2 2}}
do_execsql_test_on_specific_db {:memory:} analyze-null-values {
CREATE TABLE t(a, b);
CREATE INDEX idx ON t(a, b);
INSERT INTO t VALUES (NULL, 1);
INSERT INTO t VALUES (NULL, 1);
INSERT INTO t VALUES (NULL, 2);
INSERT INTO t VALUES (1, NULL);
INSERT INTO t VALUES (1, NULL);
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 where idx = 'idx';
} {{idx|5 3 2}}
do_execsql_test_on_specific_db {:memory:} analyze-all-identical {
CREATE TABLE t(a, b);
CREATE INDEX idx ON t(a, b);
INSERT INTO t VALUES (1, 1);
INSERT INTO t VALUES (1, 1);
INSERT INTO t VALUES (1, 1);
INSERT INTO t VALUES (1, 1);
ANALYZE;
SELECT idx, stat FROM sqlite_stat1 where idx = 'idx';
} {{idx|4 4 4}}
# Things that don't work:
do_execsql_test_in_memory_error analyze-table-without-rowid-fails {
CREATE TABLE temp (a integer primary key) WITHOUT ROWID;
ANALYZE temp;
} {.*ANALYZE.*not supported.*}