select9.test 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. # 2008 June 24
  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. # This file implements regression tests for SQLite library.
  12. #
  13. # $Id: select9.test,v 1.4 2008/07/01 14:39:35 danielk1977 Exp $
  14. # The tests in this file are focused on test compound SELECT statements
  15. # that have any or all of an ORDER BY, LIMIT or OFFSET clauses. As of
  16. # version 3.6.0, SQLite contains code to use SQL indexes where possible
  17. # to optimize such statements.
  18. #
  19. # TODO Points:
  20. #
  21. # * Are there any "column affinity" issues to consider?
  22. set testdir [file dirname $argv0]
  23. source $testdir/tester.tcl
  24. #-------------------------------------------------------------------------
  25. # test_compound_select TESTNAME SELECT RESULT
  26. #
  27. # This command is used to run multiple LIMIT/OFFSET test cases based on
  28. # the single SELECT statement passed as the second argument. The SELECT
  29. # statement may not contain a LIMIT or OFFSET clause. This proc tests
  30. # many statements of the form:
  31. #
  32. # "$SELECT limit $X offset $Y"
  33. #
  34. # for various values of $X and $Y.
  35. #
  36. # The third argument, $RESULT, should contain the expected result of
  37. # the command [execsql $SELECT].
  38. #
  39. # The first argument, $TESTNAME, is used as the base test case name to
  40. # pass to [do_test] for each individual LIMIT OFFSET test case.
  41. #
  42. proc test_compound_select {testname sql result} {
  43. set nCol 1
  44. db eval $sql A {
  45. set nCol [llength $A(*)]
  46. break
  47. }
  48. set nRow [expr {[llength $result] / $nCol}]
  49. set ::compound_sql $sql
  50. do_test $testname {
  51. execsql $::compound_sql
  52. } $result
  53. #return
  54. set iLimitIncr 1
  55. set iOffsetIncr 1
  56. if {[info exists ::G(isquick)] && $::G(isquick) && $nRow>=5} {
  57. set iOffsetIncr [expr $nRow / 5]
  58. set iLimitIncr [expr $nRow / 5]
  59. }
  60. set iLimitEnd [expr $nRow+$iLimitIncr]
  61. set iOffsetEnd [expr $nRow+$iOffsetIncr]
  62. for {set iOffset 0} {$iOffset < $iOffsetEnd} {incr iOffset $iOffsetIncr} {
  63. for {set iLimit 0} {$iLimit < $iLimitEnd} {incr iLimit} {
  64. set ::compound_sql "$sql LIMIT $iLimit"
  65. if {$iOffset != 0} {
  66. append ::compound_sql " OFFSET $iOffset"
  67. }
  68. set iStart [expr {$iOffset*$nCol}]
  69. set iEnd [expr {($iOffset*$nCol) + ($iLimit*$nCol) -1}]
  70. do_test $testname.limit=$iLimit.offset=$iOffset {
  71. execsql $::compound_sql
  72. } [lrange $result $iStart $iEnd]
  73. }
  74. }
  75. }
  76. #-------------------------------------------------------------------------
  77. # test_compound_select_flippable TESTNAME SELECT RESULT
  78. #
  79. # This command is for testing statements of the form:
  80. #
  81. # <simple select 1> <compound op> <simple select 2> ORDER BY <order by>
  82. #
  83. # where each <simple select> is a simple (non-compound) select statement
  84. # and <compound op> is one of "INTERSECT", "UNION ALL" or "UNION".
  85. #
  86. # This proc calls [test_compound_select] twice, once with the select
  87. # statement as it is passed to this command, and once with the positions
  88. # of <select statement 1> and <select statement 2> exchanged.
  89. #
  90. proc test_compound_select_flippable {testname sql result} {
  91. test_compound_select $testname $sql $result
  92. set select [string trim $sql]
  93. set RE {(.*)(UNION ALL|INTERSECT|UNION)(.*)(ORDER BY.*)}
  94. set rc [regexp $RE $select -> s1 op s2 order_by]
  95. if {!$rc} {error "Statement is unflippable: $select"}
  96. set flipsql "$s2 $op $s1 $order_by"
  97. test_compound_select $testname.flipped $flipsql $result
  98. }
  99. #############################################################################
  100. # Begin tests.
  101. #
  102. # Create and populate a sample database.
  103. #
  104. do_test select9-1.0 {
  105. execsql {
  106. CREATE TABLE t1(a, b, c);
  107. CREATE TABLE t2(d, e, f);
  108. BEGIN;
  109. INSERT INTO t1 VALUES(1, 'one', 'I');
  110. INSERT INTO t1 VALUES(3, NULL, NULL);
  111. INSERT INTO t1 VALUES(5, 'five', 'V');
  112. INSERT INTO t1 VALUES(7, 'seven', 'VII');
  113. INSERT INTO t1 VALUES(9, NULL, NULL);
  114. INSERT INTO t1 VALUES(2, 'two', 'II');
  115. INSERT INTO t1 VALUES(4, 'four', 'IV');
  116. INSERT INTO t1 VALUES(6, NULL, NULL);
  117. INSERT INTO t1 VALUES(8, 'eight', 'VIII');
  118. INSERT INTO t1 VALUES(10, 'ten', 'X');
  119. INSERT INTO t2 VALUES(1, 'two', 'IV');
  120. INSERT INTO t2 VALUES(2, 'four', 'VIII');
  121. INSERT INTO t2 VALUES(3, NULL, NULL);
  122. INSERT INTO t2 VALUES(4, 'eight', 'XVI');
  123. INSERT INTO t2 VALUES(5, 'ten', 'XX');
  124. INSERT INTO t2 VALUES(6, NULL, NULL);
  125. INSERT INTO t2 VALUES(7, 'fourteen', 'XXVIII');
  126. INSERT INTO t2 VALUES(8, 'sixteen', 'XXXII');
  127. INSERT INTO t2 VALUES(9, NULL, NULL);
  128. INSERT INTO t2 VALUES(10, 'twenty', 'XL');
  129. COMMIT;
  130. }
  131. } {}
  132. # Each iteration of this loop runs the same tests with a different set
  133. # of indexes present within the database schema. The data returned by
  134. # the compound SELECT statements in the test cases should be the same
  135. # in each case.
  136. #
  137. set iOuterLoop 1
  138. foreach indexes [list {
  139. /* Do not create any indexes. */
  140. } {
  141. CREATE INDEX i1 ON t1(a)
  142. } {
  143. CREATE INDEX i2 ON t1(b)
  144. } {
  145. CREATE INDEX i3 ON t2(d)
  146. } {
  147. CREATE INDEX i4 ON t2(e)
  148. }] {
  149. do_test select9-1.$iOuterLoop.1 {
  150. execsql $indexes
  151. } {}
  152. # Test some 2-way UNION ALL queries. No WHERE clauses.
  153. #
  154. test_compound_select select9-1.$iOuterLoop.2 {
  155. SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2
  156. } {1 one 3 {} 5 five 7 seven 9 {} 2 two 4 four 6 {} 8 eight 10 ten 1 two 2 four 3 {} 4 eight 5 ten 6 {} 7 fourteen 8 sixteen 9 {} 10 twenty}
  157. test_compound_select select9-1.$iOuterLoop.3 {
  158. SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 1
  159. } {1 one 1 two 2 two 2 four 3 {} 3 {} 4 four 4 eight 5 five 5 ten 6 {} 6 {} 7 seven 7 fourteen 8 eight 8 sixteen 9 {} 9 {} 10 ten 10 twenty}
  160. test_compound_select select9-1.$iOuterLoop.4 {
  161. SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 2
  162. } {3 {} 9 {} 6 {} 3 {} 6 {} 9 {} 8 eight 4 eight 5 five 4 four 2 four 7 fourteen 1 one 7 seven 8 sixteen 10 ten 5 ten 10 twenty 2 two 1 two}
  163. test_compound_select_flippable select9-1.$iOuterLoop.5 {
  164. SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 1, 2
  165. } {1 one 1 two 2 four 2 two 3 {} 3 {} 4 eight 4 four 5 five 5 ten 6 {} 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 9 {} 10 ten 10 twenty}
  166. test_compound_select_flippable select9-1.$iOuterLoop.6 {
  167. SELECT a, b FROM t1 UNION ALL SELECT d, e FROM t2 ORDER BY 2, 1
  168. } {3 {} 3 {} 6 {} 6 {} 9 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two}
  169. # Test some 2-way UNION queries.
  170. #
  171. test_compound_select select9-1.$iOuterLoop.7 {
  172. SELECT a, b FROM t1 UNION SELECT d, e FROM t2
  173. } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty}
  174. test_compound_select select9-1.$iOuterLoop.8 {
  175. SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 1
  176. } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty}
  177. test_compound_select select9-1.$iOuterLoop.9 {
  178. SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 2
  179. } {3 {} 6 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two}
  180. test_compound_select_flippable select9-1.$iOuterLoop.10 {
  181. SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 1, 2
  182. } {1 one 1 two 2 four 2 two 3 {} 4 eight 4 four 5 five 5 ten 6 {} 7 fourteen 7 seven 8 eight 8 sixteen 9 {} 10 ten 10 twenty}
  183. test_compound_select_flippable select9-1.$iOuterLoop.11 {
  184. SELECT a, b FROM t1 UNION SELECT d, e FROM t2 ORDER BY 2, 1
  185. } {3 {} 6 {} 9 {} 4 eight 8 eight 5 five 2 four 4 four 7 fourteen 1 one 7 seven 8 sixteen 5 ten 10 ten 10 twenty 1 two 2 two}
  186. # Test some 2-way INTERSECT queries.
  187. #
  188. test_compound_select select9-1.$iOuterLoop.11 {
  189. SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2
  190. } {3 {} 6 {} 9 {}}
  191. test_compound_select_flippable select9-1.$iOuterLoop.12 {
  192. SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 1
  193. } {3 {} 6 {} 9 {}}
  194. test_compound_select select9-1.$iOuterLoop.13 {
  195. SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 2
  196. } {3 {} 6 {} 9 {}}
  197. test_compound_select_flippable select9-1.$iOuterLoop.14 {
  198. SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 2, 1
  199. } {3 {} 6 {} 9 {}}
  200. test_compound_select_flippable select9-1.$iOuterLoop.15 {
  201. SELECT a, b FROM t1 INTERSECT SELECT d, e FROM t2 ORDER BY 1, 2
  202. } {3 {} 6 {} 9 {}}
  203. # Test some 2-way EXCEPT queries.
  204. #
  205. test_compound_select select9-1.$iOuterLoop.16 {
  206. SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2
  207. } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten}
  208. test_compound_select select9-1.$iOuterLoop.17 {
  209. SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 1
  210. } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten}
  211. test_compound_select select9-1.$iOuterLoop.18 {
  212. SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 2
  213. } {8 eight 5 five 4 four 1 one 7 seven 10 ten 2 two}
  214. test_compound_select select9-1.$iOuterLoop.19 {
  215. SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 1, 2
  216. } {1 one 2 two 4 four 5 five 7 seven 8 eight 10 ten}
  217. test_compound_select select9-1.$iOuterLoop.20 {
  218. SELECT a, b FROM t1 EXCEPT SELECT d, e FROM t2 ORDER BY 2, 1
  219. } {8 eight 5 five 4 four 1 one 7 seven 10 ten 2 two}
  220. incr iOuterLoop
  221. }
  222. do_test select9-2.0 {
  223. execsql {
  224. DROP INDEX i1;
  225. DROP INDEX i2;
  226. DROP INDEX i3;
  227. DROP INDEX i4;
  228. }
  229. } {}
  230. proc reverse {lhs rhs} {
  231. return [string compare $rhs $lhs]
  232. }
  233. db collate reverse reverse
  234. # This loop is similar to the previous one (test cases select9-1.*)
  235. # except that the simple select statements have WHERE clauses attached
  236. # to them. Sometimes the WHERE clause may be satisfied using the same
  237. # index used for ORDER BY, sometimes not.
  238. #
  239. set iOuterLoop 1
  240. foreach indexes [list {
  241. /* Do not create any indexes. */
  242. } {
  243. CREATE INDEX i1 ON t1(a)
  244. } {
  245. DROP INDEX i1;
  246. CREATE INDEX i1 ON t1(b, a)
  247. } {
  248. CREATE INDEX i2 ON t2(d DESC, e COLLATE REVERSE ASC);
  249. } {
  250. CREATE INDEX i3 ON t1(a DESC);
  251. }] {
  252. do_test select9-2.$iOuterLoop.1 {
  253. execsql $indexes
  254. } {}
  255. test_compound_select_flippable select9-2.$iOuterLoop.2 {
  256. SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5 ORDER BY 1
  257. } {1 one I 2 two II 3 {} {} 4 four IV 5 ten XX 6 {} {} 7 fourteen XXVIII 8 sixteen XXXII 9 {} {} 10 twenty XL}
  258. test_compound_select_flippable select9-2.$iOuterLoop.2 {
  259. SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5 ORDER BY 2, 1
  260. } {3 {} {} 6 {} {} 9 {} {} 4 four IV 7 fourteen XXVIII 1 one I 8 sixteen XXXII 5 ten XX 10 twenty XL 2 two II}
  261. test_compound_select_flippable select9-2.$iOuterLoop.3 {
  262. SELECT * FROM t1 WHERE a<5 UNION SELECT * FROM t2 WHERE d>=5
  263. ORDER BY 2 COLLATE reverse, 1
  264. } {3 {} {} 6 {} {} 9 {} {} 2 two II 10 twenty XL 5 ten XX 8 sixteen XXXII 1 one I 7 fourteen XXVIII 4 four IV}
  265. test_compound_select_flippable select9-2.$iOuterLoop.4 {
  266. SELECT * FROM t1 WHERE a<5 UNION ALL SELECT * FROM t2 WHERE d>=5 ORDER BY 1
  267. } {1 one I 2 two II 3 {} {} 4 four IV 5 ten XX 6 {} {} 7 fourteen XXVIII 8 sixteen XXXII 9 {} {} 10 twenty XL}
  268. test_compound_select_flippable select9-2.$iOuterLoop.5 {
  269. SELECT * FROM t1 WHERE a<5 UNION ALL SELECT * FROM t2 WHERE d>=5 ORDER BY 2, 1
  270. } {3 {} {} 6 {} {} 9 {} {} 4 four IV 7 fourteen XXVIII 1 one I 8 sixteen XXXII 5 ten XX 10 twenty XL 2 two II}
  271. test_compound_select_flippable select9-2.$iOuterLoop.6 {
  272. SELECT * FROM t1 WHERE a<5 UNION ALL SELECT * FROM t2 WHERE d>=5
  273. ORDER BY 2 COLLATE reverse, 1
  274. } {3 {} {} 6 {} {} 9 {} {} 2 two II 10 twenty XL 5 ten XX 8 sixteen XXXII 1 one I 7 fourteen XXVIII 4 four IV}
  275. test_compound_select select9-2.$iOuterLoop.4 {
  276. SELECT a FROM t1 WHERE a<8 EXCEPT SELECT d FROM t2 WHERE d<=3 ORDER BY 1
  277. } {4 5 6 7}
  278. test_compound_select select9-2.$iOuterLoop.4 {
  279. SELECT a FROM t1 WHERE a<8 INTERSECT SELECT d FROM t2 WHERE d<=3 ORDER BY 1
  280. } {1 2 3}
  281. }
  282. do_test select9-2.X {
  283. execsql {
  284. DROP INDEX i1;
  285. DROP INDEX i2;
  286. DROP INDEX i3;
  287. }
  288. } {}
  289. # This procedure executes the SQL. Then it checks the generated program
  290. # for the SQL and appends a "nosort" to the result if the program contains the
  291. # SortCallback opcode. If the program does not contain the SortCallback
  292. # opcode it appends "sort"
  293. #
  294. proc cksort {sql} {
  295. set ::sqlite_sort_count 0
  296. set data [execsql $sql]
  297. if {$::sqlite_sort_count} {set x sort} {set x nosort}
  298. lappend data $x
  299. return $data
  300. }
  301. # If the right indexes exist, the following query:
  302. #
  303. # SELECT t1.a FROM t1 UNION ALL SELECT t2.d FROM t2 ORDER BY 1
  304. #
  305. # can use indexes to run without doing a in-memory sort operation.
  306. # This block of tests (select9-3.*) is used to check if the same
  307. # is possible with:
  308. #
  309. # CREATE VIEW v1 AS SELECT a FROM t1 UNION ALL SELECT d FROM t2
  310. # SELECT a FROM v1 ORDER BY 1
  311. #
  312. # It turns out that it is.
  313. #
  314. do_test select9-3.1 {
  315. cksort { SELECT a FROM t1 ORDER BY 1 }
  316. } {1 2 3 4 5 6 7 8 9 10 sort}
  317. do_test select9-3.2 {
  318. execsql { CREATE INDEX i1 ON t1(a) }
  319. cksort { SELECT a FROM t1 ORDER BY 1 }
  320. } {1 2 3 4 5 6 7 8 9 10 nosort}
  321. do_test select9-3.3 {
  322. cksort { SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 LIMIT 5 }
  323. } {1 1 2 2 3 sort}
  324. do_test select9-3.4 {
  325. execsql { CREATE INDEX i2 ON t2(d) }
  326. cksort { SELECT a FROM t1 UNION ALL SELECT d FROM t2 ORDER BY 1 LIMIT 5 }
  327. } {1 1 2 2 3 nosort}
  328. do_test select9-3.5 {
  329. execsql { CREATE VIEW v1 AS SELECT a FROM t1 UNION ALL SELECT d FROM t2 }
  330. cksort { SELECT a FROM v1 ORDER BY 1 LIMIT 5 }
  331. } {1 1 2 2 3 nosort}
  332. do_test select9-3.X {
  333. execsql {
  334. DROP INDEX i1;
  335. DROP INDEX i2;
  336. DROP VIEW v1;
  337. }
  338. } {}
  339. # This block of tests is the same as the preceding one, except that
  340. # "UNION" is tested instead of "UNION ALL".
  341. #
  342. do_test select9-4.1 {
  343. cksort { SELECT a FROM t1 ORDER BY 1 }
  344. } {1 2 3 4 5 6 7 8 9 10 sort}
  345. do_test select9-4.2 {
  346. execsql { CREATE INDEX i1 ON t1(a) }
  347. cksort { SELECT a FROM t1 ORDER BY 1 }
  348. } {1 2 3 4 5 6 7 8 9 10 nosort}
  349. do_test select9-4.3 {
  350. cksort { SELECT a FROM t1 UNION SELECT d FROM t2 ORDER BY 1 LIMIT 5 }
  351. } {1 2 3 4 5 sort}
  352. do_test select9-4.4 {
  353. execsql { CREATE INDEX i2 ON t2(d) }
  354. cksort { SELECT a FROM t1 UNION SELECT d FROM t2 ORDER BY 1 LIMIT 5 }
  355. } {1 2 3 4 5 nosort}
  356. do_test select9-4.5 {
  357. execsql { CREATE VIEW v1 AS SELECT a FROM t1 UNION SELECT d FROM t2 }
  358. cksort { SELECT a FROM v1 ORDER BY 1 LIMIT 5 }
  359. } {1 2 3 4 5 sort}
  360. do_test select9-4.X {
  361. execsql {
  362. DROP INDEX i1;
  363. DROP INDEX i2;
  364. DROP VIEW v1;
  365. }
  366. } {}
  367. # Testing to make sure that queries involving a view of a compound select
  368. # are planned efficiently. This detects a problem reported on the mailing
  369. # list on 2012-04-26. See
  370. #
  371. # http://www.mail-archive.com/sqlite-users%40sqlite.org/msg69746.html
  372. #
  373. # For additional information.
  374. #
  375. do_test select9-5.1 {
  376. db eval {
  377. CREATE TABLE t51(x, y);
  378. CREATE TABLE t52(x, y);
  379. CREATE VIEW v5 as
  380. SELECT x, y FROM t51
  381. UNION ALL
  382. SELECT x, y FROM t52;
  383. CREATE INDEX t51x ON t51(x);
  384. CREATE INDEX t52x ON t52(x);
  385. EXPLAIN QUERY PLAN
  386. SELECT * FROM v5 WHERE x='12345' ORDER BY y;
  387. }
  388. } {~/SCAN TABLE/} ;# Uses indices with "*"
  389. do_test select9-5.2 {
  390. db eval {
  391. EXPLAIN QUERY PLAN
  392. SELECT x, y FROM v5 WHERE x='12345' ORDER BY y;
  393. }
  394. } {~/SCAN TABLE/} ;# Uses indices with "x, y"
  395. do_test select9-5.3 {
  396. db eval {
  397. EXPLAIN QUERY PLAN
  398. SELECT x, y FROM v5 WHERE +x='12345' ORDER BY y;
  399. }
  400. } {/SCAN TABLE/} ;# Full table scan if the "+x" prevents index usage.
  401. # 2013-07-09: Ticket [490a4b7235624298]:
  402. # "WHERE 0" on the first element of a UNION causes an assertion fault
  403. #
  404. do_execsql_test select9-6.1 {
  405. CREATE TABLE t61(a);
  406. CREATE TABLE t62(b);
  407. INSERT INTO t61 VALUES(111);
  408. INSERT INTO t62 VALUES(222);
  409. SELECT a FROM t61 WHERE 0 UNION SELECT b FROM t62;
  410. } {222}
  411. do_execsql_test select9-6.2 {
  412. SELECT a FROM t61 WHERE 0 UNION ALL SELECT b FROM t62;
  413. } {222}
  414. do_execsql_test select9-6.3 {
  415. SELECT a FROM t61 UNION SELECT b FROM t62 WHERE 0;
  416. } {111}
  417. finish_test