summaryrefslogtreecommitdiffstats
path: root/test/bestindex9.test
blob: d591b30efe507ba20b480d231f16a34713d90d29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# 2020-01-29
#
# 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.
#
#***********************************************************************
# 

set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix bestindex9

ifcapable !vtab {
  finish_test
  return
}


proc vtab_command {method args} {
  switch -- $method {
    xConnect {
      return $::create_table
    }

    xBestIndex {
      set hdl [lindex $args 0]
      set ::vtab_orderby [$hdl orderby]
      set ::vtab_distinct [$hdl distinct]

      return [list orderby 1]
    }

    xFilter {
      return ""
    }
  }

  return {}
}

proc do_bestindex9_test {tn create select orderby distinct} {
  forcedelete test.db2
  sqlite3 dbtest test.db2
  register_tcl_module dbtest

  set ::create_table $create
  dbtest eval { CREATE VIRTUAL TABLE t1 USING tcl(vtab_command); }
  dbtest eval $select

  do_test $tn.orderby [list set {} $::vtab_orderby] $orderby
  do_test $tn.distinct [list set {} $::vtab_distinct] $distinct

  dbtest close
}

#-------------------------------------------------------------------------
#
do_bestindex9_test 1.0 {
  CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2))
} {
  SELECT DISTINCT k1, k2 FROM t1 
} {{column 0 desc 0} {column 1 desc 0}} 2

do_bestindex9_test 1.1 {
  CREATE TABLE x(k1, k2, v1, PRIMARY KEY(k1, k2)) WITHOUT ROWID
} {
  SELECT DISTINCT k1, k2 FROM t1 
} {} 0

do_bestindex9_test 1.2 {
  CREATE TABLE x(k1 NOT NULL, k2 NOT NULL, v1, PRIMARY KEY(k1, k2))
} {
  SELECT DISTINCT k1, k2 FROM t1 
} {} 0

#-------------------------------------------------------------------------
#
do_bestindex9_test 2 {
  CREATE TABLE x(c1, c2, c3);
} {
  SELECT DISTINCT c1 FROM t1 ORDER BY c1
} {{column 0 desc 0}} 3

#-------------------------------------------------------------------------
#
do_bestindex9_test 3 {
  CREATE TABLE x(c1, c2, c3);
} {
  SELECT DISTINCT c1 FROM t1 GROUP BY c1
} {{column 0 desc 0}} 1

do_bestindex9_test 4 {
  CREATE TABLE x(c1, c2, c3);
} {
  CREATE TABLE t2(balls);
  SELECT DISTINCT c1 FROM t1, t2
} {{column 0 desc 0}} 2


finish_test