]> 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:22:55 +0000 (23:22 +0000)
committerdrh <>
Thu, 5 Sep 2024 23:22:55 +0000 (23:22 +0000)
from the FROM clause by the Omit-Noop-Join optimization of
[0cd82ee9a8413cf1].  Fix for the issue described by
[forum:/forum/8a1e467e905b8d27|format post 8a1e467e905b8d27].

FossilOrigin-Name: 22ca5a2ffb89ccb5f337993b5a95e27c449c39014284156eabc33da012a8759c

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

index b5a5da924d4bb41d064bd4143355722329f0e651..0a8c14d268e69e43e0c499aadbf607d9e05eabce 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\snotes\son\sbuild\sprocedures\sin\sthe\sREADME.md\sfile.
-D 2024-09-05T15:55:04.340
+C Ensure\sthat\sthe\sWhereInfo.revMask\sbitmap\sis\sadjusted\swhen\stables\sare\sremoved\nfrom\sthe\sFROM\sclause\sby\sthe\sOmit-Noop-Join\soptimization\sof\n[0cd82ee9a8413cf1].\s\sFix\sfor\sthe\sissue\sdescribed\sby\n[forum:/forum/8a1e467e905b8d27|format\spost\s8a1e467e905b8d27].
+D 2024-09-05T23:22:55.647
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -852,7 +852,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c 887fc4ca3f020ebb2e376f222069570834ac63bf50111ef0cbf3ae417048ed89
 F src/wal.h ba252daaa94f889f4b2c17c027e823d9be47ce39da1d3799886bbd51f0490452
 F src/walker.c d5006d6b005e4ea7302ad390957a8d41ed83faa177e412f89bc5600a7462a014
-F src/where.c c046dd58c3410f7b7528e1e6317cb876398557bad346d568ed8562321a7d002d
+F src/where.c 079f1cf6abc086315f5c9873626b7c0537f382c55184c516b8e3d29f7a537fdc
 F src/whereInt.h a5d079c346a658b7a6e9e47bb943d021e02fa1e6aed3b964ca112112a4892192
 F src/wherecode.c 5172d647798134e7c92536ddffe7e530c393d79b5dedd648b88faf2646c65baf
 F src/whereexpr.c 44f41ae554c7572e1de1485b3169b233ee04d464b2ee5881687ede3bf07cacfa
@@ -1346,7 +1346,7 @@ F test/ioerr5.test 5984da7bf74b6540aa356f2ab0c6ae68a6d12039a3d798a9ac6a100abc17d
 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
@@ -2212,8 +2212,8 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P aa5f10f21dbfb24ee54ca96bfb7b013ae29e26fec05b80681f19cc63d9face49
-R 7cc85ab35bb58c1a46f86590da7723ea
+P 1d12744fe7cc294994e53e1ffe72799d0321dd5c1ef031213f083e200918fee5
+R 45d88f5375170588d0b1bd314eace7a3
 U drh
-Z a2b02066e2e694d910978f885128ac52
+Z 4179122ae9403ba759b59f6aa6b2df32
 # Remove this line to create a well-formed Fossil manifest.
index 210827e73b5689668ced46789c7e5512010b43b5..dc2d1cd1407dce03e86b51cd92c1c0284078a55b 100644 (file)
@@ -1 +1 @@
-1d12744fe7cc294994e53e1ffe72799d0321dd5c1ef031213f083e200918fee5
+22ca5a2ffb89ccb5f337993b5a95e27c449c39014284156eabc33da012a8759c
index 2b835009dbb7dba83ca2054c71a554592db15bf0..7ca4f533f0724bd515dd89ed114986a2ade95aeb 100644 (file)
@@ -6199,6 +6199,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;
@@ -6226,6 +6227,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