From 23fb1330aba7a093cc21473360d164ad7b10a49f Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 14 Sep 2010 18:56:52 +0000 Subject: [PATCH] Further tests for compound SELECT statements. FossilOrigin-Name: a0f01ebab9bd42fca9ce5d97f8cbf44afd803f4e --- manifest | 24 ++---- manifest.uuid | 2 +- test/e_select.test | 183 +++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 175 insertions(+), 34 deletions(-) diff --git a/manifest b/manifest index 29bda8834c..0adf9fce2a 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Clarify\sthe\sdocumentation\sto\sbetter\sexplain\swhen\san\sautomatic\sre-prepare\scan\nbe\sinduced\sby\srebinding\sparameters.\s\sAdd\sevidence\smarks\sto\sthe\sautomatic\nre-prepare\slogic. -D 2010-09-14T18:23:00 +C Further\stests\sfor\scompound\sSELECT\sstatements. +D 2010-09-14T18:56:53 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -353,7 +350,7 @@ F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376 F test/e_expr.test 164e87c1d7b40ceb47c57c3bffa384c81d009aa7 F test/e_fkey.test 6721a741c6499b3ab7e5385923233343c8f1ad05 F test/e_fts3.test 75bb0aee26384ef586165e21018a17f7cd843469 -F test/e_select.test d2c9d044811e93580f5743228a84f9627e7a6756 +F test/e_select.test 64b04eb0de934478d5522c96dc27b3a4f14120f5 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398 F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041 @@ -860,14 +857,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 56a9ce7774a6f163a62684dd8d5357ce16a07de1 -R a4728c6feae09b64d78d8072cff18875 -U drh -Z e2feffe76f35afd45194eb9f5e40268d ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD8DBQFMj72HoxKgR168RlERAmkrAJ9gkEPE/A0pZg0zRXGwp8CY5l7M3wCfTmtS -iPjxlN5+VXRDwTfZ3zQFuGI= -=qgfB ------END PGP SIGNATURE----- +P 3e11f5155c5625ddf4300a9ef7e8bc20a190a752 +R ffe9d538878a55690e1d687b68362469 +U dan +Z 409ed711cbd7fa2b841cc7bdcb3c8b83 diff --git a/manifest.uuid b/manifest.uuid index 7c9677537e..49e02e6372 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3e11f5155c5625ddf4300a9ef7e8bc20a190a752 \ No newline at end of file +a0f01ebab9bd42fca9ce5d97f8cbf44afd803f4e \ No newline at end of file diff --git a/test/e_select.test b/test/e_select.test index e65332607a..7854802a26 100644 --- a/test/e_select.test +++ b/test/e_select.test @@ -1784,6 +1784,7 @@ drop_all_tables do_execsql_test e_select-7.4.0 { CREATE TABLE q1(a TEXT, b INTEGER, c); CREATE TABLE q2(d NUMBER, e BLOB); + CREATE TABLE q3(f REAL, g); INSERT INTO q1 VALUES(16, -87.66, NULL); INSERT INTO q1 VALUES('legible', 94, -42.47); @@ -1793,41 +1794,191 @@ do_execsql_test e_select-7.4.0 { INSERT INTO q2 VALUES('beauty', 2); INSERT INTO q2 VALUES(-65.91, 4); INSERT INTO q2 VALUES('emanating', -16.56); - INSERT INTO q2 VALUES(NULL, -22.82); - INSERT INTO q2 VALUES(7.48, 'example'); + + INSERT INTO q3 VALUES('beauty', 2); + INSERT INTO q3 VALUES('beauty', 2); } {} foreach {tn select res} { - 1 "SELECT a FROM q1 UNION ALL SELECT d FROM q2" - {16 legible beauty legible beauty -65.91 emanating {} 7.48} + 1 {SELECT a FROM q1 UNION ALL SELECT d FROM q2} + {16 legible beauty legible beauty -65.91 emanating} - 2 "SELECT * FROM q1 WHERE a=16 UNION ALL SELECT 'x', * FROM q2 WHERE oid=1" + 2 {SELECT * FROM q1 WHERE a=16 UNION ALL SELECT 'x', * FROM q2 WHERE oid=1} {16 -87.66 {} x legible 1} - 3 "SELECT count(*) FROM q1 UNION ALL SELECT min(e) FROM q2" {3 -22.82} + 3 {SELECT count(*) FROM q1 UNION ALL SELECT min(e) FROM q2} + {3 -16.56} + + 4 {SELECT * FROM q2 UNION ALL SELECT * FROM q3} + {legible 1 beauty 2 -65.91 4 emanating -16.56 beauty 2 beauty 2} } { do_execsql_test e_select-7.4.$tn $select [list {*}$res] } +# EVIDENCE-OF: R-20560-39162 The UNION operator works the same way as +# UNION ALL, except that duplicate rows are removed from the final +# result set. +# +foreach {tn select res} { + 1 {SELECT a FROM q1 UNION SELECT d FROM q2} + {-65.91 16 beauty emanating legible} + + 2 {SELECT * FROM q1 WHERE a=16 UNION SELECT 'x', * FROM q2 WHERE oid=1} + {16 -87.66 {} x legible 1} + + 3 {SELECT count(*) FROM q1 UNION SELECT min(e) FROM q2} + {-16.56 3} + + 4 {SELECT * FROM q2 UNION SELECT * FROM q3} + {-65.91 4 beauty 2 emanating -16.56 legible 1} +} { + do_execsql_test e_select-7.5.$tn $select [list {*}$res] +} + +# EVIDENCE-OF: R-45764-31737 The INTERSECT operator returns the +# intersection of the results of the left and right SELECTs. +# +foreach {tn select res} { + 1 {SELECT a FROM q1 INTERSECT SELECT d FROM q2} {beauty legible} + 2 {SELECT * FROM q2 INTERSECT SELECT * FROM q3} {beauty 2} +} { + do_execsql_test e_select-7.6.$tn $select [list {*}$res] +} + +# EVIDENCE-OF: R-25787-28949 The EXCEPT operator returns the subset of +# rows returned by the left SELECT that are not also returned by the +# right-hand SELECT. +# +foreach {tn select res} { + 1 {SELECT a FROM q1 EXCEPT SELECT d FROM q2} {16} + + 2 {SELECT * FROM q2 EXCEPT SELECT * FROM q3} + {-65.91 4 emanating -16.56 legible 1} +} { + do_execsql_test e_select-7.7.$tn $select [list {*}$res] +} + +# EVIDENCE-OF: R-40729-56447 Duplicate rows are removed from the results +# of INTERSECT and EXCEPT operators before the result set is returned. +# +foreach {tn select res} { + 0 {SELECT * FROM q3} {beauty 2 beauty 2} + + 1 {SELECT * FROM q3 INTERSECT SELECT * FROM q3} {beauty 2} + 2 {SELECT * FROM q3 EXCEPT SELECT a,b FROM q1} {beauty 2} +} { + do_execsql_test e_select-7.8.$tn $select [list {*}$res] +} + +# EVIDENCE-OF: R-46765-43362 For the purposes of determining duplicate +# rows for the results of compound SELECT operators, NULL values are +# considered equal to other NULL values and distinct from all non-NULL +# values. +# +db nullvalue null +foreach {tn select res} { + 1 {SELECT NULL UNION ALL SELECT NULL} {null null} + 2 {SELECT NULL UNION SELECT NULL} {null} + 3 {SELECT NULL INTERSECT SELECT NULL} {null} + 4 {SELECT NULL EXCEPT SELECT NULL} {} + + 5 {SELECT NULL UNION ALL SELECT 'ab'} {null ab} + 6 {SELECT NULL UNION SELECT 'ab'} {null ab} + 7 {SELECT NULL INTERSECT SELECT 'ab'} {} + 8 {SELECT NULL EXCEPT SELECT 'ab'} {null} + + 9 {SELECT NULL UNION ALL SELECT 0} {null 0} + 10 {SELECT NULL UNION SELECT 0} {null 0} + 11 {SELECT NULL INTERSECT SELECT 0} {} + 12 {SELECT NULL EXCEPT SELECT 0} {null} + + 13 {SELECT c FROM q1 UNION ALL SELECT g FROM q3} {null -42.47 null 2 2} + 14 {SELECT c FROM q1 UNION SELECT g FROM q3} {null -42.47 2} + 15 {SELECT c FROM q1 INTERSECT SELECT g FROM q3} {} + 16 {SELECT c FROM q1 EXCEPT SELECT g FROM q3} {null -42.47} +} { + do_execsql_test e_select-7.9.$tn $select [list {*}$res] +} +db nullvalue {} + +# EVIDENCE-OF: R-51232-50224 The collation sequence used to compare two +# text values is determined as if the columns of the left and right-hand +# SELECT statements were the left and right-hand operands of the equals +# (=) operator, except that greater precedence is not assigned to a +# collation sequence specified with the postfix COLLATE operator. +# +drop_all_tables +do_execsql_test e_select-7.10.0 { + CREATE TABLE y1(a COLLATE nocase, b COLLATE binary, c); + INSERT INTO y1 VALUES('Abc', 'abc', 'aBC'); +} {} +foreach {tn select res} { + 1 {SELECT 'abc' UNION SELECT 'ABC'} {ABC abc} + 2 {SELECT 'abc' COLLATE nocase UNION SELECT 'ABC'} {ABC} + 3 {SELECT 'abc' UNION SELECT 'ABC' COLLATE nocase} {ABC} + 4 {SELECT 'abc' COLLATE binary UNION SELECT 'ABC' COLLATE nocase} {ABC abc} + 5 {SELECT 'abc' COLLATE nocase UNION SELECT 'ABC' COLLATE binary} {ABC} + + 6 {SELECT a FROM y1 UNION SELECT b FROM y1} {abc} + 7 {SELECT b FROM y1 UNION SELECT a FROM y1} {Abc abc} + 8 {SELECT a FROM y1 UNION SELECT c FROM y1} {aBC} + + 9 {SELECT a FROM y1 UNION SELECT c COLLATE binary FROM y1} {aBC} + +} { + do_execsql_test e_select-7.10.$tn $select [list {*}$res] +} + +# EVIDENCE-OF: R-32706-07403 No affinity transformations are applied to +# any values when comparing rows as part of a compound SELECT. +# +drop_all_tables +do_execsql_test e_select-7.10.0 { + CREATE TABLE w1(a TEXT, b NUMBER); + CREATE TABLE w2(a, b TEXT); + + INSERT INTO w1 VALUES('1', 4.1); + INSERT INTO w2 VALUES(1, 4.1); +} {} + +foreach {tn select res} { + 1 { SELECT a FROM w1 UNION SELECT a FROM w2 } {1 1} + 2 { SELECT a FROM w2 UNION SELECT a FROM w1 } {1 1} + 3 { SELECT b FROM w1 UNION SELECT b FROM w2 } {4.1 4.1} + 4 { SELECT b FROM w2 UNION SELECT b FROM w1 } {4.1 4.1} + + 5 { SELECT a FROM w1 INTERSECT SELECT a FROM w2 } {} + 6 { SELECT a FROM w2 INTERSECT SELECT a FROM w1 } {} + 7 { SELECT b FROM w1 INTERSECT SELECT b FROM w2 } {} + 8 { SELECT b FROM w2 INTERSECT SELECT b FROM w1 } {} + + 9 { SELECT a FROM w1 EXCEPT SELECT a FROM w2 } {1} + 10 { SELECT a FROM w2 EXCEPT SELECT a FROM w1 } {1} + 11 { SELECT b FROM w1 EXCEPT SELECT b FROM w2 } {4.1} + 12 { SELECT b FROM w2 EXCEPT SELECT b FROM w1 } {4.1} +} { + do_execsql_test e_select-7.11.$tn $select [list {*}$res] +} + # EVIDENCE-OF: R-32562-20566 When three or more simple SELECTs are # connected into a compound SELECT, they group from left to right. In # other words, if "A", "B" and "C" are all simple SELECT statements, (A # op B op C) is processed as ((A op B) op C). # -# e_select-7.X.1: Precedence of UNION vs. INTERSECT -# e_select-7.X.2: Precedence of UNION vs. UNION ALL -# e_select-7.X.3: Precedence of UNION vs. EXCEPT -# e_select-7.X.4: Precedence of INTERSECT vs. UNION ALL -# e_select-7.X.5: Precedence of INTERSECT vs. EXCEPT -# e_select-7.X.6: Precedence of UNION ALL vs. EXCEPT -# e_select-7.X.7: Check that "a EXCEPT b EXCEPT c" is processed as +# e_select-7.12.1: Precedence of UNION vs. INTERSECT +# e_select-7.12.2: Precedence of UNION vs. UNION ALL +# e_select-7.12.3: Precedence of UNION vs. EXCEPT +# e_select-7.12.4: Precedence of INTERSECT vs. UNION ALL +# e_select-7.12.5: Precedence of INTERSECT vs. EXCEPT +# e_select-7.12.6: Precedence of UNION ALL vs. EXCEPT +# e_select-7.12.7: Check that "a EXCEPT b EXCEPT c" is processed as # "(a EXCEPT b) EXCEPT c". # # The INTERSECT and EXCEPT operations are mutually commutative. So -# the e_select-7.X.5 test cases do not prove very much. +# the e_select-7.12.5 test cases do not prove very much. # drop_all_tables -do_execsql_test e_select-7.X.0 { +do_execsql_test e_select-7.12.0 { CREATE TABLE t1(x); INSERT INTO t1 VALUES(1); INSERT INTO t1 VALUES(2); @@ -1855,7 +2006,7 @@ foreach {tn select res} { 7 "(2,3) EXCEPT (2) EXCEPT (3)" {} } { set select [string map {( {SELECT x FROM t1 WHERE x IN (}} $select] - do_execsql_test e_select-7.X.$tn $select [list {*}$res] + do_execsql_test e_select-7.12.$tn $select [list {*}$res] } finish_test