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 #***********************************************************************
13 set testdir [file dirname $argv0]
14 source $testdir/tester.tcl
15 set testprefix bestindex9
23 proc vtab_command {method args} {
26 return $::create_table
30 set hdl [lindex $args 0]
31 set ::vtab_orderby [$hdl orderby]
32 set ::vtab_distinct [$hdl distinct]
34 return [list orderby 1]
45 proc do_bestindex9_test {tn create select orderby distinct} {
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); }
54 do_test $tn.orderby [list set {} $::vtab_orderby] $orderby
55 do_test $tn.distinct [list set {} $::vtab_distinct] $distinct
60 #-------------------------------------------------------------------------
62 do_bestindex9_test 1.0 {
63 CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2))
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
71 SELECT DISTINCT k1, k2 FROM t1
74 do_bestindex9_test 1.2 {
75 CREATE TABLE x(k1 NOT NULL, k2 NOT NULL, v1, PRIMARY KEY(k1, k2))
77 SELECT DISTINCT k1, k2 FROM t1
80 #-------------------------------------------------------------------------
82 do_bestindex9_test 2 {
83 CREATE TABLE x(c1, c2, c3);
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);
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);
99 CREATE TABLE t2(balls);
100 SELECT DISTINCT c1 FROM t1, t2
101 } {{column 0 desc 0}} 2