From: dan Date: Mon, 26 Sep 2016 14:39:05 +0000 (+0000) Subject: When flattening a query of the form "SELECT * FROM (SELECT * FROM tbl WHERE x=?)... X-Git-Tag: version-3.15.0~51 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4c5ebee0b569bc0063ca76c35193454844a81adb;p=thirdparty%2Fsqlite.git When flattening a query of the form "SELECT * FROM (SELECT * FROM tbl WHERE x=?) WHERE y=?", ensure that the final WHERE clause is "x=? AND y=?" instead of "y=? AND x=?". Although it is still not guaranteed, this makes the order in which WHERE clause terms are processed comport more closely to users expectations. FossilOrigin-Name: cf7f9e6d5abff273dd2f8a8dce27d52e1449b3be --- diff --git a/manifest b/manifest index c63bc38f9d..b465f9514b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Inline\sthe\srelevent\sparts\sof\ssqlite3ExprAlloc()\sinto\sspanExpr(),\sfor\sa\nperformance\simprovement. -D 2016-09-26T12:38:22.166 +C When\sflattening\sa\squery\sof\sthe\sform\s"SELECT\s*\sFROM\s(SELECT\s*\sFROM\stbl\sWHERE\sx=?)\sWHERE\sy=?",\sensure\sthat\sthe\sfinal\sWHERE\sclause\sis\s"x=?\sAND\sy=?"\sinstead\sof\s"y=?\sAND\sx=?".\sAlthough\sit\sis\sstill\snot\sguaranteed,\sthis\smakes\sthe\sorder\sin\swhich\sWHERE\sclause\sterms\sare\sprocessed\scomport\smore\sclosely\sto\susers\sexpectations. +D 2016-09-26T14:39:05.023 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f @@ -386,7 +386,7 @@ F src/printf.c a5f0ca08ddede803c241266abb46356ec748ded1 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 3c3cf0dc719cd2a32ab5c1e10c26481dd565492e F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac -F src/select.c fb9da69a36382cf9cf57fb7a93247bf3de5a81ae +F src/select.c 6dede310d202f7a0da7f4ac1921f153707fa3d4f F src/shell.c b80396d2fadce4681397707e30078bf416e1dec2 F src/sqlite.h.in 2683a291ed8db5228024267be6421f0de507b80e F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1525,7 +1525,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 795454a3fa5f9ccc486593b5e16e8fad38c934fb -R 0064134bdfbafdb61f074a12abc7c569 -U drh -Z 916f6b7f03e59b6765f98d6400d7b198 +P fe89225eab777c2c9cb1cbc31092b9e39f516842 +R bd1b8b7597a40edc8cdb78ec48a115d9 +U dan +Z c695e6aeed2069a364c17cb8286df68b diff --git a/manifest.uuid b/manifest.uuid index 771d6a8e05..3e2a0bc1b0 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -fe89225eab777c2c9cb1cbc31092b9e39f516842 \ No newline at end of file +cf7f9e6d5abff273dd2f8a8dce27d52e1449b3be \ No newline at end of file diff --git a/src/select.c b/src/select.c index 6e4f4b99ed..a3badd12b5 100644 --- a/src/select.c +++ b/src/select.c @@ -3695,12 +3695,13 @@ static int flattenSubquery( assert( pParent->pHaving==0 ); pParent->pHaving = pParent->pWhere; pParent->pWhere = pWhere; - pParent->pHaving = sqlite3ExprAnd(db, pParent->pHaving, - sqlite3ExprDup(db, pSub->pHaving, 0)); + pParent->pHaving = sqlite3ExprAnd(db, + sqlite3ExprDup(db, pSub->pHaving, 0), pParent->pHaving + ); assert( pParent->pGroupBy==0 ); pParent->pGroupBy = sqlite3ExprListDup(db, pSub->pGroupBy, 0); }else{ - pParent->pWhere = sqlite3ExprAnd(db, pParent->pWhere, pWhere); + pParent->pWhere = sqlite3ExprAnd(db, pWhere, pParent->pWhere); } substSelect(db, pParent, iParent, pSub->pEList, 0);