Have SQLITE_ENABLE_SETLK_TIMEOUT builds block when locking a read-lock slot.
[sqlite.git] / test / bestindex9.test
blobd591b30efe507ba20b480d231f16a34713d90d29
1 # 2020-01-29
3 # The author disclaims copyright to this source code.  In place of
4 # a legal notice, here is a blessing:
6 #    May you do good and not evil.
7 #    May you find forgiveness for yourself and forgive others.
8 #    May you share freely, never taking more than you give.
10 #***********************************************************************
11
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix bestindex9
17 ifcapable !vtab {
18   finish_test
19   return
23 proc vtab_command {method args} {
24   switch -- $method {
25     xConnect {
26       return $::create_table
27     }
29     xBestIndex {
30       set hdl [lindex $args 0]
31       set ::vtab_orderby [$hdl orderby]
32       set ::vtab_distinct [$hdl distinct]
34       return [list orderby 1]
35     }
37     xFilter {
38       return ""
39     }
40   }
42   return {}
45 proc do_bestindex9_test {tn create select orderby distinct} {
46   forcedelete test.db2
47   sqlite3 dbtest test.db2
48   register_tcl_module dbtest
50   set ::create_table $create
51   dbtest eval { CREATE VIRTUAL TABLE t1 USING tcl(vtab_command); }
52   dbtest eval $select
54   do_test $tn.orderby [list set {} $::vtab_orderby] $orderby
55   do_test $tn.distinct [list set {} $::vtab_distinct] $distinct
57   dbtest close
60 #-------------------------------------------------------------------------
62 do_bestindex9_test 1.0 {
63   CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2))
64 } {
65   SELECT DISTINCT k1, k2 FROM t1 
66 } {{column 0 desc 0} {column 1 desc 0}} 2
68 do_bestindex9_test 1.1 {
69   CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2)) WITHOUT ROWID
70 } {
71   SELECT DISTINCT k1, k2 FROM t1 
72 } {} 0
74 do_bestindex9_test 1.2 {
75   CREATE TABLE x(k1 NOT NULL, k2 NOT NULL, v1, PRIMARY KEY(k1, k2))
76 } {
77   SELECT DISTINCT k1, k2 FROM t1 
78 } {} 0
80 #-------------------------------------------------------------------------
82 do_bestindex9_test 2 {
83   CREATE TABLE x(c1, c2, c3);
84 } {
85   SELECT DISTINCT c1 FROM t1 ORDER BY c1
86 } {{column 0 desc 0}} 3
88 #-------------------------------------------------------------------------
90 do_bestindex9_test 3 {
91   CREATE TABLE x(c1, c2, c3);
92 } {
93   SELECT DISTINCT c1 FROM t1 GROUP BY c1
94 } {{column 0 desc 0}} 1
96 do_bestindex9_test 4 {
97   CREATE TABLE x(c1, c2, c3);
98 } {
99   CREATE TABLE t2(balls);
100   SELECT DISTINCT c1 FROM t1, t2
101 } {{column 0 desc 0}} 2
104 finish_test