]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add test cases and minor fixes to this branch.
authordan <Dan Kennedy>
Thu, 17 Dec 2020 16:48:04 +0000 (16:48 +0000)
committerdan <Dan Kennedy>
Thu, 17 Dec 2020 16:48:04 +0000 (16:48 +0000)
FossilOrigin-Name: 5d6dc29d5f81738b07e4fee652fb2343fc409c2545f2f4667e8ee82d1a75f721

manifest
manifest.uuid
src/select.c
test/unionall.test

index 08b4c0649915ed873a7b681b1f09f07ebfb9e3c7..5e496dbf03505ee1eca23f08ba2e9e30d01728e5 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Allow\ssub-queries\sthat\suse\sUNION\sALL\sto\sbe\sflattened,\seven\sif\sthe\sparent\squery\sis\sa\sjoin.\sStill\ssome\sproblems\son\sthis\sbranch.
-D 2020-12-16T20:00:46.479
+C Add\stest\scases\sand\sminor\sfixes\sto\sthis\sbranch.
+D 2020-12-17T16:48:04.003
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -540,7 +540,7 @@ F src/printf.c 30e92b638fac71dcd85cdea1d12ecfae354c9adee2c71e8e1ae4727cde7c91ed
 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 1948a92ca9eab776632816b97e57c61d933474a78aad4f4ef835c916a83dbb1c
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
-F src/select.c 85f02c7d6bcc81c369da37e3c5decf45e326d8a4988b44f7111a06352d9c8830
+F src/select.c f80a2081645e3e841417f2d280ba7badfe44cee2537376035bf3dfb5f2fbdf73
 F src/shell.c.in e9f674ee4ec6c345679e8a5b16c869c6c59eb1540dd98ac69e4736ecddce0090
 F src/sqlite.h.in 5b7593bb0f3658e682a9fcd1cd8fcedf244ec45ca93d645055a53172f55eb783
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1627,7 +1627,7 @@ F test/tt3_vacuum.c 1753f45917699c9c1f66b64c717a717c9379f776
 F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff
 F test/types2.test 1aeb81976841a91eef292723649b5c4fe3bc3cac
 F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a
-F test/unionall.test 52a4324f59c70df2525188298a0593d650d983ccbfa9441a8a411ac99e1d6644
+F test/unionall.test d2a6956fa3f01e0566b2cb81b2eea6e10be67c54ca1b1623685c6dbff8bd465b
 F test/unionallfault.test 8dcc3f680ace498d8d3110ddcfdaa6a3d8aa1843bc7c266b990f13815ee6d7fe
 F test/unionvtab.test e1704ab1b4c1bb3ffc9da4681f8e85a0b909fd80b937984fc94b27415ac8e5a4
 F test/unionvtabfault.test e8759f3d14fb938ce9657e2342db34aeac0fb9bc1692b0d1ebb0069630151d06
@@ -1893,10 +1893,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 31cd1bbfa5b06723288d99d1cb423f88353bdef770b82e9103f71a796d66f660
-R 1855283db3260c0b82311305192dc3a1
-T *branch * union-all-flattener
-T *sym-union-all-flattener *
-T -sym-trunk *
+P 00e4bf74d3dfb87666a2266905f7d1a2afc6eb088d22cfd4f38f048733d6b936
+R 4cf81f06ce809058bd00b1e229a42929
 U dan
-Z cdcd89c0fb8db082c205bd2de653ec39
+Z 4e0770b4a8bae0abb40b2b1a928fba76
index 730454631146249cb06891ef3fb2154ffda88ad9..03481edeadfc5f409b43ebb2fdbd2f2108cda314 100644 (file)
@@ -1 +1 @@
-00e4bf74d3dfb87666a2266905f7d1a2afc6eb088d22cfd4f38f048733d6b936
\ No newline at end of file
+5d6dc29d5f81738b07e4fee652fb2343fc409c2545f2f4667e8ee82d1a75f721
\ No newline at end of file
index 24236e6a3607cbfc4cdd53cd6d46a8d5356d3fb2..81db65167ea8854829cf9a7c7bf2ffb0df0506ec 100644 (file)
@@ -3743,9 +3743,9 @@ static void recomputeColumnsUsed(
 **        (17c) every term within the subquery compound must have a FROM clause
 **        (17d) the outer query may not be
 **              (17d1) aggregate, or
-**              (17d2) DISTINCT, or
-**              (17d3) a join.
-**        (17e) the subquery may not contain window functions
+**              (17d2) DISTINCT
+**        (17e) the subquery may not contain window functions, and
+**        (17f) the subquery must not be the RHS of a LEFT JOIN.
 **
 **        The parent and sub-query may contain WHERE clauses. Subject to
 **        rules (11), (13) and (14), they may also contain ORDER BY,
@@ -3778,9 +3778,8 @@ static void recomputeColumnsUsed(
 **
 **  (22)  The subquery may not be a recursive CTE.
 **
-**  (**)  Subsumed into restriction (17d3).  Was: If the outer query is
-**        a recursive CTE, then the sub-query may not be a compound query.
-**        This restriction is because transforming the
+**  (23)  If the outer query is a recursive CTE, then the sub-query may not be
+**        a compound query.  This restriction is because transforming the
 **        parent to a compound query confuses the code that handles
 **        recursive queries in multiSelect().
 **
@@ -3921,12 +3920,13 @@ static int flattenSubquery(
       return 0;  /* Restriction (20) */
     }
     if( isAgg || (p->selFlags & SF_Distinct)!=0 || isLeftJoin>0 ){
-      return 0; /* (17d1), (17d2), or (17d3) */
+      return 0; /* (17d1), (17d2), or (17f) */
     }
     for(pSub1=pSub; pSub1; pSub1=pSub1->pPrior){
       testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Distinct );
       testcase( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))==SF_Aggregate );
       assert( pSub->pSrc!=0 );
