]> 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 leftjoin-or-fix
authordan <dan@noemail.net>
Wed, 26 Oct 2016 15:46:09 +0000 (15:46 +0000)
committerdan <dan@noemail.net>
Wed, 26 Oct 2016 15:46:09 +0000 (15:46 +0000)
same index, set the index cursor to return NULL values if there are no matches
for a row on the lhs.

FossilOrigin-Name: e7b9bc678ecb75c594d9d3ade12a99a8d551cdc9

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

index 08e0334a9c9acf8542068cafe69baeedf7ac90b1..64c4d72a0f36efdcab733a9ea5f1969f528d479e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Merge\sthe\sSQLITE_ENABLE_URI_00_ERROR\scompile-time\soption.
-D 2016-10-26T13:58:47.701
+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.
+D 2016-10-26T15:46:09.768
 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 0b44e89742024d3b6992bf404d2ab692113e1e60
 F src/wal.h bf03a23da3100ab25e5c0363450233cfee09cfc2
 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
@@ -1411,7 +1411,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
@@ -1528,8 +1528,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P b115856408b6aa5538be67beb619d7aff0630bea 1aaa06e37f44309c62335d8eda59ca6890d4be9d
-R 2575c94e1207131d6b2a9b2da34d054b
-T +closed 1aaa06e37f44309c62335d8eda59ca6890d4be9d
-U drh
-Z e54eab78f5c7dec3e7cf474d4365bacf
+P 86675ae0abc78960a2faec55d115804acfc3be6d
+R c240eb27502d404e84b4aff903524b82
+T *branch * leftjoin-or-fix
+T *sym-leftjoin-or-fix *
+T -sym-trunk *
+U dan
+Z e658c0fae6fabdecf9bbfe3c9f4a5ad1
index 7a8e3f00f48f4363dc390b42ca03a7d03226f77e..e0be9f7b69417e90114ab4e7ccb6f81c478d73b5 100644 (file)
@@ -1 +1 @@
-86675ae0abc78960a2faec55d115804acfc3be6d
\ No newline at end of file
+e7b9bc678ecb75c594d9d3ade12a99a8d551cdc9
\ 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