]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Ensure that the WhereInfo.revMask bitmap is adjusted when tables are removed
authordrh <>
Thu, 5 Sep 2024 23:44:49 +0000 (23:44 +0000)
committerdrh <>
Thu, 5 Sep 2024 23:44:49 +0000 (23:44 +0000)
from the FROM clause by the Omit-Noop-Join optimization.

FossilOrigin-Name: 2b543fbc28a03661590fa7e1f9ded65e0758f6bf6e1ee05070b9bcad422ff087

manifest
manifest.uuid
src/where.c
test/join2.test

index e7d51a329364e8ccad4593a5e131bd961ab58ce4..e34ec1c1460470577b846cd826142a6328cf63f7 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\sbug\sin\sthe\sparsing\sof\ssome\scorner-case\sJSON\sPATH\sstrings\sthat\scontain\nescaped\sdouble-quotes.
-D 2024-09-04T16:45:51.779
+C Ensure\sthat\sthe\sWhereInfo.revMask\sbitmap\sis\sadjusted\swhen\stables\sare\sremoved\nfrom\sthe\sFROM\sclause\sby\sthe\sOmit-Noop-Join\soptimization.
+D 2024-09-05T23:44:49.612
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -839,7 +839,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89
 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
 F src/walker.c 7c7ea0115345851c3da4e04e2e239a29983b61fb5b038b94eede6aba462640e2
-F src/where.c 839956666ce9f6b5d4951fc1f27e976951aac66920c82f9cdc5036b61b54ef7b
+F src/where.c 74ef82f58056c71dc0d6dc6417b9861814b9a92fe87ff32ec2fde6d01f903996
 F src/whereInt.h 82a13766f13d1a53b05387c2e60726289ef26404bc7b9b1f7770204d97357fb8
 F src/wherecode.c f5255f49d1f42b6e7e6b0362ff3522fa88cbcaa7213e52f9374744027ecdebca
 F src/whereexpr.c 1d350f8ddb7d8740423341d0289d899bf3b287faad8d19c815b6715d396bc919
@@ -1332,7 +1332,7 @@ F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4
 F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b
 F test/istrue.test e7f285bb70282625c258e866ce6337d4c762922f5a300e1b50f958aef6e7d9c9
 F test/join.test f7abfef3faeaf2800308872e33a57e5b6e4a2b44fb8c6b90c6068412e71a6cf4
-F test/join2.test 8561fe82ce434ac96de91544072e578dc2cadddf2d9bc9cd802f866a9b92502e
+F test/join2.test f59d63264fb24784ae9c3bc9d867eb569cd6d442da5660f8852effe5c1938c27
 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0
 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
 F test/join5.test 380d12a9350f99f0cc681a4f1fea999886f18b3fe0d71a9b3065bcaead1e007f
@@ -2192,9 +2192,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 45778b0bb830c473c0733681c79c8055abadff94f552562f2e8965c9d8662abc
-Q +60ac55c4b76355aaf7cbde38bf1f6082ff5612bf4ffc49ab69d00fd4e3d64e64
-R 18db2f2681323708e6bd712790016b17
+P c49c2a8c0082622890c2de006afad4f03f2c4ab931dde846e303d0374590b522
+Q +22ca5a2ffb89ccb5f337993b5a95e27c449c39014284156eabc33da012a8759c
+R 6c4a68eb6bc21deac80d2f01e5d2cb3c
 U drh
-Z 5db7aadf5ed96f0c9f6e5ad4da273556
+Z b87b900cc21c070df7552ebe1f4ad160
 # Remove this line to create a well-formed Fossil manifest.
index 18a3e3388a09553783220bcd0a8b48a0b4bd4db9..b8f955b651146e4246a80381a1abdbcf00ae8ceb 100644 (file)
@@ -1 +1 @@
-c49c2a8c0082622890c2de006afad4f03f2c4ab931dde846e303d0374590b522
+2b543fbc28a03661590fa7e1f9ded65e0758f6bf6e1ee05070b9bcad422ff087
index 84deb5e9ea6b8812e896f8bbfba5c94f7f09421b..b1c3aa5fefcf4ae81119734f493bfc4ba073177e 100644 (file)
@@ -5899,6 +5899,7 @@ static SQLITE_NOINLINE Bitmask whereOmitNoopJoin(
     WhereTerm *pTerm, *pEnd;
     SrcItem *pItem;
     WhereLoop *pLoop;
+    Bitmask m1;
     pLoop = pWInfo->a[i].pWLoop;
     pItem = &pWInfo->pTabList->a[pLoop->iTab];
     if( (pItem->fg.jointype & (JT_LEFT|JT_RIGHT))!=JT_LEFT ) continue;
@@ -5926,6 +5927,8 @@ static SQLITE_NOINLINE Bitmask whereOmitNoopJoin(
     }
     if( pTerm<pEnd ) continue;
     WHERETRACE(0xffffffff, ("-> drop loop %c not used\n", pLoop->cId));
+    m1 = MASKBIT(i)-1;
+    pWInfo->revMask = (m1 & pWInfo->revMask) | ((pWInfo->revMask>>1) & ~m1);
     notReady &= ~pLoop->maskSelf;
     for(pTerm=pWInfo->sWC.a; pTerm<pEnd; pTerm++){
       if( (pTerm->prereqAll & pLoop->maskSelf)!=0 ){
index 15e76f965dbf1866376f96ff4ecc0ba3d2509130..6f2fe1d77074e5e207a2ff22bb0536e3152bdbd1 100644 (file)
@@ -428,4 +428,25 @@ do_eqp_test 12.3 {
   `--SEARCH t1 USING INTEGER PRIMARY KEY (rowid=?) LEFT-JOIN
 }
 
+# 2024-09-05 https://sqlite.org/forum/forumpost/8a1e467e905b8d27
+# When performing the Omit-Noop-Join optimization, if FROM clause terms
+# to the right of the omitted join have the reverse-order bit set in the
+# WhereInfo.revMask bitmask, those bits need to be shifted to account
+# for the omitted join.
+#
+reset_db
+do_execsql_test 13.0 {
+  CREATE TABLE t1(a1 INTEGER PRIMARY KEY, b1 INT);
+  CREATE TABLE t2(c2 INT, d2 INTEGER PRIMARY KEY);
+  CREATE TABLE t3(e3 INTEGER PRIMARY KEY);
+  INSERT INTO t1 VALUES(33,0);
+  INSERT INTO t2 VALUES(33,1),(33,2);
+}
+do_execsql_test 13.1 {
+  SELECT t1.a1, t2.d2
+    FROM (t1 LEFT JOIN t3 ON t3.e3=t1.b1) JOIN t2 ON t2.c2=t1.a1
+   WHERE t1.a1=33
+   ORDER BY t2.d2 DESC;
+} {33 2 33 1}
+
 finish_test