+      assert( (pSub->selFlags & SF_Recursive)==0 );
       assert( pSub->pEList->nExpr==pSub1->pEList->nExpr );
       if( (pSub1->selFlags & (SF_Distinct|SF_Aggregate))!=0    /* (17b) */
        || (pSub1->pPrior && pSub1->op!=TK_ALL)                 /* (17a) */
index d8dc4c241480bf61b7d2176d90189f50e12a998e..43b24a455ff6a057ecdf5c2ae781ee5a3185d0c7 100644 (file)
@@ -55,4 +55,116 @@ do_execsql_test 1.3 {
 } {1 one 2 two 5 five 6 six}
 
 
+#-------------------------------------------------------------------------
+reset_db
+
+do_execsql_test 2.1.0 {
+  CREATE TABLE t1(x, y);
+  INSERT INTO t1 VALUES(1, 'one');
+  INSERT INTO t1 VALUES(1, 'ONE');
+  INSERT INTO t1 VALUES(2, 'two');
+  INSERT INTO t1 VALUES(2, 'TWO');
+  INSERT INTO t1 VALUES(3, 'three');
+  INSERT INTO t1 VALUES(3, 'THREE');
+}
+
+do_execsql_test 2.1.1 {
+  WITH s(i) AS (
+      SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<3
+  )
+  SELECT * FROM (
+    SELECT 0 AS i UNION ALL SELECT i FROM s UNION ALL SELECT 0
+  ), t1 WHERE x=i;
+} {
+  1 1 one 1 1 ONE 2 2 two 2 2 TWO 3 3 three 3 3 THREE
+}
+
+do_catchsql_test 2.1.2 {
+  WITH s(i) AS (
+      SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<3 UNION ALL SELECT 4
+  )
+  SELECT * FROM s, t1 WHERE x=i;
+} {1 {circular reference: s}}
+
+do_execsql_test 2.2.0 {
+  CREATE TABLE t2_a(k INTEGER PRIMARY KEY, v TEXT);
+  CREATE TABLE t2_b(k INTEGER PRIMARY KEY, v TEXT);
+
+  CREATE VIEW t2 AS 
+    SELECT * FROM t2_a 
+    UNION ALL 
+    SELECT * FROM t2_b;
+
+  CREATE TRIGGER t2_insert INSTEAD OF INSERT ON t2 BEGIN
+    INSERT INTO t2_a SELECT new.k, new.v WHERE (new.k%2)==0;
+    INSERT INTO t2_b SELECT new.k, new.v WHERE (new.k%2)==1;
+  END;
+
+  INSERT INTO t2 VALUES(5, 'v'), (4, 'iv'), (3, 'iii'), (2, 'ii');
+}
+
+do_execsql_test 2.2.1 {
+  SELECT * FROM t1, t2 WHERE x=k;
+} {
+  2 two 2 ii 2 TWO 2 ii 3 three 3 iii 3 THREE 3 iii
+}
+
+do_execsql_test 2.2.2 {
+  SELECT * FROM t1 LEFT JOIN t2 ON (x=k);
+} {
+  1 one {} {}
+  1 ONE {} {}
+  2 two 2 ii 2 TWO 2 ii 3 three 3 iii 3 THREE 3 iii
+}
+
+do_execsql_test 2.2.3 {
+  SELECT x1.*, x2.* FROM t2 AS x1, t2 AS x2 WHERE x1.k=x2.k+1
+} {
+  4 iv   3 iii 
+  3 iii  2 ii 
+  5 v    4 iv
+}
+
+do_execsql_test 2.2.4 {
+  SELECT * FROM t1, t2 WHERE x=k ORDER BY y;
+} {
+  3 THREE 3 iii 
+  2 TWO 2 ii 
+  3 three 3 iii 
+  2 two 2 ii
+}
+do_execsql_test 2.2.5 {
+  SELECT * FROM t1, t2 WHERE x=k ORDER BY y||'';
+} {
+  3 THREE 3 iii 
+  2 TWO 2 ii 
+  3 three 3 iii 
+  2 two 2 ii
+}
+do_execsql_test 2.2.6 {
+  SELECT * FROM t1, t2 WHERE x=k ORDER BY v
+} {
+  2 two   2 ii
+  2 TWO   2 ii 
+  3 three 3 iii 
+  3 THREE 3 iii 
+}
+do_execsql_test 2.2.7 {
+  SELECT * FROM t1, t2 WHERE x=k ORDER BY v||''
+} {
+  2 two   2 ii
+  2 TWO   2 ii 
+  3 three 3 iii 
+  3 THREE 3 iii 
+}
+do_execsql_test 2.2.8 {
+  SELECT * FROM t1, t2 WHERE x=k ORDER BY k,v||''
+} {
+  2 two   2 ii
+  2 TWO   2 ii 
+  3 three 3 iii 
+  3 THREE 3 iii 
+}
+
+
 finish_test