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
19 ifcapable {!rtree || rtree_int_only} {
25 # ----------------------
31 # ----------------------
33 proc rtree_strategy {sql} {
35 db eval "explain $sql" a {
36 if {$a(opcode) eq "VFilter"} {
43 proc query_plan {sql} {
45 db eval "explain query plan $sql" a {
46 lappend ret $a(detail)
53 CREATE TABLE t2(k INTEGER PRIMARY KEY, v);
54 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
59 rtree_strategy {SELECT * FROM t1 WHERE x1>10}
63 rtree_strategy {SELECT * FROM t1 WHERE x1<10}
67 rtree_strategy {SELECT * FROM t1,t2 WHERE k=ii AND x1<10}
71 rtree_strategy {SELECT * FROM t1,t2 WHERE k=+ii AND x1<10}
74 do_eqp_test rtree6.2.1 {
75 SELECT * FROM t1,t2 WHERE k=+ii AND x1<10
77 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0}
78 0 1 1 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)}
81 do_eqp_test rtree6.2.2 {
82 SELECT * FROM t1,t2 WHERE k=ii AND x1<10
84 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0}
85 0 1 1 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)}
88 do_eqp_test rtree6.2.3 {
89 SELECT * FROM t1,t2 WHERE k=ii
91 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:}
92 0 1 1 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)}
95 do_eqp_test rtree6.2.4.1 {
96 SELECT * FROM t1,t2 WHERE v=+ii and x1<10 and x2>10
98 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1}
99 0 1 1 {SEARCH TABLE t2 USING AUTOMATIC COVERING INDEX (v=?)}
101 do_eqp_test rtree6.2.4.2 {
102 SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10
104 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:C0E1}
105 0 1 1 {SEARCH TABLE t2 USING AUTOMATIC COVERING INDEX (v=?)}
108 do_eqp_test rtree6.2.5 {
109 SELECT * FROM t1,t2 WHERE k=ii AND x1<v
111 0 0 0 {SCAN TABLE t1 VIRTUAL TABLE INDEX 2:}
112 0 1 1 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?)}
115 do_execsql_test rtree6-3.1 {
116 CREATE VIRTUAL TABLE t3 USING rtree(id, x1, x2, y1, y2);
117 INSERT INTO t3 VALUES(NULL, 1, 1, 2, 2);
118 SELECT * FROM t3 WHERE
119 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
120 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
121 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
122 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
123 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
124 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5;
125 } {1 1.0 1.0 2.0 2.0}
129 SELECT * FROM t3 WHERE
130 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
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
135 } {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
138 SELECT * FROM t3 WHERE
139 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
140 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
141 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
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
146 } {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
148 do_execsql_test rtree6-3.4 {
149 SELECT * FROM t3 WHERE x1>0.5 AND x1>0.8 AND x1>1.1
151 do_execsql_test rtree6-3.5 {
152 SELECT * FROM t3 WHERE
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 AND x1>0.5 AND
157 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
158 x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>1.1