xref: /sqlite-3.40.0/test/index9.test (revision 3e380a44)
15aa550cfSdan# 2017 Jun 24
25aa550cfSdan#
35aa550cfSdan# The author disclaims copyright to this source code.  In place of
45aa550cfSdan# a legal notice, here is a blessing:
55aa550cfSdan#
65aa550cfSdan#    May you do good and not evil.
75aa550cfSdan#    May you find forgiveness for yourself and forgive others.
85aa550cfSdan#    May you share freely, never taking more than you give.
95aa550cfSdan#
105aa550cfSdan#***********************************************************************
115aa550cfSdan#
125aa550cfSdan# Test that partial indexes work with bound variables.
135aa550cfSdan#
145aa550cfSdan
155aa550cfSdanset testdir [file dirname $argv0]
165aa550cfSdansource $testdir/tester.tcl
175aa550cfSdanset testprefix index9
185aa550cfSdan
195aa550cfSdanproc sqluses {sql} {
205aa550cfSdan  array unset ::T
215aa550cfSdan  uplevel [list db eval "EXPLAIN $sql" a {
225aa550cfSdan    if {$a(opcode)=="OpenRead"} { set ::T($a(p2)) 1 }
235aa550cfSdan  }]
245aa550cfSdan
255aa550cfSdan  set in [join [array names ::T] ,]
265aa550cfSdan  db eval "SELECT name FROM sqlite_master WHERE rootpage IN ($in) ORDER BY 1"
275aa550cfSdan}
285aa550cfSdan
295aa550cfSdanproc do_sqluses_test {tn sql objects} {
305aa550cfSdan  uplevel [list do_test $tn [list sqluses $sql] $objects]
315aa550cfSdan}
325aa550cfSdan
335aa550cfSdando_execsql_test 1.0 {
345aa550cfSdan  CREATE TABLE t1(x, y);
355aa550cfSdan  CREATE INDEX t1x ON t1(x) WHERE y=45;
365aa550cfSdan}
375aa550cfSdanset y [expr 45]
385aa550cfSdando_sqluses_test 1.1 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1 t1x}
395aa550cfSdanset y [expr 45.1]
405aa550cfSdando_sqluses_test 1.2 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1}
415aa550cfSdanset y [expr 44]
425aa550cfSdando_sqluses_test 1.3 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1}
435aa550cfSdanunset -nocomplain y
445aa550cfSdando_sqluses_test 1.4 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1}
455aa550cfSdanset y [string range "45" 0 end]
465aa550cfSdando_sqluses_test 1.5 { SELECT * FROM t1 WHERE x=? AND y=$y } {t1}
475aa550cfSdan
485aa550cfSdando_execsql_test 2.0 {
495aa550cfSdan  CREATE INDEX t1x2 ON t1(x) WHERE y=-20111000111
505aa550cfSdan}
515aa550cfSdando_sqluses_test 2.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
525aa550cfSdanset y [expr -20111000111]
535aa550cfSdando_sqluses_test 2.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x2}
545aa550cfSdanset y [expr -20111000110]
555aa550cfSdando_sqluses_test 2.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
565aa550cfSdanset y [expr -20111000112]
575aa550cfSdando_sqluses_test 2.4 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
585aa550cfSdan
595aa550cfSdando_execsql_test 3.0 {
605aa550cfSdan  CREATE INDEX t1x3 ON t1(x) WHERE y=9223372036854775807
615aa550cfSdan}
625aa550cfSdanset y [expr 9223372036854775807]
635aa550cfSdando_sqluses_test 3.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x3}
645aa550cfSdanset y [expr 9223372036854775808]
655aa550cfSdando_sqluses_test 3.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
665aa550cfSdanset y [expr 9223372036854775806]
675aa550cfSdando_sqluses_test 3.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
68*3e380a44Sdrhdb cache flush
69*3e380a44Sdrhsqlite3_db_config db QPSG 1
70*3e380a44Sdrhset y [expr 9223372036854775807]
71*3e380a44Sdrhdo_sqluses_test 3.4 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
72*3e380a44Sdrhset y [expr 9223372036854775808]
73*3e380a44Sdrhdo_sqluses_test 3.5 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
74*3e380a44Sdrhsqlite3_db_config db QPSG 0
75*3e380a44Sdrhdb cache flush
765aa550cfSdan
77*3e380a44Sdrh
78*3e380a44Sdrhdo_execsql_test 4.0 {
795aa550cfSdan  CREATE INDEX t1x4 ON t1(x) WHERE y=-9223372036854775808
805aa550cfSdan}
815aa550cfSdanset y [expr -9223372036854775808]
82*3e380a44Sdrhdo_sqluses_test 4.1 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1 t1x4}
835aa550cfSdanset y [expr -9223372036854775807]
84*3e380a44Sdrhdo_sqluses_test 4.2 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
855aa550cfSdanset y [expr -9223372036854775809]
86*3e380a44Sdrhdo_sqluses_test 4.3 { SELECT * FROM t1 WHERE y=$y ORDER BY x } {t1}
875aa550cfSdanset y [expr -9223372036854775808]
88*3e380a44Sdrhdo_sqluses_test 4.4 { SELECT * FROM t1 WHERE $y=y ORDER BY x } {t1 t1x4}
89*3e380a44Sdrhdb cache flush
90*3e380a44Sdrhsqlite3_db_config db QPSG 1
91*3e380a44Sdrhdo_sqluses_test 4.5 { SELECT * FROM t1 WHERE $y=y ORDER BY x } {t1}
92*3e380a44Sdrhsqlite3_db_config db QPSG 0
93*3e380a44Sdrhdb cache flush
945aa550cfSdan
955aa550cfSdanfinish_test
96