| OLD | NEW |
| 1 # 2010 August 28 | 1 # 2010 August 28 |
| 2 # | 2 # |
| 3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
| 4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
| 5 # | 5 # |
| 6 # May you do good and not evil. | 6 # May you do good and not evil. |
| 7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
| 8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
| 9 # | 9 # |
| 10 #*********************************************************************** | 10 #*********************************************************************** |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 WITH RECURSIVE | 45 WITH RECURSIVE |
| 46 x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4), | 46 x(x) AS (VALUES(0) UNION ALL SELECT x+1 FROM x WHERE x<4), |
| 47 y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4) | 47 y(y) AS (VALUES(0) UNION ALL SELECT y+1 FROM y WHERE y<4) |
| 48 INSERT INTO rt1 SELECT 200+x+5*y, x*7, x*7+15, y*7+200, y*7+215 FROM x, y; | 48 INSERT INTO rt1 SELECT 200+x+5*y, x*7, x*7+15, y*7+200, y*7+215 FROM x, y; |
| 49 } {} | 49 } {} |
| 50 | 50 |
| 51 # Queries against each of the three clusters */ | 51 # Queries against each of the three clusters */ |
| 52 do_execsql_test rtreeE-1.1 { | 52 do_execsql_test rtreeE-1.1 { |
| 53 SELECT id FROM rt1 WHERE id MATCH Qcircle(0.0, 0.0, 50.0, 3) ORDER BY id; | 53 SELECT id FROM rt1 WHERE id MATCH Qcircle(0.0, 0.0, 50.0, 3) ORDER BY id; |
| 54 } {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24} | 54 } {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24} |
| 55 do_execsql_test rtreeE-1.1x { |
| 56 SELECT id FROM rt1 WHERE id MATCH Qcircle('x:0 y:0 r:50.0 e:3') ORDER BY id; |
| 57 } {0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24} |
| 55 do_execsql_test rtreeE-1.2 { | 58 do_execsql_test rtreeE-1.2 { |
| 56 SELECT id FROM rt1 WHERE id MATCH Qcircle(100.0, 0.0, 50.0, 3) ORDER BY id; | 59 SELECT id FROM rt1 WHERE id MATCH Qcircle(100.0, 0.0, 50.0, 3) ORDER BY id; |
| 57 } {100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 1
19 120 121 122 123 124} | 60 } {100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 1
19 120 121 122 123 124} |
| 58 do_execsql_test rtreeE-1.3 { | 61 do_execsql_test rtreeE-1.3 { |
| 59 SELECT id FROM rt1 WHERE id MATCH Qcircle(0.0, 200.0, 50.0, 3) ORDER BY id; | 62 SELECT id FROM rt1 WHERE id MATCH Qcircle(0.0, 200.0, 50.0, 3) ORDER BY id; |
| 60 } {200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 2
19 220 221 222 223 224} | 63 } {200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 2
19 220 221 222 223 224} |
| 61 | 64 |
| 62 # The Qcircle geometry function gives a lower score to larger leaf-nodes. | 65 # The Qcircle geometry function gives a lower score to larger leaf-nodes. |
| 63 # This causes the 200s to sort before the 100s and the 0s to sort before | 66 # This causes the 200s to sort before the 100s and the 0s to sort before |
| 64 # last. | 67 # last. |
| 65 # | 68 # |
| 66 do_execsql_test rtreeE-1.4 { | 69 do_execsql_test rtreeE-1.4 { |
| 67 SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,3) AND id%100==0 | 70 SELECT id FROM rt1 WHERE id MATCH Qcircle('r:1000 e:3') AND id%100==0 |
| 68 } {200 100 0} | 71 } {200 100 0} |
| 69 | 72 |
| 70 # Exclude odd rowids on a depth-first search | 73 # Exclude odd rowids on a depth-first search |
| 71 do_execsql_test rtreeE-1.5 { | 74 do_execsql_test rtreeE-1.5 { |
| 72 SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,4) ORDER BY +id | 75 SELECT id FROM rt1 WHERE id MATCH Qcircle('r:1000 e:4') ORDER BY +id |
| 73 } {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120
122 124 200 202 204 206 208 210 212 214 216 218 220 222 224} | 76 } {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120
122 124 200 202 204 206 208 210 212 214 216 218 220 222 224} |
| 74 | 77 |
| 75 # Exclude odd rowids on a breadth-first search. | 78 # Exclude odd rowids on a breadth-first search. |
| 76 do_execsql_test rtreeE-1.6 { | 79 do_execsql_test rtreeE-1.6 { |
| 77 SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,5) ORDER BY +id | 80 SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,5) ORDER BY +id |
| 78 } {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120
122 124 200 202 204 206 208 210 212 214 216 218 220 222 224} | 81 } {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120
122 124 200 202 204 206 208 210 212 214 216 218 220 222 224} |
| 79 | 82 |
| 83 # Test that rtree prefers MATCH to lookup-by-rowid. |
| 84 # |
| 85 do_execsql_test rtreeE-1.7 { |
| 86 SELECT id FROM rt1 WHERE id=18 AND id MATCH Qcircle(0,0,1000,5) |
| 87 } {18} |
| 88 |
| 89 |
| 80 # Construct a large 2-D RTree with thousands of random entries. | 90 # Construct a large 2-D RTree with thousands of random entries. |
| 81 # | 91 # |
| 82 do_test rtreeE-2.1 { | 92 do_test rtreeE-2.1 { |
| 83 db eval { | 93 db eval { |
| 84 CREATE TABLE t2(id,x0,x1,y0,y1); | 94 CREATE TABLE t2(id,x0,x1,y0,y1); |
| 85 CREATE VIRTUAL TABLE rt2 USING rtree(id,x0,x1,y0,y1); | 95 CREATE VIRTUAL TABLE rt2 USING rtree(id,x0,x1,y0,y1); |
| 86 BEGIN; | 96 BEGIN; |
| 87 } | 97 } |
| 88 expr srand(0) | 98 expr srand(0) |
| 89 for {set i 1} {$i<=10000} {incr i} { | 99 for {set i 1} {$i<=10000} {incr i} { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 119 # | 129 # |
| 120 set ans [db eval {SELECT id FROM t2 WHERE x1>=0 AND x0<=5000 AND y1>=0 AND y0<=5
000 ORDER BY id}] | 130 set ans [db eval {SELECT id FROM t2 WHERE x1>=0 AND x0<=5000 AND y1>=0 AND y0<=5
000 ORDER BY id}] |
| 121 do_execsql_test rtreeE-2.3 { | 131 do_execsql_test rtreeE-2.3 { |
| 122 SELECT id FROM rt2 WHERE id MATCH breadthfirstsearch(0,5000,0,5000) ORDER BY i
d | 132 SELECT id FROM rt2 WHERE id MATCH breadthfirstsearch(0,5000,0,5000) ORDER BY i
d |
| 123 } $ans | 133 } $ans |
| 124 set ans [db eval {SELECT id FROM t2 WHERE x1>=0 AND x0<=10000 AND y1>=0 AND y0<=
10000 ORDER BY id}] | 134 set ans [db eval {SELECT id FROM t2 WHERE x1>=0 AND x0<=10000 AND y1>=0 AND y0<=
10000 ORDER BY id}] |
| 125 do_execsql_test rtreeE-2.4 { | 135 do_execsql_test rtreeE-2.4 { |
| 126 SELECT id FROM rt2 WHERE id MATCH breadthfirstsearch(0,10000,0,10000) ORDER BY
id | 136 SELECT id FROM rt2 WHERE id MATCH breadthfirstsearch(0,10000,0,10000) ORDER BY
id |
| 127 } $ans | 137 } $ans |
| 128 | 138 |
| 139 |
| 129 finish_test | 140 finish_test |
| OLD | NEW |