]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Do not allow a WHERE clause constraint to be used to drive an index for
authordrh <>
Mon, 6 Jun 2022 15:27:42 +0000 (15:27 +0000)
committerdrh <>
Mon, 6 Jun 2022 15:27:42 +0000 (15:27 +0000)
the right operand of a RIGHT JOIN, since this can cause problem if the
constraint implies a not-NULL value for one of the columns for the left
operand of the same join.  See
[forum:/forumpost/206d99a16dd9212f|forum post 206d99a16dd9212f].

FossilOrigin-Name: 4a31b7942a15c9c4363477365784d6d4ac5b1bbe8ff8aeaf2dd3d6532bf8bc96

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

index 1fcfe4ef05f83de249f5142504c3ebd7bad1e444..9048bd2ce4b4ff4af24528753bad07b30d9f5f5a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C In\sCLI,\sdrop\s.dbinfo\scommand\swhen\sbuild\soptions\sprevent\sit\sfrom\sworking.
-D 2022-06-06T15:22:11.742
+C Do\snot\sallow\sa\sWHERE\sclause\sconstraint\sto\sbe\sused\sto\sdrive\san\sindex\sfor\nthe\sright\soperand\sof\sa\sRIGHT\sJOIN,\ssince\sthis\scan\scause\sproblem\sif\sthe\nconstraint\simplies\sa\snot-NULL\svalue\sfor\sone\sof\sthe\scolumns\sfor\sthe\sleft\noperand\sof\sthe\ssame\sjoin.\s\sSee\n[forum:/forumpost/206d99a16dd9212f|forum\spost\s206d99a16dd9212f].
+D 2022-06-06T15:27:42.276
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -657,7 +657,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d
 F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
 F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b
-F src/where.c 3a69f4403aa994cda45db8f4070d146d8f253f9850b4c827a9ade7d444f889ea
+F src/where.c 667f8fab750f246e499a82b4b6711bfc605541bbf5206912fb647b9d325baeb5
 F src/whereInt.h b48ca529ffe293c18cbfa8326af18a09e39910de66fb3e96ef788c7cbf8ef3a7
 F src/wherecode.c 0b09abfcb88c61c6a6984a3e065786631ff35495e9bdf865e6b74ab0a1299c5b
 F src/whereexpr.c 20255cf03e0b765b742301197d165511ff99e95da0d7ee9c8a2ebc1e888dd049
@@ -1166,7 +1166,7 @@ F test/join4.test 1a352e4e267114444c29266ce79e941af5885916
 F test/join5.test d22b6cba8fb59ab3f1c82701434c360705eb12d4ce200c449f37b018fc47681a
 F test/join6.test f809c025fa253f9e150c0e9afd4cef8813257bceeb6f46e04041228c9403cc2c
 F test/join7.test 2268dcbb54b724391dda3748ea95c60d960607ffeed67885675998e7117697f6
-F test/join8.test 01c46c005f3cd20f530e1b7e17d003a1e6d16ae945ceca395f6c016bbee92e9f
+F test/join8.test 037d271ace8297b3c3814ade8964053553b84f07271497c128a9861c5dde681d
 F test/join9.test 9056ddd3b0c0f4f9d658f4521038d9a37dc23ead8ca9a505d0b0db2b6a471e05
 F test/joinA.test 7eab225dc1c1ab258a5e62513a4ed7cabbd3db971d59d5d92f4fb6fa14c12f6a
 F test/joinB.test 1b2ba3fc8568b49411787fccbf540570c148e9b6a53a30f80691cb6268098ded
@@ -1975,8 +1975,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 f7c17449ea0685e322f50abe7a59b7afcde0f7e38e03645ec5b13753a6d0dcf3 268072f636b25c24ec47e34f2a8356f466ec200b80487b1041e89e0ae909c8bd
-R 9207d306b462962d71351cad5c380553
-U larrybr
-Z d9afd3ca8797e6fffb53fd8da4b761d1
+P 4b50a55165f4603674a250df89cfc5ac1fef8aabaf433df8400df14d53bfbbe0
+R 36fe1e3adae6d605b2e8ea991b2037d0
+U drh
+Z 423aad7ac6c7bb7244bb6ead300ddf34
 # Remove this line to create a well-formed Fossil manifest.
