]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure partial indexes are not qualified incorrectly by a constraint that
authordrh <drh@noemail.net>
Tue, 24 Feb 2015 20:12:57 +0000 (20:12 +0000)
committerdrh <drh@noemail.net>
Tue, 24 Feb 2015 20:12:57 +0000 (20:12 +0000)
is inside the ON clause of a LEFT JOIN.  Fix for ticket [2326c258d02ead33].
Cherry-pick from [491cfe9b3f87f].

FossilOrigin-Name: 9d94ac6a8b7a2721c15745184b3bb09b15a82503

manifest
manifest.uuid
src/where.c
test/autoindex4.test
test/index6.test

index 03cfba192837550a17670e4c24f5cd6d1a92189d..d4e3a325e2d564be16609c6c73f706ffa75b1810 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Increase\sthe\sversion\snumber\sto\s3.8.8.3
-D 2015-02-24T16:22:01.861
+C Make\ssure\spartial\sindexes\sare\snot\squalified\sincorrectly\sby\sa\sconstraint\sthat\nis\sinside\sthe\sON\sclause\sof\sa\sLEFT\sJOIN.\s\sFix\sfor\sticket\s[2326c258d02ead33].\nCherry-pick\sfrom\s[491cfe9b3f87f].
+D 2015-02-24T20:12:57.079
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5407a688f4d77a05c18a8142be8ae5a2829dd610
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -305,7 +305,7 @@ F src/vtab.c c08ec66f45919eaa726bf88aa53eb08379d607f9
 F src/wal.c 39303f2c9db02a4e422cd8eb2c8760420c6a51fe
 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
-F src/where.c d46de821bc604a4fd36fa3928c086950e91aafb1
+F src/where.c 88509f19a64a36e1c22a1dbdac74ee1a62d99dc3
 F src/whereInt.h d3633e9b592103241b74b0ec76185f3e5b8b62e0
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
@@ -349,7 +349,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 49d3cd791a9baa16fb461d7ea3de80d019a819cf
 F test/autovacuum.test 941892505d2c0f410a0cb5970dfa1c7c4e5f6e74
 F test/autovacuum_ioerr2.test 8a367b224183ad801e0e24dcb7d1501f45f244b4
 F test/avtrans.test 0252654f4295ddda3b2cce0e894812259e655a85
@@ -650,7 +650,7 @@ F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6
 F test/index3.test 55a90cff99834305e8141df7afaef39674b57062
 F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6
 F test/index5.test 25b0b451aceed4ac5f7d49f856f6de7257470b3e
-F test/index6.test fb370966ac3cd0989053dd5385757b5c3e24ab6a
+F test/index6.test c56852451b574ad5b2a1789e566e62e6ab244f42
 F test/index7.test 917cf1e1c7439bb155abbeabec511b28945e157b
 F test/indexedby.test b2f22f3e693a53813aa3f50b812eb609ba6df1ec
 F test/indexfault.test 31d4ab9a7d2f6e9616933eb079722362a883eb1d
@@ -1237,7 +1237,8 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P b20824628f92dfa97533e9f751264b77129cc468
-R 1d12159d5ce064f942cf8d82a191d03d
+P a92afe7d8cc7d0e84d843c8ea7ef714994c3585c
+Q +491cfe9b3f87f5fcc579f953745012cea8d64db7
+R e6b4de7ecd23615c982ef0db9e9401c6
 U drh
-Z d2c2bb21cec144f949d676c43bb1b0d3
+Z 41a907f033a9b3020b069f727af1463b
index 4acb20fc0880ca527d170c4859c6f0f1b9d7346e..4e8e60fdd7c941680afc7acf7d76b60e526c7798 100644 (file)
@@ -1 +1 @@
-a92afe7d8cc7d0e84d843c8ea7ef714994c3585c
\ No newline at end of file
+9d94ac6a8b7a2721c15745184b3bb09b15a82503
\ No newline at end of file
index 183a8cb66790d38a6ac6698d1dca8f5e604e1a7c..f45da74794aacb389f8acc8beda13f2bb6024b72 100644 (file)
@@ -1614,6 +1614,7 @@ static void constructAutomaticIndex(
   for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
     if( pLoop->prereq==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));
@@ -4694,7 +4695,11 @@ static int whereUsablePartialIndex(int iTab, WhereClause *pWC, Expr *pWhere){
   int i;
   WhereTerm *pTerm;
   for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
-    if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab) ) return 1;
+    if( sqlite3ExprImpliesExpr(pTerm->pExpr, pWhere, iTab)
+     && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
+    ){
+      return 1;
+    }
   }
   return 0;
 }
index 6d0865bf720f9fefb9010341fc360a80138b99ea..0e7a80df216d9ef41537ba2c4e3d5dc790f9dc5a 100644 (file)
@@ -49,4 +49,35 @@ 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}
+do_execsql_test autoindex4-3.1 {
+  CREATE INDEX Items_x1 ON Items(ItemName,Name) WHERE ItemName = 'dummy';
+  
+  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
index 68bdd06c14b477c31f9c276828925688b333492e..8414b11baafe5056db6892a3ca13f67362e7242f 100644 (file)
@@ -267,5 +267,33 @@ do_execsql_test index6-6.2 {
   PRAGMA integrity_check;
 } {ok}
 
+# Test case for ticket [2326c258d02ead33d69faa63de8f4686b9b1b9d9] on
+# 2015-02-24.  Any use of a partial index qualifying constraint inside
+# the ON clause of a LEFT JOIN was causing incorrect results for all
+# versions of SQLite 3.8.0 through 3.8.8.
+#
+do_execsql_test index6-7.0 {
+  CREATE TABLE t7a(x);
+  CREATE TABLE t7b(y);
+  INSERT INTO t7a(x) VALUES(1);
+  CREATE INDEX t7ax ON t7a(x) WHERE x=99;
+  PRAGMA automatic_index=OFF;
+  SELECT * FROM t7a LEFT JOIN t7b ON (x=99) ORDER BY x;
+} {1 {}}
+do_execsql_test index6-7.1 {
+  INSERT INTO t7b(y) VALUES(2);
+  SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x;
+} {}
+do_execsql_test index6-7.2 {
+  INSERT INTO t7a(x) VALUES(99);
+  SELECT * FROM t7a LEFT JOIN t7b ON (x=99) ORDER BY x;
+} {1 {} 99 2}
+do_execsql_test index6-7.3 {
+  SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x;
+} {99 2}
+do_execsql_test index6-7.4 {
+  EXPLAIN QUERY PLAN
+  SELECT * FROM t7a JOIN t7b ON (x=99) ORDER BY x;
+} {/USING COVERING INDEX t7ax/}
 
 finish_test