]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
If all branches of an OR optimize scan that is the rhs of a LEFT JOIN use the
authordrh <drh@noemail.net>
Thu, 3 Nov 2016 18:33:52 +0000 (18:33 +0000)
committerdrh <drh@noemail.net>
Thu, 3 Nov 2016 18:33:52 +0000 (18:33 +0000)
same index, set the index cursor to return NULL values if there are no matches
for a row on the lhs.  Fix for ticket [34a579141b2c5ac]

FossilOrigin-Name: 54eeddeceb7545c9843d4ddf4ff73a894214c43b

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

index 8b19dc5c9239d925d5d8d5b4246aef2f4746962f..1248a42fe40ebc59b98c54c08a3ebf6d0c42f023 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C In\sthe\ssessions\smodule,\savoid\srecording\sa\schange\sif\san\sUPDATE\sstatement\noverwrites\sa\scolumn\swith\sREAL\saffinity\scontaining\san\sinteger\svalue\swith\s\nthe\ssame\svalue.
-D 2016-11-03T18:31:40.361
+C If\sall\sbranches\sof\san\sOR\soptimize\sscan\sthat\sis\sthe\srhs\sof\sa\sLEFT\sJOIN\suse\sthe\nsame\sindex,\sset\sthe\sindex\scursor\sto\sreturn\sNULL\svalues\sif\sthere\sare\sno\smatches\nfor\sa\srow\son\sthe\slhs.\s\sFix\sfor\sticket\s[34a579141b2c5ac]
+D 2016-11-03T18:33:52.696
 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678
 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
 F Makefile.msc 5151cc64c4c05f3455f4f692ad11410a810d937f
@@ -468,7 +468,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c 02eeecc265f6ffd0597378f5d8ae9070b62a406a
 F src/wal.h 6dd221ed384afdc204bc61e25c23ef7fd5a511f2
 F src/walker.c 91a6df7435827e41cff6bb7df50ea00934ee78b0
-F src/where.c 5f846d94bb3d35b3146d9915eb301ee362957b0a
+F src/where.c 125af074723cf390d0e71ed1ca385240e6d4ea7c
 F src/whereInt.h 2bcc3d176e6091cb8f50a30b65c006e88a73614d
 F src/wherecode.c 717a65294df46f30e9b9933d2a63a4bcbca5a9a8
 F src/whereexpr.c 379d0017fb7bc9e5a4d8cd4b056c747de946430e
@@ -1409,7 +1409,7 @@ F test/where9.test 729c3ba9b47e8f9f1aab96bae7dad2a524f1d1a2
 F test/whereA.test 4d253178d135ec46d1671e440cd8f2b916aa6e6b
 F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5
 F test/whereC.test cae295158703cb3fc23bf1a108a9ab730efff0f6
-F test/whereD.test 51366b07cb6f546cd30cc803f7e754f063b940de
+F test/whereD.test 711d4df58d6d4fb9b3f5ce040b818564198be002
 F test/whereE.test b3a055eef928c992b0a33198a7b8dc10eea5ad2f
 F test/whereF.test 5b2ba0dbe8074aa13e416b37c753991f0a2492d7
 F test/whereG.test dde4c52a97385a55be6a7cd46be8373f0cf35501
@@ -1526,8 +1526,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 63cfe19724b5856bd246c6fb98d3d79f8e022f71
-Q +5f3e602831ba2ecaf8ba5411efb387afcde05a33
-R fcf2469686fdd99311b823fa3dc6b687
+P 0fc4f0f4c270d29ec9c03d2954ef57f98461ede8
+Q +ec9dab8054c71d112c68f58a45821b38c2a45677
+R b74c0a845e2e5047c9a6af740eb668f6
 U drh