index df5448dbf7546946e472298d2a5221f63dbcefab..e6384d1de6be9b4baf9a77a0b514969ed61f9e10 100644 (file)
@@ -1 +1 @@
-4b50a55165f4603674a250df89cfc5ac1fef8aabaf433df8400df14d53bfbbe0
\ No newline at end of file
+4a31b7942a15c9c4363477365784d6d4ac5b1bbe8ff8aeaf2dd3d6532bf8bc96
\ No newline at end of file
index 75925e4ae739282aa0cdbc1304ebc0a757632a48..b77fa78e0835e92c4ea51ee8ec2dc224d57708fe 100644 (file)
@@ -1177,11 +1177,11 @@ static sqlite3_index_info *allocateIndexInfo(
     assert( pTerm->u.x.leftColumn<pTab->nCol );
 
     /* tag-20191211-002: WHERE-clause constraints are not useful to the
-    ** right-hand table of a LEFT JOIN nor to the left-hand table of a
+    ** right-hand table of a LEFT JOIN nor to the either table of a
     ** RIGHT JOIN.  See tag-20191211-001 for the
     ** equivalent restriction for ordinary tables. */
-    if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
-     && !ExprHasProperty(pTerm->pExpr, EP_OuterON)
+    if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
+     && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
     ){
       continue;
     }
@@ -2833,9 +2833,15 @@ static int whereLoopAddBtreeIndex(
 
     /* tag-20191211-001:  Do not allow constraints from the WHERE clause to
     ** be used by the right table of a LEFT JOIN nor by the left table of a
-    ** RIGHT JOIN.  Only constraints in the
-    ** ON clause are allowed.  See tag-20191211-002 for the vtab equivalent. */
-    if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ))!=0
+    ** RIGHT JOIN.  Only constraints in the ON clause are allowed.
+    ** See tag-20191211-002 for the vtab equivalent.  
+    **
+    ** 2022-06-06: See https://sqlite.org/forum/forumpost/206d99a16dd9212f
+    ** for an example of a WHERE clause constraints that may not be used on
+    ** the right table of a RIGHT JOIN because the constraint implies a
+    ** not-NULL condition on the left table of the RIGHT JOIN.
+    */
+    if( (pSrc->fg.jointype & (JT_LEFT|JT_LTORJ|JT_RIGHT))!=0
      && !ExprHasProperty(pTerm->pExpr, EP_OuterON|EP_InnerON)
     ){
       continue;
index 528dad3d6c9c3edf4f4bdaf95a36219c771f00cc..48f0ad03eb19b0f5a19464e6f15a0c99ea2d5356 100644 (file)
@@ -572,4 +572,19 @@ do_execsql_test join8-17091 {
   SELECT t3.a FROM t4 RIGHT JOIN t3 ON (x=a) WHERE (b, 4) IS (SELECT 3, 4);
 } {1}
 
+# 2022-06-06
+# https://sqlite.org/forum/forumpost/206d99a16dd9212f
+# tag-20191211-001
+#
+reset_db
+do_execsql_test join8-18000 {
+  CREATE TABLE t1(a BOOLEAN); INSERT INTO t1 VALUES (false);
+  CREATE TABLE t2(x INT);     INSERT INTO t2 VALUES (0);
+  SELECT *, x NOTNULL, (x NOTNULL)=a FROM t2 RIGHT JOIN t1 ON true WHERE (x NOTNULL)=a;
+} {}
+do_execsql_test join8-18010 {
+  CREATE INDEX t1a ON t1(a);
+  SELECT *, x NOTNULL, (x NOTNULL)=a FROM t2 RIGHT JOIN t1 ON true WHERE (x NOTNULL)=a;
+} {}
+
 finish_test