]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add back the ability to flatten a LEFT JOIN subquery - previously removed
authordrh <>
Thu, 23 Jun 2022 15:15:03 +0000 (15:15 +0000)
committerdrh <>
Thu, 23 Jun 2022 15:15:03 +0000 (15:15 +0000)
due to ticket [cad1ab4cb7b0fc344].

FossilOrigin-Name: f8fe936ad4f7678f9b26ba6fab41c5df9f4938634cdb3286b0f2dcd1357f919a

manifest
manifest.uuid
src/select.c
src/vdbe.c
test/join.test

index 8882a0bee8d181d8e38d3accb207f26e8ce12feb..e7bdf3876694a117cf14b3011c6293a549d1b8bf 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Minor\scorrection\sto\sa\scomment.\s\sNo\scode\schanges.
-D 2022-06-23T12:36:56.505
+C Add\sback\sthe\sability\sto\sflatten\sa\sLEFT\sJOIN\ssubquery\s-\spreviously\sremoved\ndue\sto\sticket\s[cad1ab4cb7b0fc344].
+D 2022-06-23T15:15:03.618
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -570,7 +570,7 @@ F src/printf.c 6166a30417b05c5b2f82e1f183f75faa2926ad60531c0b688a57dbc951441a20
 F src/random.c 097dc8b31b8fba5a9aca1697aeb9fd82078ec91be734c16bffda620ced7ab83c
 F src/resolve.c 1655e44c77c51ebbe82924287528a78bd4a4aaaf34189dbae28d19ccf2ca615c
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
-F src/select.c 2db8bbf13f57cc9872f9b927546e98f5ea583e9e364182426492a434a994421b
+F src/select.c 0e07ed5e7dc93ebdc0b5ed4760e147417c30709a2697f263876357009673eb1c
 F src/shell.c.in 08e59f1cb9d9b1180aba52861aaada0c95f6ddd210488719684e160a0724c806
 F src/sqlite.h.in 172528c287399a34f188154017b7268bf82c6d5b780902e361958d2318c4e37c
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -642,7 +642,7 @@ F src/upsert.c 8789047a8f0a601ea42fa0256d1ba3190c13746b6ba940fe2d25643a7e991937
 F src/utf.c ee39565f0843775cc2c81135751ddd93eceb91a673ea2c57f61c76f288b041a0
 F src/util.c 602fe229f32a96ceccae4f40824129669582096f7c355f53dbac156c9fecef23
 F src/vacuum.c bb346170b0b54c6683bba4a5983aea40485597fdf605c87ec8bc2e199fe88cd8
-F src/vdbe.c d7a10fd2afa527886e930ea39eb4a946206e0e439e6cca7424d7373232183010
+F src/vdbe.c c303875051361dc8f5b5c927c2c843ae9d664fc240be4dbeffe243a5af35d6ab
 F src/vdbe.h 07641758ca8b4f4c6d81ea667ea167c541e6ece21f5574da11e3d21ec37e2662
 F src/vdbeInt.h 2cad0aeeb106371ed0e0946bab89f60627087068847afc2451c05056961c18da
 F src/vdbeapi.c 602610f1252d59cd69742f78a1e2f6fbae40a4b407f5506a6a7b869b0df08ff2
@@ -1161,7 +1161,7 @@ F test/ioerr4.test f130fe9e71008577b342b8874d52984bd04ede2c
 F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
 F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
 F test/istrue.test e7f285bb70282625c258e866ce6337d4c762922f5a300e1b50f958aef6e7d9c9
-F test/join.test 5c7f917aa219a125d1df517d3df384c79f74860fdfb2e48c0a599f1e2b3e9ed8
+F test/join.test 6dacc1c7121cac00d17c720677c5a598c8ef6e16780ea9a24edfb96c9b397137
 F test/join2.test 466b07233820f5deee66a6c3bf6e4500c8bbf7b83649e67606f5f649c07928c0
 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
@@ -1978,8 +1978,11 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 83ff1a28e3e7a99fa90d5079897d76529c4256eed859bf7cb98b860fbedfdc5b
-R 84b3e295df7fc9b4a1509f0d6ebc58aa
+P 5fa00959ebc3a46fe400564d5a30e8c44857cd4f0473fb25e84154019eff3f39
+R 7c9e5bbcdf37f239d91e48a825683444
+T *branch * flatten-left-join
+T *sym-flatten-left-join *
+T -sym-trunk *
 U drh
-Z 71ed77c77f9d7bcfc9156cb5b9ba5369
+Z b50ebd17a3c7c4abceffd64a112d48b3
 # Remove this line to create a well-formed Fossil manifest.
