2016-02-22 20:51:08 +01:00
|
|
|
# 2009 Nov 11
|
|
|
|
#
|
|
|
|
# The author disclaims copyright to this source code. In place of
|
|
|
|
# a legal notice, here is a blessing:
|
|
|
|
#
|
|
|
|
# May you do good and not evil.
|
|
|
|
# May you find forgiveness for yourself and forgive others.
|
|
|
|
# May you share freely, never taking more than you give.
|
|
|
|
#
|
|
|
|
#***********************************************************************
|
2024-03-11 20:33:55 +01:00
|
|
|
# TESTRUNNER: shell
|
2016-02-22 20:51:08 +01:00
|
|
|
#
|
|
|
|
# The focus of this file is testing the CLI shell tool. Specifically,
|
|
|
|
# the ".recommend" command.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
# Test plan:
|
|
|
|
#
|
|
|
|
#
|
2017-04-10 22:00:26 +02:00
|
|
|
if {![info exists testdir]} {
|
|
|
|
set testdir [file join [file dirname [info script]] .. .. test]
|
|
|
|
}
|
2016-02-22 20:51:08 +01:00
|
|
|
source $testdir/tester.tcl
|
2017-04-08 20:56:32 +02:00
|
|
|
set testprefix expert1
|
2016-02-22 20:51:08 +01:00
|
|
|
|
2018-01-09 15:30:49 +01:00
|
|
|
if {[info commands sqlite3_expert_new]==""} {
|
|
|
|
finish_test
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-11 15:22:44 +01:00
|
|
|
|
2017-12-19 18:42:13 +01:00
|
|
|
set CLI [test_binary_name sqlite3]
|
|
|
|
set CMD [test_binary_name sqlite3_expert]
|
2016-02-22 20:51:08 +01:00
|
|
|
|
|
|
|
proc squish {txt} {
|
|
|
|
regsub -all {[[:space:]]+} $txt { }
|
|
|
|
}
|
|
|
|
|
|
|
|
proc do_setup_rec_test {tn setup sql res} {
|
|
|
|
reset_db
|
2020-03-20 21:54:28 +01:00
|
|
|
if {[info exists ::set_main_db_name]} {
|
|
|
|
dbconfig_maindbname_icecube db
|
|
|
|
}
|
2016-02-22 20:51:08 +01:00
|
|
|
db eval $setup
|
|
|
|
uplevel [list do_rec_test $tn $sql $res]
|
|
|
|
}
|
|
|
|
|
2017-04-10 18:13:20 +02:00
|
|
|
foreach {tn setup} {
|
|
|
|
1 {
|
|
|
|
if {![file executable $CMD]} { continue }
|
|
|
|
|
|
|
|
proc do_rec_test {tn sql res} {
|
|
|
|
set res [squish [string trim $res]]
|
|
|
|
set tst [subst -nocommands {
|
|
|
|
squish [string trim [exec $::CMD -verbose 0 -sql {$sql;} test.db]]
|
|
|
|
}]
|
|
|
|
uplevel [list do_test $tn $tst $res]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
2 {
|
|
|
|
if {[info commands sqlite3_expert_new]==""} { continue }
|
|
|
|
|
|
|
|
proc do_rec_test {tn sql res} {
|
|
|
|
set expert [sqlite3_expert_new db]
|
|
|
|
$expert sql $sql
|
|
|
|
$expert analyze
|
|
|
|
|
|
|
|
set result [list]
|
|
|
|
for {set i 0} {$i < [$expert count]} {incr i} {
|
2017-04-11 19:43:12 +02:00
|
|
|
set idx [string trim [$expert report $i indexes]]
|
|
|
|
if {$idx==""} {set idx "(no new indexes)"}
|
|
|
|
lappend result $idx
|
2017-04-10 18:13:20 +02:00
|
|
|
lappend result [string trim [$expert report $i plan]]
|
|
|
|
}
|
2016-02-22 20:51:08 +01:00
|
|
|
|
2017-04-10 18:13:20 +02:00
|
|
|
$expert destroy
|
|
|
|
|
|
|
|
set tst [subst -nocommands {set {} [squish [join {$result}]]}]
|
|
|
|
uplevel [list do_test $tn $tst [string trim [squish $res]]]
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 18:42:13 +01:00
|
|
|
3 {
|
2020-03-20 21:54:28 +01:00
|
|
|
if {[info commands sqlite3_expert_new]==""} { continue }
|
|
|
|
set ::set_main_db_name 1
|
|
|
|
}
|
|
|
|
4 {
|
2017-12-19 18:42:13 +01:00
|
|
|
if {![file executable $CLI]} { continue }
|
|
|
|
|
|
|
|
proc do_rec_test {tn sql res} {
|
|
|
|
set res [squish [string trim $res]]
|
|
|
|
set tst [subst -nocommands {
|
|
|
|
squish [string trim [exec $::CLI test.db ".expert" {$sql;}]]
|
|
|
|
}]
|
|
|
|
uplevel [list do_test $tn $tst $res]
|
|
|
|
}
|
|
|
|
}
|
2017-04-10 18:13:20 +02:00
|
|
|
} {
|
|
|
|
|
|
|
|
eval $setup
|
|
|
|
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.1 { CREATE TABLE t1(a, b, c) } {
|
2016-02-22 20:51:08 +01:00
|
|
|
SELECT * FROM t1
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN t1
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.2 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 WHERE b>?;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000062 ON t1(b);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t1 USING INDEX t1_idx_00000062 (b>?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.3 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 WHERE b COLLATE nocase BETWEEN ? AND ?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_3e094c27 ON t1(b COLLATE NOCASE);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t1 USING INDEX t1_idx_3e094c27 (b>? AND b<?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.4 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT a FROM t1 ORDER BY b;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000062 ON t1(b);
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN t1 USING INDEX t1_idx_00000062
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.5 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT a FROM t1 WHERE a=? ORDER BY b;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_000123a7 ON t1(a, b);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t1 USING COVERING INDEX t1_idx_000123a7 (a=?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2019-08-21 19:46:34 +02:00
|
|
|
if 0 {
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.6 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT min(a) FROM t1
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000061 ON t1(a);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t1 USING COVERING INDEX t1_idx_00000061
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
2019-08-21 19:46:34 +02:00
|
|
|
}
|
2016-02-22 20:51:08 +01:00
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.7 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t1(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 ORDER BY a, b, c;
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_033e95fe ON t1(a, b, c);
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN t1 USING COVERING INDEX t1_idx_033e95fe
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-14 21:41:37 +02:00
|
|
|
#do_setup_rec_test $tn.1.8 {
|
|
|
|
# CREATE TABLE t1(a, b, c);
|
|
|
|
#} {
|
|
|
|
# SELECT * FROM t1 ORDER BY a ASC, b COLLATE nocase DESC, c ASC;
|
|
|
|
#} {
|
|
|
|
# CREATE INDEX t1_idx_5be6e222 ON t1(a, b COLLATE NOCASE DESC, c);
|
2021-03-20 16:11:29 +01:00
|
|
|
# 0|0|0|SCAN t1 USING COVERING INDEX t1_idx_5be6e222
|
2017-04-14 21:41:37 +02:00
|
|
|
#}
|
2016-02-22 20:51:08 +01:00
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.8.1 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t1(a COLLATE NOCase, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 WHERE a=?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t1_idx_00000061 ON t1(a);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t1 USING INDEX t1_idx_00000061 (a=?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.8.2 {
|
2017-04-14 21:41:37 +02:00
|
|
|
CREATE TABLE t1(a, b COLLATE nocase, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 ORDER BY a ASC, b DESC, c ASC;
|
|
|
|
} {
|
|
|
|
CREATE INDEX t1_idx_5cb97285 ON t1(a, b DESC, c);
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN t1 USING COVERING INDEX t1_idx_5cb97285
|
2017-04-14 21:41:37 +02:00
|
|
|
}
|
|
|
|
|
2016-02-22 20:51:08 +01:00
|
|
|
|
|
|
|
# Tables with names that require quotes.
|
|
|
|
#
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.9.1 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE "t t"(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM "t t" WHERE a=?
|
|
|
|
} {
|
2021-09-21 22:03:05 +02:00
|
|
|
CREATE INDEX "t t_idx_00000061" ON "t t"(a);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t t USING INDEX t t_idx_00000061 (a=?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.9.2 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE "t t"(a, b, c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM "t t" WHERE b BETWEEN ? AND ?
|
|
|
|
} {
|
2021-09-21 22:03:05 +02:00
|
|
|
CREATE INDEX "t t_idx_00000062" ON "t t"(b);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t t USING INDEX t t_idx_00000062 (b>? AND b<?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Columns with names that require quotes.
|
|
|
|
#
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.10.1 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t3(a, "b b", c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t3 WHERE "b b" = ?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t3_idx_00050c52 ON t3('b b');
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t3 USING INDEX t3_idx_00050c52 (b b=?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.10.2 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t3(a, "b b", c);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t3 ORDER BY "b b"
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t3_idx_00050c52 ON t3('b b');
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN t3 USING INDEX t3_idx_00050c52
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Transitive constraints
|
|
|
|
#
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.11.1 {
|
2016-02-22 20:51:08 +01:00
|
|
|
CREATE TABLE t5(a, b);
|
|
|
|
CREATE TABLE t6(c, d);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t5, t6 WHERE a=? AND b=c AND c=?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t5_idx_000123a7 ON t5(a, b);
|
|
|
|
CREATE INDEX t6_idx_00000063 ON t6(c);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t6 USING INDEX t6_idx_00000063 (c=?)
|
|
|
|
SEARCH t5 USING COVERING INDEX t5_idx_000123a7 (a=? AND b=?)
|
2016-02-22 20:51:08 +01:00
|
|
|
}
|
|
|
|
|
2017-04-04 19:50:31 +02:00
|
|
|
# OR terms.
|
|
|
|
#
|
2017-04-15 18:52:12 +02:00
|
|
|
do_setup_rec_test $tn.12.1 {
|
2017-04-04 19:50:31 +02:00
|
|
|
CREATE TABLE t7(a, b);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t7 WHERE a=? OR b=?
|
|
|
|
} {
|
2017-04-06 20:44:18 +02:00
|
|
|
CREATE INDEX t7_idx_00000062 ON t7(b);
|
2017-04-08 20:56:32 +02:00
|
|
|
CREATE INDEX t7_idx_00000061 ON t7(a);
|
2018-05-04 02:39:43 +02:00
|
|
|
MULTI-INDEX OR
|
2018-12-24 21:21:06 +01:00
|
|
|
INDEX 1
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t7 USING INDEX t7_idx_00000061 (a=?)
|
2018-12-24 21:21:06 +01:00
|
|
|
INDEX 2
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t7 USING INDEX t7_idx_00000062 (b=?)
|
2017-04-04 19:50:31 +02:00
|
|
|
}
|
|
|
|
|
2017-04-15 18:52:12 +02:00
|
|
|
# rowid terms.
|
|
|
|
#
|
|
|
|
do_setup_rec_test $tn.13.1 {
|
|
|
|
CREATE TABLE t8(a, b);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t8 WHERE rowid=?
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t8 USING INTEGER PRIMARY KEY (rowid=?)
|
2017-04-15 18:52:12 +02:00
|
|
|
}
|
|
|
|
do_setup_rec_test $tn.13.2 {
|
|
|
|
CREATE TABLE t8(a, b);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t8 ORDER BY rowid
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN t8
|
2017-04-15 18:52:12 +02:00
|
|
|
}
|
|
|
|
do_setup_rec_test $tn.13.3 {
|
|
|
|
CREATE TABLE t8(a, b);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t8 WHERE a=? ORDER BY rowid
|
|
|
|
} {
|
|
|
|
CREATE INDEX t8_idx_00000061 ON t8(a);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t8 USING INDEX t8_idx_00000061 (a=?)
|
2017-04-15 18:52:12 +02:00
|
|
|
}
|
|
|
|
|
2017-04-17 19:03:08 +02:00
|
|
|
# Triggers
|
|
|
|
#
|
|
|
|
do_setup_rec_test $tn.14 {
|
|
|
|
CREATE TABLE t9(a, b, c);
|
|
|
|
CREATE TABLE t10(a, b, c);
|
|
|
|
CREATE TRIGGER t9t AFTER INSERT ON t9 BEGIN
|
|
|
|
UPDATE t10 SET a=new.a WHERE b = new.b;
|
|
|
|
END;
|
|
|
|
} {
|
|
|
|
INSERT INTO t9 VALUES(?, ?, ?);
|
|
|
|
} {
|
|
|
|
CREATE INDEX t10_idx_00000062 ON t10(b);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t10 USING INDEX t10_idx_00000062 (b=?)
|
2017-04-17 19:03:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-18 22:10:16 +02:00
|
|
|
do_setup_rec_test $tn.15 {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
CREATE TABLE t2(c, d);
|
|
|
|
|
|
|
|
WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
|
|
|
|
INSERT INTO t1 SELECT (i-1)/50, (i-1)/20 FROM s;
|
|
|
|
|
|
|
|
WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
|
|
|
|
INSERT INTO t2 SELECT (i-1)/20, (i-1)/5 FROM s;
|
|
|
|
} {
|
|
|
|
SELECT * FROM t2, t1 WHERE b=? AND d=? AND t2.rowid=t1.rowid
|
|
|
|
} {
|
|
|
|
CREATE INDEX t2_idx_00000064 ON t2(d);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH t2 USING INDEX t2_idx_00000064 (d=?)
|
|
|
|
SEARCH t1 USING INTEGER PRIMARY KEY (rowid=?)
|
2017-04-18 22:10:16 +02:00
|
|
|
}
|
|
|
|
|
2017-12-19 19:56:28 +01:00
|
|
|
do_setup_rec_test $tn.16 {
|
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 WHERE b IS NOT NULL;
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN t1
|
2017-12-19 19:56:28 +01:00
|
|
|
}
|
|
|
|
|
2020-09-17 19:01:16 +02:00
|
|
|
do_setup_rec_test $tn.17.1 {
|
|
|
|
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
|
|
|
} {
|
|
|
|
SELECT * FROM example WHERE a=?
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH example USING INDEX sqlite_autoindex_example_1 (A=?)
|
2020-09-17 19:01:16 +02:00
|
|
|
}
|
|
|
|
do_setup_rec_test $tn.17.2 {
|
|
|
|
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
|
|
|
} {
|
|
|
|
SELECT * FROM example WHERE b=?
|
|
|
|
} {
|
|
|
|
CREATE INDEX example_idx_00000042 ON example(B);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH example USING INDEX example_idx_00000042 (B=?)
|
2020-09-17 19:01:16 +02:00
|
|
|
}
|
|
|
|
do_setup_rec_test $tn.17.3 {
|
|
|
|
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
|
|
|
} {
|
|
|
|
SELECT * FROM example WHERE a=? AND b=?
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH example USING INDEX sqlite_autoindex_example_1 (A=? AND B=?)
|
2020-09-17 19:01:16 +02:00
|
|
|
}
|
|
|
|
do_setup_rec_test $tn.17.4 {
|
|
|
|
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
|
|
|
} {
|
|
|
|
SELECT * FROM example WHERE a=? AND b>?
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH example USING INDEX sqlite_autoindex_example_1 (A=? AND B>?)
|
2020-09-17 19:01:16 +02:00
|
|
|
}
|
|
|
|
do_setup_rec_test $tn.17.5 {
|
|
|
|
CREATE TABLE example (A INTEGER, B INTEGER, C INTEGER, PRIMARY KEY (A,B));
|
|
|
|
} {
|
|
|
|
SELECT * FROM example WHERE a>? AND b=?
|
|
|
|
} {
|
|
|
|
CREATE INDEX example_idx_0000cb3f ON example(B, A);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH example USING INDEX example_idx_0000cb3f (B=? AND A>?)
|
2020-09-17 19:01:16 +02:00
|
|
|
}
|
|
|
|
|
2020-12-11 15:22:44 +01:00
|
|
|
do_setup_rec_test $tn.18.0 {
|
|
|
|
CREATE TABLE SomeObject (
|
|
|
|
a INTEGER PRIMARY KEY,
|
|
|
|
x TEXT GENERATED ALWAYS AS(HEX(a)) VIRTUAL
|
|
|
|
);
|
|
|
|
} {
|
|
|
|
SELECT x FROM SomeObject;
|
|
|
|
} {
|
|
|
|
(no new indexes)
|
2021-03-20 16:11:29 +01:00
|
|
|
SCAN SomeObject
|
2020-12-11 15:22:44 +01:00
|
|
|
}
|
|
|
|
do_setup_rec_test $tn.18.1 {
|
|
|
|
CREATE TABLE SomeObject (
|
|
|
|
a INTEGER PRIMARY KEY,
|
|
|
|
x TEXT GENERATED ALWAYS AS(HEX(a)) VIRTUAL
|
|
|
|
);
|
|
|
|
} {
|
|
|
|
SELECT * FROM SomeObject WHERE x=?;
|
|
|
|
} {
|
|
|
|
CREATE INDEX SomeObject_idx_00000078 ON SomeObject(x);
|
2021-03-20 16:11:29 +01:00
|
|
|
SEARCH SomeObject USING COVERING INDEX SomeObject_idx_00000078 (x=?)
|
2020-12-11 15:22:44 +01:00
|
|
|
}
|
|
|
|
|
2022-08-10 17:29:21 +02:00
|
|
|
|
|
|
|
do_setup_rec_test $tn.19.0 {
|
|
|
|
CREATE TABLE t1("index");
|
|
|
|
} {
|
|
|
|
SELECT * FROM t1 ORDER BY "index";
|
|
|
|
} {
|
|
|
|
CREATE INDEX t1_idx_01a7214e ON t1('index');
|
|
|
|
SCAN t1 USING COVERING INDEX t1_idx_01a7214e
|
|
|
|
}
|
|
|
|
|
2024-10-12 20:00:22 +02:00
|
|
|
ifcapable fts5 {
|
|
|
|
do_setup_rec_test $tn.20.0 {
|
|
|
|
CREATE VIRTUAL TABLE ft USING fts5(a);
|
|
|
|
CREATE TABLE t1(x, y);
|
|
|
|
} {
|
|
|
|
SELECT * FROM ft, t1 WHERE a=x
|
|
|
|
} {
|
|
|
|
CREATE INDEX t1_idx_00000078 ON t1(x);
|
|
|
|
SCAN ft VIRTUAL TABLE INDEX 0:
|
|
|
|
SEARCH t1 USING INDEX t1_idx_00000078 (x=?)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-18 22:10:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
proc do_candidates_test {tn sql res} {
|
|
|
|
set res [squish [string trim $res]]
|
|
|
|
|
|
|
|
set expert [sqlite3_expert_new db]
|
|
|
|
$expert sql $sql
|
|
|
|
$expert analyze
|
|
|
|
|
|
|
|
set candidates [squish [string trim [$expert report 0 candidates]]]
|
|
|
|
$expert destroy
|
|
|
|
|
|
|
|
uplevel [list do_test $tn [list set {} $candidates] $res]
|
2017-04-10 18:13:20 +02:00
|
|
|
}
|
|
|
|
|
2017-04-18 22:10:16 +02:00
|
|
|
|
|
|
|
reset_db
|
2020-03-20 21:54:28 +01:00
|
|
|
do_execsql_test 5.0 {
|
2017-04-18 22:10:16 +02:00
|
|
|
CREATE TABLE t1(a, b);
|
|
|
|
CREATE TABLE t2(c, d);
|
|
|
|
|
|
|
|
WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
|
|
|
|
INSERT INTO t1 SELECT (i-1)/50, (i-1)/20 FROM s;
|
|
|
|
|
|
|
|
WITH s(i) AS ( VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<100)
|
|
|
|
INSERT INTO t2 SELECT (i-1)/20, (i-1)/5 FROM s;
|
2024-09-24 13:26:21 +02:00
|
|
|
|
|
|
|
CREATE INDEX i1 ON t1( lower(a) );
|
2017-04-18 22:10:16 +02:00
|
|
|
}
|
2020-03-20 21:54:28 +01:00
|
|
|
do_candidates_test 5.1 {
|
2017-04-18 22:10:16 +02:00
|
|
|
SELECT * FROM t1,t2 WHERE (b=? OR a=?) AND (c=? OR d=?)
|
|
|
|
} {
|
|
|
|
CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20
|
|
|
|
CREATE INDEX t1_idx_00000061 ON t1(a); -- stat1: 100 50
|
|
|
|
CREATE INDEX t2_idx_00000063 ON t2(c); -- stat1: 100 20
|
|
|
|
CREATE INDEX t2_idx_00000064 ON t2(d); -- stat1: 100 5
|
|
|
|
}
|
|
|
|
|
2020-03-20 21:54:28 +01:00
|
|
|
do_candidates_test 5.2 {
|
2017-04-18 22:10:16 +02:00
|
|
|
SELECT * FROM t1,t2 WHERE a=? AND b=? AND c=? AND d=?
|
|
|
|
} {
|
|
|
|
CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 17
|
|
|
|
CREATE INDEX t2_idx_0001295b ON t2(c, d); -- stat1: 100 20 5
|
|
|
|
}
|
|
|
|
|
2020-03-20 21:54:28 +01:00
|
|
|
do_execsql_test 5.3 {
|
2017-04-18 22:10:16 +02:00
|
|
|
CREATE INDEX t1_idx_00000061 ON t1(a); -- stat1: 100 50
|
|
|
|
CREATE INDEX t1_idx_00000062 ON t1(b); -- stat1: 100 20
|
|
|
|
CREATE INDEX t1_idx_000123a7 ON t1(a, b); -- stat1: 100 50 16
|
|
|
|
|
|
|
|
CREATE INDEX t2_idx_00000063 ON t2(c); -- stat1: 100 20
|
|
|
|
CREATE INDEX t2_idx_00000064 ON t2(d); -- stat1: 100 5
|
|
|
|
CREATE INDEX t2_idx_0001295b ON t2(c, d); -- stat1: 100 20 5
|
|
|
|
|
|
|
|
ANALYZE;
|
|
|
|
SELECT * FROM sqlite_stat1 ORDER BY 1, 2;
|
|
|
|
} {
|
2024-09-24 13:26:21 +02:00
|
|
|
t1 i1 {100 50}
|
2017-04-18 22:10:16 +02:00
|
|
|
t1 t1_idx_00000061 {100 50}
|
|
|
|
t1 t1_idx_00000062 {100 20}
|
|
|
|
t1 t1_idx_000123a7 {100 50 17}
|
|
|
|
t2 t2_idx_00000063 {100 20}
|
|
|
|
t2 t2_idx_00000064 {100 5}
|
|
|
|
t2 t2_idx_0001295b {100 20 5}
|
|
|
|
}
|
|
|
|
|
2024-08-08 17:26:11 +02:00
|
|
|
do_catchsql_test 5.4 {
|
|
|
|
SELECT sqlite_expert_rem(123, 123);
|
|
|
|
} {1 {no such function: sqlite_expert_rem}}
|
|
|
|
do_catchsql_test 5.5 {
|
|
|
|
SELECT sqlite_expert_sample();
|
|
|
|
} {1 {no such function: sqlite_expert_sample}}
|
|
|
|
|
2023-10-23 13:41:41 +02:00
|
|
|
if 0 {
|
2023-09-24 21:38:22 +02:00
|
|
|
do_test expert1-6.0 {
|
|
|
|
catchcmd :memory: {
|
|
|
|
.expert
|
|
|
|
select base64('');
|
|
|
|
.expert
|
|
|
|
select name from pragma_collation_list order by name collate uint;
|
|
|
|
}
|
|
|
|
} {0 {(no new indexes)
|
|
|
|
|
|
|
|
SCAN CONSTANT ROW
|
|
|
|
|
|
|
|
(no new indexes)
|
|
|
|
|
|
|
|
SCAN pragma_collation_list VIRTUAL TABLE INDEX 0:
|
|
|
|
USE TEMP B-TREE FOR ORDER BY
|
|
|
|
}}
|
2023-10-23 13:41:41 +02:00
|
|
|
}
|
2023-09-24 21:38:22 +02:00
|
|
|
|
2024-09-24 17:11:34 +02:00
|
|
|
do_execsql_test 6.0 {
|
|
|
|
CREATE TABLE x1(a, b, c, d);
|
|
|
|
CREATE INDEX x1ab ON x1(a, lower(b));
|
|
|
|
CREATE INDEX x1dcba ON x1(d, b+c, a);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_candidates_test 6.1 {
|
|
|
|
SELECT * FROM x1 WHERE b=? ORDER BY a;
|
|
|
|
} {
|
|
|
|
CREATE INDEX x1_idx_0001267f ON x1(b, a);
|
|
|
|
CREATE INDEX x1_idx_00000062 ON x1(b);
|
|
|
|
}
|
|
|
|
|
2024-10-12 20:00:22 +02:00
|
|
|
#-------------------------------------------------------------------------
|
2024-10-12 20:33:40 +02:00
|
|
|
ifcapable fts5 {
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 7.0 {
|
|
|
|
CREATE VIRTUAL TABLE ft USING fts5(a);
|
|
|
|
CREATE TABLE t1(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_candidates_test 7.1 {
|
|
|
|
SELECT * FROM ft, t1 WHERE a=x
|
|
|
|
} {
|
|
|
|
CREATE INDEX t1_idx_00000078 ON t1(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
register_tcl_module db
|
|
|
|
proc vtab_command {method args} {
|
|
|
|
global G
|
|
|
|
|
|
|
|
switch -- $method {
|
|
|
|
xConnect {
|
|
|
|
return "CREATE TABLE t1(a, b, c);"
|
|
|
|
}
|
|
|
|
|
|
|
|
xBestIndex {
|
|
|
|
return [list]
|
|
|
|
}
|
|
|
|
|
|
|
|
xFilter {
|
|
|
|
return [list sql "SELECT rowid, * FROM t0"]
|
|
|
|
}
|
2024-10-12 20:00:22 +02:00
|
|
|
}
|
2024-10-12 20:33:40 +02:00
|
|
|
|
|
|
|
return {}
|
2024-10-12 20:00:22 +02:00
|
|
|
}
|
2024-10-12 20:33:40 +02:00
|
|
|
|
|
|
|
do_execsql_test 7.2 {
|
|
|
|
CREATE TABLE t0(a, b, c);
|
|
|
|
INSERT INTO t0 VALUES(1, 2, 3), (11, 22, 33);
|
|
|
|
CREATE VIRTUAL TABLE t2 USING tcl(vtab_command);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_execsql_test 7.3 {
|
|
|
|
SELECT * FROM t2
|
|
|
|
} {
|
|
|
|
1 2 3
|
|
|
|
11 22 33
|
|
|
|
}
|
|
|
|
|
|
|
|
do_candidates_test 7.4 {
|
|
|
|
SELECT * FROM ft, t1 WHERE a=x
|
|
|
|
} {
|
|
|
|
CREATE INDEX t1_idx_00000078 ON t1(x);
|
|
|
|
}
|
|
|
|
|
|
|
|
do_test 7.5 {
|
|
|
|
set expert [sqlite3_expert_new db]
|
|
|
|
list [catch { $expert sql "SELECT * FROM ft, t2 WHERE b=1" } msg] $msg
|
|
|
|
} {1 {no such table: t2}}
|
|
|
|
$expert destroy
|
2024-10-20 09:19:38 +02:00
|
|
|
|
|
|
|
reset_db
|
|
|
|
do_execsql_test 7.6 {
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
CREATE TABLE IF NOT EXISTS 'bfts_idx_data'(id INTEGER PRIMARY KEY, block BLOB);
|
|
|
|
CREATE TABLE IF NOT EXISTS 'fts_idx_data'(id INTEGER PRIMARY KEY, block BLOB);
|
|
|
|
INSERT INTO fts_idx_data VALUES(1,X'');
|
|
|
|
INSERT INTO fts_idx_data VALUES(10,X'00000000ff000001000000');
|
|
|
|
CREATE TABLE IF NOT EXISTS 'fts_idx_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID;
|
|
|
|
CREATE TABLE IF NOT EXISTS 'fts_idx_docsize'(id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER);
|
|
|
|
CREATE TABLE IF NOT EXISTS 'fts_idx_config'(k PRIMARY KEY, v) WITHOUT ROWID;
|
|
|
|
INSERT INTO fts_idx_config VALUES('version',4);
|
|
|
|
PRAGMA writable_schema=ON;
|
|
|
|
INSERT INTO sqlite_schema(type,name,tbl_name,rootpage,sql)VALUES('table','fts_idx','fts_idx',0,'CREATE VIRTUAL TABLE fts_idx USING fts5(Title, Description, Channel, Tags, content='''', contentless_delete=1)');
|
|
|
|
|
|
|
|
CREATE TABLE f(x BLOB, y);
|
|
|
|
COMMIT;
|
|
|
|
PRAGMA writable_schema = RESET;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_candidates_test 7.4 {
|
|
|
|
SELECT * FROM fts_idx, f WHERE x = fts_idx.Channel
|
|
|
|
} {
|
|
|
|
CREATE INDEX f_idx_00000078 ON f(x);
|
|
|
|
}
|
2024-10-12 20:00:22 +02:00
|
|
|
}
|
|
|
|
|
2016-02-22 20:51:08 +01:00
|
|
|
finish_test
|