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 #***********************************************************************
14 if {![info exists testdir]} {
15 set testdir [file join [file dirname [info script]] .. .. test]
17 source $testdir/tester.tcl
20 ifcapable {!rtree || rtree_int_only} {
26 # ----------------------
32 # ----------------------
34 proc rtree_strategy {sql} {
36 db eval "explain $sql" a {
37 if {$a(opcode) eq "VFilter"} {
44 proc query_plan {sql} {
46 db eval "explain query plan $sql" a {
47 lappend ret $a(detail)
54 CREATE TABLE t2(k INTEGER PRIMARY KEY, v);
55 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
60 rtree_strategy {SELECT * FROM t1 WHERE x1>10}
62 do_test rtree6-1.2.1 {
63 rtree_strategy {SELECT * FROM t1 WHERE x1>10 AND x2 LIKE '%x%'}
67 rtree_strategy {SELECT * FROM t1 WHERE x1<10}
71 rtree_strategy {SELECT * FROM t1,t2 WHERE k=ii AND x1<10}
75 rtree_strategy {SELECT * FROM t1,t2 WHERE k=+ii AND x1<10}
78 do_eqp_test rtree6.2.1 {
79 SELECT * FROM t1,t2 WHERE k=+ii AND x1<10
82 |--SCAN t1 VIRTUAL TABLE INDEX 2:C0
83 `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
86 do_eqp_test rtree6.2.2 {
87 SELECT * FROM t1,t2 WHERE k=ii AND x1<10
90 |--SCAN t1 VIRTUAL TABLE INDEX 2:C0
91 `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
94 do_eqp_test rtree6.2.3 {
95 SELECT * FROM t1,t2 WHERE k=ii
98 |--SCAN t1 VIRTUAL TABLE INDEX 2:
99 `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
102 do_eqp_test rtree6.2.4.1 {
103 SELECT * FROM t1,t2 WHERE v=+ii and x1<10 and x2>10
106 |--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
107 |--BLOOM FILTER ON t2 (v=?)
108 `--SEARCH t2 USING AUTOMATIC COVERING INDEX (v=?)
110 do_eqp_test rtree6.2.4.2 {
111 SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10
114 |--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
115 |--BLOOM FILTER ON t2 (v=?)
116 `--SEARCH t2 USING AUTOMATIC PARTIAL COVERING INDEX (v=?)
119 do_eqp_test rtree6.2.5 {
120 SELECT * FROM t1,t2 WHERE k=ii AND x1<v
123 |--SCAN t1 VIRTUAL TABLE INDEX 2:
124 `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
127 do_execsql_test rtree6-3.1 {
128 CREATE VIRTUAL TABLE t3 USING rtree(id, x1, x2, y1, y2);
129 INSERT INTO t3 VALUES(NULL, 1, 1, 2, 2);
130 SELECT * FROM t3 WHERE
131 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
132 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
133 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
134 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
135 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
136 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5;
137 } {1 1.0 1.0 2.0 2.0}
141 SELECT * FROM t3 WHERE
142 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
143 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
144 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
145 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5
147 } {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
150 SELECT * FROM t3 WHERE
151 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
152 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
153 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
154 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
155 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
156 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5
158 } {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
160 do_execsql_test rtree6-3.4 {
161 SELECT * FROM t3 WHERE x1>0.5 AND x1>0.8 AND x1>1.1
163 do_execsql_test rtree6-3.5 {
164 SELECT * FROM t3 WHERE
165 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
166 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
167 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
168 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
169 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
170 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>1.1
173 #-------------------------------------------------------------------------
175 do_execsql_test 4.0 {
176 CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1);
178 do_execsql_test 4.1 {
179 DELETE FROM t1 WHERE x0>1 AND x1<2 OR y0<92;