From: drh <> Date: Fri, 4 Feb 2022 13:05:29 +0000 (+0000) Subject: For the MULTI-INDEX-OR optimization, when pushing down WHERE clause terms from X-Git-Tag: version-3.38.0~60 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02e3e041343e6ac950771bb5ef813f1876f5036b;p=thirdparty%2Fsqlite.git For the MULTI-INDEX-OR optimization, when pushing down WHERE clause terms from the main query into the various OR-term subqueries, do not push down slices of a vector comparison, since the right-hand operand of the comparison might have only been initialized in a different OR branch that was not taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1. FossilOrigin-Name: 9f67ad00cd38b7c5ec6d14b379e1a611777bbdf6901d843a80712ba7d94d6d33 --- diff --git a/manifest b/manifest index 844ec5dafa..3f02ec9d75 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\stypo\sfix\sin\scomment.\sNo\scode\schanges. -D 2022-02-03T18:14:22.642 +C For\sthe\sMULTI-INDEX-OR\soptimization,\swhen\spushing\sdown\sWHERE\sclause\sterms\sfrom\nthe\smain\squery\sinto\sthe\svarious\sOR-term\ssubqueries,\sdo\snot\spush\sdown\sslices\nof\sa\svector\scomparison,\ssince\sthe\sright-hand\soperand\sof\sthe\scomparison\smight\nhave\sonly\sbeen\sinitialized\sin\sa\sdifferent\sOR\sbranch\sthat\swas\snot\staken.\ndbsqlfuzz\s80a9fade844b4fb43564efc972bcb2c68270f5d1. +D 2022-02-04T13:05:29.719 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -640,9 +640,9 @@ F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b F src/where.c 31bc1f43b0bf679e93c3e7a7d67cbcaddc7ae746694b149b282427d337b06caa -F src/whereInt.h 1d821657238a0bd12b3c8f2926c7f8f9294bc5efe20af53c7c50d53a0a026cb9 -F src/wherecode.c 5879604677f0bdfb8d95ff616d834daecc12256346b7d9ad96a7e84a1cb08fdc -F src/whereexpr.c fa8017f9fed4b50c59b4f105139679dd59ed7fea43179ebb0f6b8b5796a30515 +F src/whereInt.h 099c7fa273f34afa5adc7f25dcacc48df70392ce224089b641b1c9c5b01d5598 +F src/wherecode.c 4a0dd0403e1c9b628a420eefbe1d60da0003356de6ee18e6707480c9b995bae7 +F src/whereexpr.c 2da56404a024dc8dc41a31d8b498eed2c7c6b0bb412150d88cb3327516aa3b9f F src/window.c dfaec4abc6012cbc18e4a202ca3a5d5a0efcc4011d86a06d882ddaab8aedee4d F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 @@ -1324,7 +1324,7 @@ F test/round1.test 768018b04522ca420b1aba8a24bd76091d269f3bce3902af3ec6ebcee41ab F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 F test/rowid.test e29025be95baf6b32f0d5edef59a7633028325896a98f1caa8019559ca910350 -F test/rowvalue.test 02214016f747854ef636e64ff204778649937aa801ca78e2495a960f8e0d509d +F test/rowvalue.test 228b312f8526ed000ecda559a6a9adf30aa2d79dcb12afa5c04eebaafcf55eae F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b F test/rowvalue3.test 3068f508753af69884b12125995f023da0dbb256 F test/rowvalue4.test 441e7e366ac6d939a3a95a574031c56ec2a854077a91d66eee5ff1d86cb5be58 @@ -1943,8 +1943,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 e35ab16dd0fd40b07a71d26e1cdb19ef664a2a628a4abcb2e130f5e555de8ca9 -R 20ef9d61f41a89bdff8a0b9888d3988c +P f9b763042c5c4446115c5375a8e4731e522e36ad9fc53e9ef775de9bc297ea19 +R 928b302c497557d2f34fa5bbc849c67c U drh -Z bc10ba616693d19ec8e6518f2199687e +Z 80d96bf6fd3b06fc995fb22f494a3906 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index a441058899..9993c3d6b7 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9b763042c5c4446115c5375a8e4731e522e36ad9fc53e9ef775de9bc297ea19 \ No newline at end of file +9f67ad00cd38b7c5ec6d14b379e1a611777bbdf6901d843a80712ba7d94d6d33 \ No newline at end of file diff --git a/src/whereInt.h b/src/whereInt.h index fc3740f519..8cd4144874 100644 --- a/src/whereInt.h +++ b/src/whereInt.h @@ -285,6 +285,7 @@ struct WhereTerm { #else # define TERM_HIGHTRUTH 0 /* Only used with STAT4 */ #endif +#define TERM_SLICE 0x8000 /* One slice of a row-value/vector comparison */ /* ** An instance of the WhereScan object is used as an iterator for locating diff --git a/src/wherecode.c b/src/wherecode.c index 8d7163ce08..603fcdfd76 100644 --- a/src/wherecode.c +++ b/src/wherecode.c @@ -2317,7 +2317,7 @@ Bitmask sqlite3WhereCodeOneLoopStart( iRetInit = sqlite3VdbeAddOp2(v, OP_Integer, 0, regReturn); /* If the original WHERE clause is z of the form: (x1 OR x2 OR ...) AND y - ** Then for every term xN, evaluate as the subexpression: xN AND z + ** Then for every term xN, evaluate as the subexpression: xN AND y ** That way, terms in y that are factored into the disjunction will ** be picked up by the recursive calls to sqlite3WhereBegin() below. ** @@ -2329,6 +2329,12 @@ Bitmask sqlite3WhereCodeOneLoopStart( ** This optimization also only applies if the (x1 OR x2 OR ...) term ** is not contained in the ON clause of a LEFT JOIN. ** See ticket http://www.sqlite.org/src/info/f2369304e4 + ** + ** 2022-02-04: Do not push down slices of a row-value comparison. + ** In other words, "w" or "y" may not be a slice of a vector. Otherwise, + ** the initialization of the right-hand operand of the vector comparison + ** might not occur, or might occur only in an OR branch that is not + ** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1. */ if( pWC->nTerm>1 ){ int iTerm; @@ -2337,7 +2343,10 @@ Bitmask sqlite3WhereCodeOneLoopStart( if( &pWC->a[iTerm] == pTerm ) continue; testcase( pWC->a[iTerm].wtFlags & TERM_VIRTUAL ); testcase( pWC->a[iTerm].wtFlags & TERM_CODED ); - if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED))!=0 ) continue; + testcase( pWC->a[iTerm].wtFlags & TERM_SLICE ); + if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){ + continue; + } if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue; testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO ); pExpr = sqlite3ExprDup(db, pExpr, 0); diff --git a/src/whereexpr.c b/src/whereexpr.c index e212bcb932..ac4f2e1fbe 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -1399,7 +1399,7 @@ static void exprAnalyze( pNew = sqlite3PExpr(pParse, pExpr->op, pLeft, pRight); transferJoinMarkings(pNew, pExpr); - idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC); + idxNew = whereClauseInsert(pWC, pNew, TERM_DYNAMIC|TERM_SLICE); exprAnalyze(pSrc, pWC, idxNew); } pTerm = &pWC->a[idxTerm]; diff --git a/test/rowvalue.test b/test/rowvalue.test index 7c101d9b3e..92d3260e6c 100644 --- a/test/rowvalue.test +++ b/test/rowvalue.test @@ -708,5 +708,23 @@ do_execsql_test 31.2 { SELECT * FROM t1 LEFT JOIN t2 ON b=NULL WHERE (c,d)==(SELECT 123, 456+a); } {} +# 2022-02-03 dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1 +reset_db +do_execsql_test 32.1 { + CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT, c INT); + CREATE TABLE t2(d INTEGER PRIMARY KEY); + INSERT INTO t1(a,b,c) VALUES(500,654,456); + INSERT INTO t1(a,b,c) VALUES(501,655,456); + INSERT INTO t1(a,b,c) VALUES(502,654,122); + INSERT INTO t1(a,b,c) VALUES(503,654,221); + INSERT INTO t1(a,b,c) VALUES(601,654,122); + INSERT INTO t2(d) VALUES(456); + INSERT INTO t2(d) VALUES(122); + SELECT a FROM ( + SELECT t1.a FROM t2, t1 + WHERE (987, t1.b) = ( SELECT 987, 654 ) AND t2.d=t1.c + ) AS t3 + WHERE a=1234 OR a<=567; +} {500 502} finish_test