1# 2011 March 2 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# Make sure the rtreenode() testing function can handle entries with 12# 64-bit rowids. 13# 14 15if {![info exists testdir]} { 16 set testdir [file join [file dirname [info script]] .. .. test] 17} 18source $testdir/tester.tcl 19ifcapable !rtree { finish_test ; return } 20set testprefix rtreeC 21 22do_execsql_test 1.0 { 23 CREATE VIRTUAL TABLE r_tree USING rtree(id, min_x, max_x, min_y, max_y); 24 CREATE TABLE t(x, y); 25} 26 27do_eqp_test 1.1 { 28 SELECT * FROM r_tree, t 29 WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y 30} { 31 0 0 1 {SCAN TABLE t} 32 0 1 0 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:DdBcDbBa} 33} 34 35do_eqp_test 1.2 { 36 SELECT * FROM t, r_tree 37 WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y 38} { 39 0 0 0 {SCAN TABLE t} 40 0 1 1 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:DdBcDbBa} 41} 42 43do_eqp_test 1.3 { 44 SELECT * FROM t, r_tree 45 WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND ?<=max_y 46} { 47 0 0 0 {SCAN TABLE t} 48 0 1 1 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:DdBcDbBa} 49} 50 51do_eqp_test 1.5 { 52 SELECT * FROM t, r_tree 53} { 54 0 0 1 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:} 55 0 1 0 {SCAN TABLE t} 56} 57 58do_execsql_test 2.0 { 59 INSERT INTO t VALUES(0, 0); 60 INSERT INTO t VALUES(0, 1); 61 INSERT INTO t VALUES(0, 2); 62 INSERT INTO t VALUES(0, 3); 63 INSERT INTO t VALUES(0, 4); 64 INSERT INTO t VALUES(0, 5); 65 INSERT INTO t VALUES(0, 6); 66 INSERT INTO t VALUES(0, 7); 67 INSERT INTO t VALUES(0, 8); 68 INSERT INTO t VALUES(0, 9); 69 70 INSERT INTO t SELECT x+1, y FROM t; 71 INSERT INTO t SELECT x+2, y FROM t; 72 INSERT INTO t SELECT x+4, y FROM t; 73 INSERT INTO r_tree SELECT NULL, x-1, x+1, y-1, y+1 FROM t; 74 ANALYZE; 75} 76 77db close 78sqlite3 db test.db 79 80do_eqp_test 2.1 { 81 SELECT * FROM r_tree, t 82 WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y 83} { 84 0 0 1 {SCAN TABLE t} 85 0 1 0 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:DdBcDbBa} 86} 87 88do_eqp_test 2.2 { 89 SELECT * FROM t, r_tree 90 WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND t.x<=max_y 91} { 92 0 0 0 {SCAN TABLE t} 93 0 1 1 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:DdBcDbBa} 94} 95 96do_eqp_test 2.3 { 97 SELECT * FROM t, r_tree 98 WHERE t.x>=min_x AND t.x<=max_x AND t.y>=min_y AND ?<=max_y 99} { 100 0 0 0 {SCAN TABLE t} 101 0 1 1 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:DdBcDbBa} 102} 103 104do_eqp_test 2.5 { 105 SELECT * FROM t, r_tree 106} { 107 0 0 1 {SCAN TABLE r_tree VIRTUAL TABLE INDEX 2:} 108 0 1 0 {SCAN TABLE t} 109} 110 111#------------------------------------------------------------------------- 112# Test that the special CROSS JOIN handling works with rtree tables. 113# 114do_execsql_test 3.1 { 115 CREATE TABLE t1(x); 116 CREATE TABLE t2(y); 117 CREATE VIRTUAL TABLE t3 USING rtree(z, x1,x2, y1,y2); 118} 119 120do_eqp_test 3.2.1 { SELECT * FROM t1 CROSS JOIN t2 } { 121 0 0 0 {SCAN TABLE t1} 122 0 1 1 {SCAN TABLE t2} 123} 124do_eqp_test 3.2.2 { SELECT * FROM t2 CROSS JOIN t1 } { 125 0 0 0 {SCAN TABLE t2} 0 1 1 {SCAN TABLE t1} 126} 127 128do_eqp_test 3.3.1 { SELECT * FROM t1 CROSS JOIN t3 } { 129 0 0 0 {SCAN TABLE t1} 130 0 1 1 {SCAN TABLE t3 VIRTUAL TABLE INDEX 2:} 131} 132do_eqp_test 3.3.2 { SELECT * FROM t3 CROSS JOIN t1 } { 133 0 0 0 {SCAN TABLE t3 VIRTUAL TABLE INDEX 2:} 134 0 1 1 {SCAN TABLE t1} 135} 136 137#-------------------------------------------------------------------- 138# Test that LEFT JOINs are not reordered if the right-hand-side is 139# a virtual table. 140# 141reset_db 142do_execsql_test 4.1 { 143 CREATE TABLE t1(a); 144 CREATE VIRTUAL TABLE t2 USING rtree(b, x1,x2); 145 146 INSERT INTO t1 VALUES(1); 147 INSERT INTO t1 VALUES(2); 148 149 INSERT INTO t2 VALUES(1, 0.0, 0.1); 150 INSERT INTO t2 VALUES(3, 0.0, 0.1); 151} 152 153do_execsql_test 4.2 { 154 SELECT a, b FROM t1 LEFT JOIN t2 ON (+a = +b); 155} {1 1 2 {}} 156 157do_execsql_test 4.3 { 158 SELECT b, a FROM t2 LEFT JOIN t1 ON (+a = +b); 159} {1 1 3 {}} 160 161finish_test 162 163