index b65bad0e2e7cbc0ff66fc7be7bfde723da820fec..65826fbe1b624744eb883b4d6bae61f92aa99d39 100644 (file)
@@ -1 +1 @@
-5fa00959ebc3a46fe400564d5a30e8c44857cd4f0473fb25e84154019eff3f39
\ No newline at end of file
+f8fe936ad4f7678f9b26ba6fab41c5df9f4938634cdb3286b0f2dcd1357f919a
\ No newline at end of file
index 6f5e8c82abc9e72a7d6f1d545252220a404e5df7..12bca38bf83917e55a030d16da28d722a7602b3a 100644 (file)
@@ -4068,7 +4068,7 @@ static void renumberCursors(
 **        (3a) the subquery may not be a join and
 **        (3b) the FROM clause of the subquery may not contain a virtual
 **             table and
-**        (3c) the outer query may not be an aggregate.
+**        (**) REMOVED.  Was: the outer query may not be an aggregate.
 **        (3d) the outer query may not be DISTINCT.
 **        See also (26) for restrictions on RIGHT JOIN.
 **
@@ -4273,16 +4273,10 @@ static int flattenSubquery(
   **
   ** which is not at all the same thing.
   **
-  ** If the subquery is the right operand of a LEFT JOIN, then the outer
-  ** query cannot be an aggregate. (3c)  This is an artifact of the way
-  ** aggregates are processed - there is no mechanism to determine if
-  ** the LEFT JOIN table should be all-NULL.
-  **
   ** See also tickets #306, #350, and #3300.
   */
   if( (pSubitem->fg.jointype & (JT_OUTER|JT_LTORJ))!=0 ){
     if( pSubSrc->nSrc>1                        /* (3a) */
-     || isAgg                                  /* (3c) */
      || IsVirtual(pSubSrc->a[0].pTab)          /* (3b) */
      || (p->selFlags & SF_Distinct)!=0         /* (3d) */
      || (pSubitem->fg.jointype & JT_RIGHT)!=0  /* (26) */
index 7857924a80f8e375341dc5c6ee1eb59e376628b3..b01e6416bf5d0dda47c56e6048eb641f29384233 100644 (file)
@@ -2639,11 +2639,14 @@ case OP_NotNull: {            /* same as TK_NOTNULL, jump, in1 */
 ** If it is, then set register P3 to NULL and jump immediately to P2.
 ** If P1 is not on a NULL row, then fall through without making any
 ** changes.
+**
+** If P1 is not an open cursor, then this opcode is a no-op.
 */
 case OP_IfNullRow: {         /* jump */
+  VdbeCursor *pC;
   assert( pOp->p1>=0 && pOp->p1<p->nCursor );
-  assert( p->apCsr[pOp->p1]!=0 );
-  if( p->apCsr[pOp->p1]->nullRow ){
+  pC = p->apCsr[pOp->p1];
+  if( pC && pC->nullRow ){
     sqlite3VdbeMemSetNull(aMem + pOp->p3);
     goto jump_to_p2;
   }
index 38143c05608f6fbbbde8ecc96f148315159b58cc..c7d1377f2a5557fcf0d4bb34e1cf9f8f70d98df7 100644 (file)
@@ -763,6 +763,23 @@ do_execsql_test join-14.4 {
   SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1;
 } {111 {}}
 do_execsql_test join-14.5 {
+  SELECT * FROM (SELECT 111 AS x UNION ALL SELECT 222)
+                LEFT JOIN (SELECT c+333 AS y FROM t1) ON x=y GROUP BY 1;
+} {111 {} 222 {}}
+do_execsql_test join-14.6 {
+  SELECT * FROM (SELECT 111 AS x UNION ALL SELECT 111)
+                LEFT JOIN (SELECT c+333 AS y FROM t1) ON x=y GROUP BY 1;
+} {111 {}}
+do_execsql_test join-14.7 {
+  SELECT * FROM (SELECT 111 AS x UNION ALL SELECT 111 UNION ALL SELECT 222)
+                LEFT JOIN (SELECT c+333 AS y FROM t1) ON x=y GROUP BY 1;
+} {111 {} 222 {}}
+do_execsql_test join-14.8 {
+  INSERT INTO t1(c) VALUES(-111);
+  SELECT * FROM (SELECT 111 AS x UNION ALL SELECT 111 UNION ALL SELECT 222)
+                LEFT JOIN (SELECT c+333 AS y FROM t1) ON x=y GROUP BY 1;
+} {111 {} 222 222}
+do_execsql_test join-14.9 {
   DROP TABLE IF EXISTS t1;
   CREATE TABLE t1(c PRIMARY KEY) WITHOUT ROWID;
   SELECT * FROM (SELECT 111) LEFT JOIN (SELECT c+222 FROM t1) GROUP BY 1;