From: drh Date: Tue, 24 Feb 2015 16:05:54 +0000 (+0000) Subject: Make sure partial automatic indexes are not based on terms in the ON clause X-Git-Tag: version-3.8.9~119^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=36f65bafe5c571a3548435751939a99155b5f129;p=thirdparty%2Fsqlite.git Make sure partial automatic indexes are not based on terms in the ON clause of a LEFT JOIN. Fix for ticket [2326c258d02ead3]. FossilOrigin-Name: c0f4e308a508183b72ceda447dc3ac778cb85b9f --- diff --git a/manifest b/manifest index 8dd0ff3390..34750ae8f3 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sdocument\son\ssqlite3_mprintf()\sand\srelated\sfunctions.\s\sDiscuss\sthe\n%w\sformat\sand\spoint\sout\sthat\sobscure\sANSI-C\sformats\sare\snot\ssupported.\nNo\schanges\sto\scode. -D 2015-02-21T15:42:57.800 +C Make\ssure\spartial\sautomatic\sindexes\sare\snot\sbased\son\sterms\sin\sthe\sON\sclause\nof\sa\sLEFT\sJOIN.\s\sFix\sfor\sticket\s[2326c258d02ead3]. +D 2015-02-24T16:05:54.976 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 6b9e7677829aa94b9f30949656e27312aefb9a46 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -306,7 +306,7 @@ F src/vtab.c 699f2b8d509cfe379c33dde33827875d5b030e01 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 -F src/where.c d46de821bc604a4fd36fa3928c086950e91aafb1 +F src/where.c 59ab7da73b0de376d945c96c2867a1d550686717 F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -350,7 +350,7 @@ F test/autoinc.test c58912526998a39e11f66b533e23cfabea7f25b7 F test/autoindex1.test 6ff78b94f43a59616c06c11c55b12935173506d7 F test/autoindex2.test af7e595c6864cc6ef5fc38d5db579a3e34940cb8 F test/autoindex3.test a3be0d1a53a7d2edff208a5e442312957047e972 -F test/autoindex4.test fc807f9efd158bec60f5dfdf34ebe46fb274612d +F test/autoindex4.test 364be4c1654267720aa537beba4ef0ca4d7f60d9 F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85 @@ -1239,7 +1239,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c299e55a661c04f71ab43cb8aed04f8ece6e0567 -R dda772aafb6dee5a528cc1c5d5a14dc2 +P f8917ba4d917bc762b3b252466ab72a8a70dc0d8 +R 3f565b8438472847d9367d99d4186ffd U drh -Z 75f83919b9b483315b93f05f4ef8627c +Z f1617e86199163d366d582f2564e1bac diff --git a/manifest.uuid b/manifest.uuid index c46ad20405..8ebe715cb4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f8917ba4d917bc762b3b252466ab72a8a70dc0d8 \ No newline at end of file +c0f4e308a508183b72ceda447dc3ac778cb85b9f \ No newline at end of file diff --git a/src/where.c b/src/where.c index 183a8cb667..aef1820e80 100644 --- a/src/where.c +++ b/src/where.c @@ -1614,6 +1614,7 @@ static void constructAutomaticIndex( for(pTerm=pWC->a; pTermprereq==0 && (pTerm->wtFlags & TERM_VIRTUAL)==0 + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) && sqlite3ExprIsTableConstant(pTerm->pExpr, pSrc->iCursor) ){ pPartial = sqlite3ExprAnd(pParse->db, pPartial, sqlite3ExprDup(pParse->db, pTerm->pExpr, 0)); diff --git a/test/autoindex4.test b/test/autoindex4.test index 6d0865bf72..8e32462df4 100644 --- a/test/autoindex4.test +++ b/test/autoindex4.test @@ -49,4 +49,25 @@ do_execsql_test autoindex4-2.0 { ORDER BY rowid; } {1 123 654 | 0 555 444 | 4 234 987 |} +# Ticket [2326c258d02ead33d] +# Two joins, one with and the other without an ORDER BY clause. +# The one without ORDER BY correctly returns two rows of result. +# The one with ORDER BY returns no rows. +# +do_execsql_test autoindex4-3.0 { + CREATE TABLE A(Name text); + CREATE TABLE Items(ItemName text , Name text); + INSERT INTO Items VALUES('Item1','Parent'); + INSERT INTO Items VALUES('Item2','Parent'); + CREATE TABLE B(Name text); + + SELECT Items.ItemName + FROM Items + LEFT JOIN A ON (A.Name = Items.ItemName and Items.ItemName = 'dummy') + LEFT JOIN B ON (B.Name = Items.ItemName) + WHERE Items.Name = 'Parent' + ORDER BY Items.ItemName; +} {Item1 Item2} + + finish_test