]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
In the WHERE-constraint propagation optimization, if there are duplicate
authordrh <drh@noemail.net>
Thu, 25 Oct 2018 15:25:10 +0000 (15:25 +0000)
committerdrh <drh@noemail.net>
Thu, 25 Oct 2018 15:25:10 +0000 (15:25 +0000)
constraint, make sure only one of them propagates.  Proposed fix for
ticket [cf5ed20fc8621b165].

FossilOrigin-Name: caebf8792576752d1cd8af29f00ba3909b2448018c830287007328f6c31072c1

manifest
manifest.uuid
src/select.c
test/whereL.test

index 07d2ce336380f6de557ffc843e40dd69b4a5a824..b163d7e08607b633a21f8ca138816881f6cea96a 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\spotential\scrash\sthat\scan\soccur\swhile\sreading\san\sindex\sfrom\sa\scorrupt\ndatabase\sfile.\s\sThe\scorruption\sis\sa\srecord-header-size\sthat\sis\slarger\sthan\n0x7fffffff.\s\sProblem\sdetected\sby\sOSSFuzz\sagainst\sGDAL\sand\sreported\sto\sus\s\n(with\sa\ssuggested\sfix)\sby\sEven\sRouault.\s\sThe\stest\scase\sis\sin\sTH3.
-D 2018-10-01T14:05:03.008
+C In\sthe\sWHERE-constraint\spropagation\soptimization,\sif\sthere\sare\sduplicate\nconstraint,\smake\ssure\sonly\sone\sof\sthem\spropagates.\s\sProposed\sfix\sfor\nticket\s[cf5ed20fc8621b165].
+D 2018-10-25T15:25:10.254
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 6b650013511fd9d8b094203ac268af9220d292cc7d4e1bc9fbca15aacd8c7995
@@ -501,7 +501,7 @@ F src/printf.c 0f1177cf1dd4d7827bf64d840768514ec76409abecaca9e8b577dbd065150381
 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 352c6af1a99441206ff62a6f7429dbf537827f42c428639695220b9c8639e33b
 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93
-F src/select.c 1604a23093e68d223fdd81d3f4856f76f8f23d4ca4aa47da899ab6a7cc44c101
+F src/select.c 0671309c245ecb2b75d8b33948cbcf039325468aaedc13f37c8c4f3f62f48d5f
 F src/shell.c.in 6e0aad854be738a5d0368940459399be211e9ac43aebe92bb9ed46cfe38d0e1f
 F src/sqlite.h.in 4b4c2f2daeeed4412ba9d81bc78092c69831fe6eda4f0ae5bf951da51a8dccec
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -1631,7 +1631,7 @@ F test/whereH.test e4b07f7a3c2f5d31195cd33710054c78667573b2
 F test/whereI.test b7769ee8dbefd987fb266715fee887f05f9ff180016b06fca7fa402df739193b
 F test/whereJ.test 88287550f6ee604422403b053455b1ad894eeaa5c35d348532dfa1439286cb9a
 F test/whereK.test f8e3cf26a8513ecc7f514f54df9f0572c046c42b
-F test/whereL.test 84de61afe4b8e5a3ff7d741c990d85cb44b3ce798cd8412d5603930f3f75014f
+F test/whereL.test 0a19fc44cd1122040f56c934f1b14d0ca85bde28f270268a428dd9796ea0634c
 F test/wherefault.test 1374c3aa198388925246475f84ad4cd5f9528864
 F test/wherelfault.test 9012e4ef5259058b771606616bd007af5d154e64cc25fa9fd4170f6411db44e3
 F test/wherelimit.test 592081800806d297dd7449b1030c863d2883d6d42901837ccd2e5a9bd962edb0
@@ -1767,8 +1767,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 31ac8dbae4d5d3d5aee28959e9b1bfcb72a2f878541c0cbd74be46b0193df89c
-Q +8ac2cdda68f92b0352bc7f0b4be5fca4bb58565ca65055fb34153cc284ed6922
-R ddc2059c5b5350801be17552d74219d6
+P 5d2916589649421b53c599417577c8707352583378b0f47c899ee779cbd523c7
+Q +5d5b596f152bb2781011a05f75f9e200774d4f69d648ef68de577b4ace973e07
+R d18d3ffdeccd1af2b9b6e6109060fe80
 U drh
-Z 8c12b3e34e3633bc6bee9a2b48f148f6
+Z 18440bce5872df2e7bc423fbc2279523
index bf56708bad3dc49a9a9d5ec593149654b055c14c..bb4a56ab78b2985abd92f021d2c89cb63f19d8a3 100644 (file)
@@ -1 +1 @@
-5d2916589649421b53c599417577c8707352583378b0f47c899ee779cbd523c7
\ No newline at end of file
+caebf8792576752d1cd8af29f00ba3909b2448018c830287007328f6c31072c1
\ No newline at end of file
index 324556de5354e4dda5d20ef3f9aa33e35c475d79..fd39cbc7fe9d3858f451419dfee3978ab5f8b690 100644 (file)
@@ -4074,7 +4074,7 @@ static int flattenSubquery(
 #endif /* !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW) */
 
 /*
-** A structure to keep track of all of the column values that fixed to
+** A structure to keep track of all of the column values that are fixed to
 ** a known value due to WHERE clause constraints of the form COLUMN=VALUE.
 */
 typedef struct WhereConst WhereConst;
@@ -4086,13 +4086,28 @@ struct WhereConst {
 };
 
 /*
-** Add a new entry to the pConst object
+** Add a new entry to the pConst object.  Except, do not add duplicate
+** pColumn entires.
 */
 static void constInsert(
-  WhereConst *pConst,
-  Expr *pColumn,
-  Expr *pValue
+  WhereConst *pConst,      /* The WhereConst into which we are inserting */
+  Expr *pColumn,           /* The COLUMN part of the constraint */
+  Expr *pValue             /* The VALUE part of the constraint */
 ){
+  int i;
+  assert( pColumn->op==TK_COLUMN );
+
+  /* 2018-10-25 ticket [cf5ed20f]
+  ** Make sure the same pColumn is not inserted more than once */
+  for(i=0; i<pConst->nConst; i++){
+    const Expr *pExpr = pConst->apExpr[i*2];
+    assert( pExpr->op==TK_COLUMN );
+    if( pExpr->iTable==pColumn->iTable
+     && pExpr->iColumn==pColumn->iColumn
+    ){
+      return;  /* Already present.  Return without doing anything. */
+    }
+  }
 
   pConst->nConst++;
   pConst->apExpr = sqlite3DbReallocOrFree(pConst->pParse->db, pConst->apExpr,
index 3fe725b8774755c7e0b9a53e2cfd50f925863741..d0e5f0b6043f679756fe04ba63a9a7cea5850303 100644 (file)
@@ -111,4 +111,15 @@ do_execsql_test 302 {
      AND B.id=subq.zz;
 } {1}  
 
+# 2018-10-25: Ticket [cf5ed20f]
+# Incorrect join result with duplicate WHERE clause constraint.
+#
+do_execsql_test 400 {
+  CREATE TABLE x(a, b, c);
+  CREATE TABLE y(a, b);
+  INSERT INTO x VALUES (1, 0, 1);
+  INSERT INTO y VALUES (1, 2);
+  SELECT x.a FROM x JOIN y ON x.c = y.a WHERE x.b = 1 AND x.b = 1;
+} {}
+
 finish_test