-Z d0ff821c6b80628a32af0e2f8342ffa9
+Z fac95abf508553a060f232c04f72da9c
index 868e466e44f33fa9d184285dfbbca531024a67dd..b4c729fa1d75ce52e95b010d62c3865eb5f0967f 100644 (file)
@@ -1 +1 @@
-0fc4f0f4c270d29ec9c03d2954ef57f98461ede8
\ No newline at end of file
+54eeddeceb7545c9843d4ddf4ff73a894214c43b
\ No newline at end of file
index c75eb943f3f202a33aa3f4cf755dad437137b104..d77c333c34da6ddcc9381fcdf049603059e7b1f0 100644 (file)
@@ -4860,13 +4860,15 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
     }
 #endif
     if( pLevel->iLeftJoin ){
+      int ws = pLoop->wsFlags;
       addr = sqlite3VdbeAddOp1(v, OP_IfPos, pLevel->iLeftJoin); VdbeCoverage(v);
-      assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
-           || (pLoop->wsFlags & WHERE_INDEXED)!=0 );
-      if( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 ){
+      assert( (ws & WHERE_IDX_ONLY)==0 || (ws & WHERE_INDEXED)!=0 );
+      if( (ws & WHERE_IDX_ONLY)==0 ){
         sqlite3VdbeAddOp1(v, OP_NullRow, pTabList->a[i].iCursor);
       }
-      if( pLoop->wsFlags & WHERE_INDEXED ){
+      if( (ws & WHERE_INDEXED) 
+       || ((ws & WHERE_MULTI_OR) && pLevel->u.pCovidx) 
+      ){
         sqlite3VdbeAddOp1(v, OP_NullRow, pLevel->iIdxCur);
       }
       if( pLevel->op==OP_Return ){
index de0f9618d2245e56e0abd7e6295936defb78f55f..8ced0ffc723ac9b2bc4816269a46cb9b06df4d1e 100644 (file)
@@ -337,4 +337,81 @@ do_searchcount_test 6.6.4 {
   SELECT c FROM x1 WHERE b=6 OR c=11 OR a=1
 } {7 11 3 search 7}
 
+#-------------------------------------------------------------------------
+#
+do_execsql_test 7.0 {
+  CREATE TABLE y1(a, b);
+  CREATE TABLE y2(x, y);
+  CREATE INDEX y2xy ON y2(x, y);
+  INSERT INTO y1 VALUES(1, 1);
+  INSERT INTO y2 VALUES(3, 3);
+}
+
+do_execsql_test 7.1 {
+  SELECT * FROM y1 LEFT JOIN y2 ON ((x=1 AND y=b) OR (x=2 AND y=b))
+} {1 1 {} {}}
+
+do_execsql_test 7.3 {
+  CREATE TABLE foo (Id INTEGER PRIMARY KEY, fa INTEGER, fb INTEGER); 
+  CREATE TABLE bar (Id INTEGER PRIMARY KEY, ba INTEGER, bb INTEGER);
+
+  INSERT INTO foo VALUES(1, 1, 1);
+  INSERT INTO foo VALUES(2, 1, 2);
+  INSERT INTO foo VALUES(3, 1, 3);
+  INSERT INTO foo VALUES(4, 1, 4);
+  INSERT INTO foo VALUES(5, 1, 5);
+  INSERT INTO foo VALUES(6, 1, 6);
+  INSERT INTO foo VALUES(7, 1, 7);
+  INSERT INTO foo VALUES(8, 1, 8);
+  INSERT INTO foo VALUES(9, 1, 9);
+
+  INSERT INTO bar VALUES(NULL, 1, 1);
+  INSERT INTO bar VALUES(NULL, 2, 2);
+  INSERT INTO bar VALUES(NULL, 3, 3);
+  INSERT INTO bar VALUES(NULL, 1, 4);
+  INSERT INTO bar VALUES(NULL, 2, 5);
+  INSERT INTO bar VALUES(NULL, 3, 6);
+  INSERT INTO bar VALUES(NULL, 1, 7);
+  INSERT INTO bar VALUES(NULL, 2, 8);
+  INSERT INTO bar VALUES(NULL, 3, 9);
+}
+
+do_execsql_test 7.4 {
+  SELECT 
+    bar.Id, bar.ba, bar.bb, foo.fb
+    FROM foo LEFT JOIN bar
+           ON (bar.ba = 1 AND bar.bb = foo.fb)
+           OR (bar.ba = 5 AND bar.bb = foo.fb);
+} {
+  1 1 1 1 
+  {} {} {} 2 
+  {} {} {} 3 
+  4 1 4 4 
+  {} {} {} 5 
+  {} {} {} 6 
+  7 1 7 7 
+  {} {} {} 8 
+  {} {} {} 9
+}
+
+do_execsql_test 7.5 {
+  CREATE INDEX idx_bar ON bar(ba, bb);
+  SELECT 
+    bar.Id, bar.ba, bar.bb, foo.fb
+    FROM foo LEFT JOIN bar
+           ON (bar.ba = 1 AND bar.bb = foo.fb)
+           OR (bar.ba = 5 AND bar.bb = foo.fb);
+} {
+  1 1 1 1 
+  {} {} {} 2 
+  {} {} {} 3 
+  4 1 4 4 
+  {} {} {} 5 
+  {} {} {} 6 
+  7 1 7 7 
+  {} {} {} 8 
+  {} {} {} 9
+}
+
+
 finish_test