]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the query flattener so that it does not flatten a RIGHT or FULL JOIN into
authordrh <>
Mon, 18 Apr 2022 23:20:02 +0000 (23:20 +0000)
committerdrh <>
Mon, 18 Apr 2022 23:20:02 +0000 (23:20 +0000)
any position of the outer query other than the first.

FossilOrigin-Name: 837322aa95b1c46201b7dd0c2e6c7b9915b4276d997949f1ecf961fb7f3514cf

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

index 2e1950ca8699bea5f2f9a2c64491d2194dbb796a..77c55c7a933fd16acc8fced5d8478678755fbbf6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C New\stest\scases,\sincluding\sone\sthat\sgets\sa\sdifferent\sresult\sthan\sPostgres.
-D 2022-04-18T22:51:24.965
+C Fix\sthe\squery\sflattener\sso\sthat\sit\sdoes\snot\sflatten\sa\sRIGHT\sor\sFULL\sJOIN\sinto\nany\sposition\sof\sthe\souter\squery\sother\sthan\sthe\sfirst.
+D 2022-04-18T23:20:02.870
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -552,7 +552,7 @@ F src/printf.c 05d8dfd2018bc4fc3ddb8b37eb97ccef7abf985643fa1caebdcf2916ca90fa32
 F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c ce4cb0889f1bf5990b698740b88026385cf6f30222fde1f02a3168bb780eb579
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
-F src/select.c 6544e02167adbb89a7152acf6ff2f0218a6de94146377b83e79bc8b09bf6f16e
+F src/select.c 459cea7ae6e6ff517b04ad3ec7ed6479b666096a85fcec5b4edec2d5cacca2d8
 F src/shell.c.in ecff6f4ab0e8e25acd578b3eb27ac0bad4d48643c160259a277151d6e9d412e1
 F src/sqlite.h.in 2a35f62185eb5e7ecc64a2f68442b538ce9be74f80f28a00abc24837edcf1c17
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1148,7 +1148,7 @@ F test/join5.test c4df54e2e204d7f1417bfbdd21ca324b4b07415c647595cc47798eacfddc96
 F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c
 F test/join7.test 8e72de4b45e5e930d18c305c7efe86015fb2552731e4e03ea226353036b0dab0
 F test/join8.test 6ed7eed8993e060e5e9d07f6bcadf1bb634742a03b9824afbcfa193adf7f9965
-F test/join9.test a651f427b9906fda7c3548a0a9dbec725b9e80e92a65787f9d2a845d49af649d
+F test/join9.test 9056ddd3b0c0f4f9d658f4521038d9a37dc23ead8ca9a505d0b0db2b6a471e05
 F test/journal1.test c7b768041b7f494471531e17abc2f4f5ebf9e5096984f43ed17c4eb80ba34497
 F test/journal2.test 9dac6b4ba0ca79c3b21446bbae993a462c2397c4
 F test/journal3.test 7c3cf23ffc77db06601c1fcfc9743de8441cb77db9d1aa931863d94f5ffa140e
@@ -1948,8 +1948,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 5bcf4aa3bf6b1b9f47142bc37683bb3bf0adeffd052d07449af7c9b415add052
-R 81d9c0efaaa8f2b2681b74a83997038e
+P 49ea11a4a5fd630db44f458304d4f45fa103529ed6b36d538c78074965e8d799
+R f732ede2542062631f39bbd96137d61f
 U drh
-Z 354a9aaf45b00cc0c5b254cdf7868063
+Z dd5cee205fd9f7e997652ba77ec73d51
 # Remove this line to create a well-formed Fossil manifest.
index 8a412559d8532b42673e7c2818f9df6d7b1d5a90..bbad85cdc6e28ff5ca708f5fdde27c4fbaf5efd4 100644 (file)
@@ -1 +1 @@
-49ea11a4a5fd630db44f458304d4f45fa103529ed6b36d538c78074965e8d799
\ No newline at end of file
+837322aa95b1c46201b7dd0c2e6c7b9915b4276d997949f1ecf961fb7f3514cf
\ No newline at end of file
index 6d185a1685b9f6433ea55f6bc2e339f83d135142..d65719e0abf1de3d840f87c57b194224bc76b12a 100644 (file)
@@ -4122,6 +4122,9 @@ static void renumberCursors(
 **  (26)  The subquery may not be the right operand of a RIGHT JOIN.
 **        See also (3) for restrictions on LEFT JOIN.
 **
+**  (27)  The subquery may not contain a FULL or RIGHT JOIN unless it
+**        is the first element of the parent query.
+**
 **
 ** In this routine, the "p" parameter is a pointer to the outer query.
 ** The subquery is p->pSrc->a[iFrom].  isAgg is true if the outer query
@@ -4241,6 +4244,11 @@ static int flattenSubquery(
   }
 #endif
 
+  assert( pSubSrc->nSrc>0 );  /* True by restriction (7) */
+  if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
+    return 0;   /* Restriction (27) */
+  }
+
   /* Restriction (17): If the sub-query is a compound SELECT, then it must
   ** use only the UNION ALL operator. And none of the simple select queries
   ** that make up the compound SELECT are allowed to be aggregate or distinct
index 4f143034c4b148967751a3d46fb2711b9b9610e2..e547d4ce7084beb5e63a2f388157f40012f18aa4 100644 (file)
@@ -518,6 +518,7 @@ foreach {id schema} {
     -   -      8   dave   -       -  
   }
 
+  # Restriction (27) in the query flattener
   # Verified by PG-14
   do_execsql_test join9-$id.1000 {
     WITH t56(id,y,z) AS (SELECT * FROM t5 FULL JOIN t6 USING(id) LIMIT 50)
@@ -538,5 +539,27 @@ foreach {id schema} {
     4   bob    green   444
   }
 
+  # Verified by PG-14
+  do_execsql_test join9-$id.1020 {
+    SELECT id,x,y,z
+      FROM t4 FULL JOIN t5 USING(id) INNER JOIN t6 USING(id)
+     ORDER BY 1;
+  } {
+    3   -    yellow  333
+    4   bob  green   444
+    5   -    blue    555
+  }
+
+  # Verified by PG-14
+  do_execsql_test join9-$id.1030 {
+    WITH t45(id,x,y) AS (SELECT * FROM t4 FULL JOIN t5 USING(id) LIMIT 50)
+    SELECT id,x,y,z FROM t45 JOIN t6 USING(id)
+    ORDER BY 1;
+  } {
+    3   -    yellow  333
+    4   bob  green   444
+    5   -    blue    555
+  }
+
 }
 finish_test