rtree6.test 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. # 2008 Sep 1
  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. #
  12. #
  13. if {![info exists testdir]} {
  14. set testdir [file join [file dirname [info script]] .. .. test]
  15. }
  16. source $testdir/tester.tcl
  17. set testprefix rtree6
  18. ifcapable {!rtree || rtree_int_only} {
  19. finish_test
  20. return
  21. }
  22. # Operator Byte Value
  23. # ----------------------
  24. # = 0x41 ('A')
  25. # <= 0x42 ('B')
  26. # < 0x43 ('C')
  27. # >= 0x44 ('D')
  28. # > 0x45 ('E')
  29. # ----------------------
  30. proc rtree_strategy {sql} {
  31. set ret [list]
  32. db eval "explain $sql" a {
  33. if {$a(opcode) eq "VFilter"} {
  34. lappend ret $a(p4)
  35. }
  36. }
  37. set ret
  38. }
  39. proc query_plan {sql} {
  40. set ret [list]
  41. db eval "explain query plan $sql" a {
  42. lappend ret $a(detail)
  43. }
  44. set ret
  45. }
  46. do_test rtree6-1.1 {
  47. execsql {
  48. CREATE TABLE t2(k INTEGER PRIMARY KEY, v);
  49. CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2);
  50. }
  51. } {}
  52. do_test rtree6-1.2 {
  53. rtree_strategy {SELECT * FROM t1 WHERE x1>10}
  54. } {E0}
  55. do_test rtree6-1.2.1 {
  56. rtree_strategy {SELECT * FROM t1 WHERE x1>10 AND x2 LIKE '%x%'}
  57. } {E0}
  58. do_test rtree6-1.3 {
  59. rtree_strategy {SELECT * FROM t1 WHERE x1<10}
  60. } {C0}
  61. do_test rtree6-1.4 {
  62. rtree_strategy {SELECT * FROM t1,t2 WHERE k=ii AND x1<10}
  63. } {C0}
  64. do_test rtree6-1.5 {
  65. rtree_strategy {SELECT * FROM t1,t2 WHERE k=+ii AND x1<10}
  66. } {C0}
  67. do_eqp_test rtree6.2.1 {
  68. SELECT * FROM t1,t2 WHERE k=+ii AND x1<10
  69. } {
  70. QUERY PLAN
  71. |--SCAN t1 VIRTUAL TABLE INDEX 2:C0
  72. `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
  73. }
  74. do_eqp_test rtree6.2.2 {
  75. SELECT * FROM t1,t2 WHERE k=ii AND x1<10
  76. } {
  77. QUERY PLAN
  78. |--SCAN t1 VIRTUAL TABLE INDEX 2:C0
  79. `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
  80. }
  81. do_eqp_test rtree6.2.3 {
  82. SELECT * FROM t1,t2 WHERE k=ii
  83. } {
  84. QUERY PLAN
  85. |--SCAN t1 VIRTUAL TABLE INDEX 2:
  86. `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
  87. }
  88. do_eqp_test rtree6.2.4.1 {
  89. SELECT * FROM t1,t2 WHERE v=+ii and x1<10 and x2>10
  90. } {
  91. QUERY PLAN
  92. |--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
  93. |--BLOOM FILTER ON t2 (v=?)
  94. `--SEARCH t2 USING AUTOMATIC COVERING INDEX (v=?)
  95. }
  96. do_eqp_test rtree6.2.4.2 {
  97. SELECT * FROM t1,t2 WHERE v=10 and x1<10 and x2>10
  98. } {
  99. QUERY PLAN
  100. |--SCAN t1 VIRTUAL TABLE INDEX 2:C0E1
  101. |--BLOOM FILTER ON t2 (v=?)
  102. `--SEARCH t2 USING AUTOMATIC PARTIAL COVERING INDEX (v=?)
  103. }
  104. do_eqp_test rtree6.2.5 {
  105. SELECT * FROM t1,t2 WHERE k=ii AND x1<v
  106. } {
  107. QUERY PLAN
  108. |--SCAN t1 VIRTUAL TABLE INDEX 2:
  109. `--SEARCH t2 USING INTEGER PRIMARY KEY (rowid=?)
  110. }
  111. do_execsql_test rtree6-3.1 {
  112. CREATE VIRTUAL TABLE t3 USING rtree(id, x1, x2, y1, y2);
  113. INSERT INTO t3 VALUES(NULL, 1, 1, 2, 2);
  114. SELECT * FROM t3 WHERE
  115. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  116. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  117. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  118. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  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;
  121. } {1 1.0 1.0 2.0 2.0}
  122. do_test rtree6.3.2 {
  123. rtree_strategy {
  124. SELECT * FROM t3 WHERE
  125. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  126. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  127. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  128. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5
  129. }
  130. } {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
  131. do_test rtree6.3.3 {
  132. rtree_strategy {
  133. SELECT * FROM t3 WHERE
  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 AND x1>0.5 AND
  137. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  138. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  139. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5
  140. }
  141. } {E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0}
  142. do_execsql_test rtree6-3.4 {
  143. SELECT * FROM t3 WHERE x1>0.5 AND x1>0.8 AND x1>1.1
  144. } {}
  145. do_execsql_test rtree6-3.5 {
  146. SELECT * FROM t3 WHERE
  147. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  148. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  149. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  150. x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND
  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>1.1
  153. } {}
  154. #-------------------------------------------------------------------------
  155. reset_db
  156. do_execsql_test 4.0 {
  157. CREATE VIRTUAL TABLE t1 USING rtree(id,x0,x1,y0,y1);
  158. }
  159. do_execsql_test 4.1 {
  160. DELETE FROM t1 WHERE x0>1 AND x1<2 OR y0<92;
  161. }
  162. expand_all_sql db
  163. finish_test