From bfca6a40669f0acfe0ec9b8cf4e8b58d544e383f Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 24 Aug 2012 10:52:35 +0000 Subject: [PATCH 1/8] Experimental change to support the covering index optimization for queries with OR terms in the WHERE clause that search a single index more than once. FossilOrigin-Name: 1dc8c7c741a82bb98a07f3fdb8142d8bc8d8a98b --- manifest | 20 +++++++++++-------- manifest.uuid | 2 +- src/sqliteInt.h | 1 + src/where.c | 50 ++++++++++++++++++++++++++++++++++++++++++++---- test/whereD.test | 36 ++++++++++++++++++++++++++++++++++ 5 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 test/whereD.test diff --git a/manifest b/manifest index 09414718bc..cde938ca24 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Merge\sthe\snested\saggregate\squery\senhancements\sinto\strunk. -D 2012-08-24T01:07:52.214 +C Experimental\schange\sto\ssupport\sthe\scovering\sindex\soptimization\sfor\squeries\swith\sOR\sterms\sin\sthe\sWHERE\sclause\sthat\ssearch\sa\ssingle\sindex\smore\sthan\sonce. +D 2012-08-24T10:52:35.794 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -180,7 +180,7 @@ F src/select.c 2c0291db072924cace54aadbff1996297e9b8de0 F src/shell.c 076e1c90d594644f36027c8ecff9a392cf2d3a06 F src/sqlite.h.in f664797c68ced43c2ea2c541d4ec8e1e04ec68ac F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 -F src/sqliteInt.h f4748d18114510f61e6de8bac0d513dc76e8f21c +F src/sqliteInt.h 66b3bc97e63dcb65c71ceddd668c1c7ca30f78f7 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 35939e7e03abf1b7577ce311f48f682c40de3208 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -250,7 +250,7 @@ F src/vtab.c bb8ea3a26608bb1357538a5d2fc72beba6638998 F src/wal.c 9294df6f96aae5909ae1a9b733fd1e1b4736978b F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b -F src/where.c 24c7494d8875ead994b4dfe5461340c27fd424ca +F src/where.c b4d98014de3ce6e0e9a63ba16018fff89dc72d73 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00 @@ -965,6 +965,7 @@ F test/where9.test ae98dc22ef9b6f2bc81e9f164e41b38faa9bda06 F test/whereA.test 24c234263c8fe358f079d5e57d884fb569d2da0a F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test 13ff5ec0dba407c0e0c075980c75b3275a6774e5 +F test/whereD.test 54e11307e85c2ae987744f0fefd34214f752ba49 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/win32lock.test b2a539e85ae6b2d78475e016a9636b4451dc7fb9 F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 @@ -1012,7 +1013,10 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P 20f184f2d5908badd9d44d4fe2ad7c9e182c8803 00b1dc71be4c3420730b5f7840af824ea86165e7 -R c1fab8e17aa8935c76d7626b4d7fe139 -U drh -Z 3e9a3890be18a0a197379668b716e1a3 +P d4cd6017c9875947a05b1dc36538d4272fb18739 +R 0e14b06eb4293757e84906b2ad3f48bd +T *branch * multi-or-covering-index +T *sym-multi-or-covering-index * +T -sym-trunk * +U dan +Z a3dcd5ab6d90b9bc7bd57494f6da388a diff --git a/manifest.uuid b/manifest.uuid index 78d216df97..af0b97af79 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d4cd6017c9875947a05b1dc36538d4272fb18739 \ No newline at end of file +1dc8c7c741a82bb98a07f3fdb8142d8bc8d8a98b \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 443eaa4035..5cb10ca920 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1948,6 +1948,7 @@ struct WhereLevel { } *aInLoop; /* Information about each nested IN operator */ } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */ } u; + Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR levels */ /* The following field is really not part of the current level. But ** we need a place to cache virtual table index information for each diff --git a/src/where.c b/src/where.c index d324228c9f..cbe94b561d 100644 --- a/src/where.c +++ b/src/where.c @@ -4297,6 +4297,8 @@ static Bitmask codeOneLoopStart( */ WhereClause *pOrWc; /* The OR-clause broken out into subterms */ SrcList *pOrTab; /* Shortened table list or OR-clause generation */ + Index *pCov = 0; /* Potential covering index (or NULL) */ + int iCovCur = 0; /* Cursor used to open pCov */ int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */ int regRowset = 0; /* Register for RowSet object */ @@ -4315,7 +4317,7 @@ static Bitmask codeOneLoopStart( pLevel->op = OP_Return; pLevel->p1 = regReturn; - /* Set up a new SrcList ni pOrTab containing the table being scanned + /* Set up a new SrcList in pOrTab containing the table being scanned ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. ** This becomes the SrcList in the recursive call to sqlite3WhereBegin(). */ @@ -4393,7 +4395,9 @@ static Bitmask codeOneLoopStart( pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY); + assert( pSubWInfo || pParse->nErr || pParse->db->mallocFailed ); if( pSubWInfo ){ + WhereLevel *pLvl; explainOneScan( pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0 ); @@ -4414,11 +4418,45 @@ static Bitmask codeOneLoopStart( */ if( pSubWInfo->untestedTerms ) untestedTerms = 1; + /* If all of the OR-connected terms are optimized using the same + ** index, and the index is opened using the same cursor number + ** by each call to sqlite3WhereBegin() made by this loop, it may + ** be possible to use that index as a covering index. + ** + ** If the call to sqlite3WhereBegin() above resulted in a scan that + ** uses an index, and this is either the first OR-connected term + ** processed or the index is the same as that used by all previous + ** terms, set pCov to the candidate covering index and iCovCur to + ** the cursor number used to open it. Otherwise, set pCov to NULL + ** to indicate that no candidate covering index will be available. + */ + pLvl = &pSubWInfo->a[0]; + if( (pLvl->plan.wsFlags & WHERE_INDEXED)!=0 + && (pLvl->plan.wsFlags & WHERE_TEMP_INDEX)==0 + && (pLvl->iIdxCur==pParse->nTab-1) + && (ii==0 || (pLvl->plan.u.pIdx==pCov && pLvl->iIdxCur==iCovCur)) + ){ + pCov = pLvl->plan.u.pIdx; + iCovCur = pLvl->iIdxCur; + /* Decrement pParse->nTab in order to make cursor number iCovCur + ** available to the next OR-connected term. */ + pParse->nTab--; + }else{ + pCov = 0; + } + /* Finish the loop through table entries that match term pOrTerm. */ sqlite3WhereEnd(pSubWInfo); } } } + /* Increment pParse->nTab here to ensure that it really is larger than + ** the largest cursor number used by the VM (this may not be the case + ** if pParse->nTab was decremented by the final iteration of the loop + ** above). */ + pParse->nTab++; + pLevel->pCovidx = pCov; + pLevel->iIdxCur = iCovCur; if( pAndExpr ){ pAndExpr->pLeft = 0; sqlite3ExprDelete(pParse->db, pAndExpr); @@ -5208,6 +5246,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ */ assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc ); for(i=0, pLevel=pWInfo->a; inLevel; i++, pLevel++){ + Index *pIdx = 0; struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom]; Table *pTab = pTabItem->pTab; assert( pTab!=0 ); @@ -5237,12 +5276,15 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ ** that reference the table and converts them into opcodes that ** reference the index. */ - if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){ + if( pLevel->plan.wsFlags & WHERE_INDEXED ){ + pIdx = pLevel->plan.u.pIdx; + }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){ + pIdx = pLevel->pCovidx; + } + if( pIdx && !db->mallocFailed){ int k, j, last; VdbeOp *pOp; - Index *pIdx = pLevel->plan.u.pIdx; - assert( pIdx!=0 ); pOp = sqlite3VdbeGetOp(v, pWInfo->iTop); last = sqlite3VdbeCurrentAddr(v); for(k=pWInfo->iTop; k Date: Fri, 24 Aug 2012 15:29:03 +0000 Subject: [PATCH 2/8] Additional test cases for OR-optimization with covering indices, including one test case that currently fails. FossilOrigin-Name: d8b7ab37120ac20e60b6a600cd0e5b34a09cf97a --- manifest | 17 +++++++--------- manifest.uuid | 2 +- test/whereD.test | 53 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index cde938ca24..d50c519f35 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Experimental\schange\sto\ssupport\sthe\scovering\sindex\soptimization\sfor\squeries\swith\sOR\sterms\sin\sthe\sWHERE\sclause\sthat\ssearch\sa\ssingle\sindex\smore\sthan\sonce. -D 2012-08-24T10:52:35.794 +C Additional\stest\scases\sfor\sOR-optimization\swith\scovering\sindices,\sincluding\none\stest\scase\sthat\scurrently\sfails. +D 2012-08-24T15:29:03.804 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -965,7 +965,7 @@ F test/where9.test ae98dc22ef9b6f2bc81e9f164e41b38faa9bda06 F test/whereA.test 24c234263c8fe358f079d5e57d884fb569d2da0a F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test 13ff5ec0dba407c0e0c075980c75b3275a6774e5 -F test/whereD.test 54e11307e85c2ae987744f0fefd34214f752ba49 +F test/whereD.test 1aee8a7b3a0674d8d0119d764e069225ce426406 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/win32lock.test b2a539e85ae6b2d78475e016a9636b4451dc7fb9 F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 @@ -1013,10 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P d4cd6017c9875947a05b1dc36538d4272fb18739 -R 0e14b06eb4293757e84906b2ad3f48bd -T *branch * multi-or-covering-index -T *sym-multi-or-covering-index * -T -sym-trunk * -U dan -Z a3dcd5ab6d90b9bc7bd57494f6da388a +P 1dc8c7c741a82bb98a07f3fdb8142d8bc8d8a98b +R 0de9e52cb560b3160307382415072714 +U drh +Z f74e9ea8f0417bf70ede532a4ecba542 diff --git a/manifest.uuid b/manifest.uuid index af0b97af79..590ba48360 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1dc8c7c741a82bb98a07f3fdb8142d8bc8d8a98b \ No newline at end of file +d8b7ab37120ac20e60b6a600cd0e5b34a09cf97a \ No newline at end of file diff --git a/test/whereD.test b/test/whereD.test index 10ccbb7d0a..3098b1acfd 100644 --- a/test/whereD.test +++ b/test/whereD.test @@ -19,18 +19,57 @@ source $testdir/tester.tcl set ::testprefix whereD do_execsql_test 1.1 { - CREATE TABLE t(i,j,k); - CREATE INDEX i ON t(i,j,k); + CREATE TABLE t(i,j,k,m,n); + CREATE INDEX ijk ON t(i,j,k); + CREATE INDEX jmn ON t(j,m,n); - INSERT INTO t VALUES(3, 3, 'three'); - INSERT INTO t VALUES(2, 2, 'two'); - INSERT INTO t VALUES(1, 1, 'one'); - INSERT INTO t VALUES(4, 4, 'four'); + INSERT INTO t VALUES(3, 3, 'three', 3, 3); + INSERT INTO t VALUES(2, 2, 'two', 2, 2); + INSERT INTO t VALUES(1, 1, 'one', 1, 1); + INSERT INTO t VALUES(4, 4, 'four', 4, 4); } do_execsql_test 1.2 { SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2); } {one two} +do_execsql_test 1.3 { + SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (i=3 AND j=3); +} {one two three} +do_execsql_test 1.4 { + SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2); +} {one two} +do_execsql_test 1.5 { + SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (j=3 AND m=3); +} {one two three} +do_execsql_test 1.6 { + SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2) OR (i=3 AND j=3); +} {one two three} +do_execsql_test 1.7 { + SELECT k FROM t WHERE (j=1 AND m=1) OR (i=2 AND j=2) OR (i=3 AND j=3); +} {one two three} +do_execsql_test 1.8 { + SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND i=2) OR (i=3 AND j=3); +} {one two three} + +do_execsql_test 2.0 { + CREATE TABLE t1(a,b,c,d); + CREATE INDEX t1b ON t1(b); + CREATE INDEX t1c ON t1(c); + CREATE INDEX t1d ON t1(d); + CREATE TABLE t2(x,y); + CREATE INDEX t2y ON t2(y); + + INSERT INTO t1 VALUES(1,2,3,4); + INSERT INTO t1 VALUES(5,6,7,8); + INSERT INTO t2 VALUES(1,2); + INSERT INTO t2 VALUES(2,7); + INSERT INTO t2 VALUES(3,4); +} {} +do_execsql_test 2.1 { + SELECT a, x FROM t1 JOIN t2 ON +y=d OR x=7 ORDER BY a, x; +} {1 3} +do_execsql_test 2.2 { + SELECT a, x FROM t1 JOIN t2 ON y=d OR x=7 ORDER BY a, x; +} {1 3} finish_test - From 8fea5f3b97395b5d404e9c35ccae06f2fbc43e5e Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Aug 2012 17:52:54 +0000 Subject: [PATCH 3/8] More test cases for OR-optimization covering indices. FossilOrigin-Name: e5c3190c27b69dc50f348c849a81b79031b2fb67 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/whereD.test | 42 +++++++++++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index d50c519f35..bd45eba640 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\stest\scases\sfor\sOR-optimization\swith\scovering\sindices,\sincluding\none\stest\scase\sthat\scurrently\sfails. -D 2012-08-24T15:29:03.804 +C More\stest\scases\sfor\sOR-optimization\scovering\sindices. +D 2012-08-24T17:52:54.133 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -965,7 +965,7 @@ F test/where9.test ae98dc22ef9b6f2bc81e9f164e41b38faa9bda06 F test/whereA.test 24c234263c8fe358f079d5e57d884fb569d2da0a F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test 13ff5ec0dba407c0e0c075980c75b3275a6774e5 -F test/whereD.test 1aee8a7b3a0674d8d0119d764e069225ce426406 +F test/whereD.test 1322fdcfbcc5e6eb6bb3b5d69930e231da388cc6 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/win32lock.test b2a539e85ae6b2d78475e016a9636b4451dc7fb9 F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 @@ -1013,7 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P 1dc8c7c741a82bb98a07f3fdb8142d8bc8d8a98b -R 0de9e52cb560b3160307382415072714 +P d8b7ab37120ac20e60b6a600cd0e5b34a09cf97a +R 1216a31c3d13954b6b3320ccc0d31427 U drh -Z f74e9ea8f0417bf70ede532a4ecba542 +Z 34330edabbd56fc5c7c7902f48b24346 diff --git a/manifest.uuid b/manifest.uuid index 590ba48360..cc0fb09dfe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d8b7ab37120ac20e60b6a600cd0e5b34a09cf97a \ No newline at end of file +e5c3190c27b69dc50f348c849a81b79031b2fb67 \ No newline at end of file diff --git a/test/whereD.test b/test/whereD.test index 3098b1acfd..e9269232a4 100644 --- a/test/whereD.test +++ b/test/whereD.test @@ -23,33 +23,57 @@ do_execsql_test 1.1 { CREATE INDEX ijk ON t(i,j,k); CREATE INDEX jmn ON t(j,m,n); - INSERT INTO t VALUES(3, 3, 'three', 3, 3); - INSERT INTO t VALUES(2, 2, 'two', 2, 2); - INSERT INTO t VALUES(1, 1, 'one', 1, 1); - INSERT INTO t VALUES(4, 4, 'four', 4, 4); + INSERT INTO t VALUES(3, 3, 'three', 3, 'tres'); + INSERT INTO t VALUES(2, 2, 'two', 2, 'dos'); + INSERT INTO t VALUES(1, 1, 'one', 1, 'uno'); + INSERT INTO t VALUES(4, 4, 'four', 4, 'cuatro'); } do_execsql_test 1.2 { SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2); } {one two} do_execsql_test 1.3 { + SELECT k FROM t WHERE (i=1 AND j=1) OR (+i=2 AND j=2); +} {one two} +do_execsql_test 1.4 { + SELECT n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2); +} {uno dos} +do_execsql_test 1.5 { + SELECT k, n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2); +} {one uno two dos} +do_execsql_test 1.6 { SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (i=3 AND j=3); } {one two three} -do_execsql_test 1.4 { +do_execsql_test 1.7 { + SELECT n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (i=3 AND j=3); +} {uno dos tres} +do_execsql_test 1.8 { SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2); } {one two} -do_execsql_test 1.5 { +do_execsql_test 1.9 { SELECT k FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (j=3 AND m=3); } {one two three} -do_execsql_test 1.6 { +do_execsql_test 1.10 { + SELECT n FROM t WHERE (i=1 AND j=1) OR (i=2 AND j=2) OR (j=3 AND m=3); +} {uno dos tres} +do_execsql_test 1.11 { SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2) OR (i=3 AND j=3); } {one two three} -do_execsql_test 1.7 { +do_execsql_test 1.12 { + SELECT n FROM t WHERE (i=1 AND j=1) OR (j=2 AND m=2) OR (i=3 AND j=3); +} {uno dos tres} +do_execsql_test 1.13 { SELECT k FROM t WHERE (j=1 AND m=1) OR (i=2 AND j=2) OR (i=3 AND j=3); } {one two three} -do_execsql_test 1.8 { +do_execsql_test 1.14 { SELECT k FROM t WHERE (i=1 AND j=1) OR (j=2 AND i=2) OR (i=3 AND j=3); } {one two three} +do_execsql_test 1.15 { + SELECT k FROM t WHERE (i=1 AND j=2) OR (i=2 AND j=1) OR (i=3 AND j=4); +} {} +do_execsql_test 1.16 { + SELECT k FROM t WHERE (i=1 AND (j=1 or j=2)) OR (i=3 AND j=3); +} {one three} do_execsql_test 2.0 { CREATE TABLE t1(a,b,c,d); From 0efb72c9695f37fed1908620156170e1a6807f7c Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 24 Aug 2012 18:44:56 +0000 Subject: [PATCH 4/8] Fix a problem to do with multi-or queries and automatic indexes. FossilOrigin-Name: a3e26038a1d9f3331239f777c67d1920d904aab0 --- manifest | 24 ++++++++++++------------ manifest.uuid | 2 +- src/delete.c | 2 +- src/fkey.c | 2 +- src/select.c | 6 +++--- src/sqliteInt.h | 3 ++- src/update.c | 2 +- src/where.c | 36 +++++++++++++++++------------------- 8 files changed, 38 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index bd45eba640..c92077aba0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C More\stest\scases\sfor\sOR-optimization\scovering\sindices. -D 2012-08-24T17:52:54.133 +C Fix\sa\sproblem\sto\sdo\swith\smulti-or\squeries\sand\sautomatic\sindexes. +D 2012-08-24T18:44:56.189 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -131,10 +131,10 @@ F src/callback.c 0cb4228cdcd827dcc5def98fb099edcc9142dbcd F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 500d019da966631ad957c37705642be87524463b F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 -F src/delete.c 4c20ea4f6213b3bc1c6a510586864b679946e05e +F src/delete.c 335f36750dc6ac88d580aa36a6487459be9889de F src/expr.c 217840a107dcc1e5dbb57cea311daad04bedbb9a F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb -F src/fkey.c 657212460bf5cfd3ae607d12ea62092844c227b5 +F src/fkey.c 9c77d842dc9961d92a06a65abb80c64ef1750296 F src/func.c 18dfedfb857e100b05755a1b12e88b389f957879 F src/global.c 4cfdca5cb0edd33c4d021baec4ede958cb2c793b F src/hash.c a4031441741932da9e7a65bee2b36b5d0e81c073 @@ -176,11 +176,11 @@ F src/printf.c 4a9f882f1c1787a8b494a2987765acf9d97ac21f F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 9e28280ec98035f31900fdd1db01f86f68ca6c32 F src/rowset.c f6a49f3e9579428024662f6e2931832511f831a1 -F src/select.c 2c0291db072924cace54aadbff1996297e9b8de0 +F src/select.c a9d68e04f07348038ac279f3316ee8f8e146f59a F src/shell.c 076e1c90d594644f36027c8ecff9a392cf2d3a06 F src/sqlite.h.in f664797c68ced43c2ea2c541d4ec8e1e04ec68ac F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 -F src/sqliteInt.h 66b3bc97e63dcb65c71ceddd668c1c7ca30f78f7 +F src/sqliteInt.h d5d74494335876dad1853b36559367927fe5f1e7 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 35939e7e03abf1b7577ce311f48f682c40de3208 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -233,7 +233,7 @@ F src/test_wholenumber.c 3d2b9ed1505c40ad5c5ca2ad16ae7a289d6cc251 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 F src/tokenize.c 1e86210d3976717a19238ea7b047fac481fe8c12 F src/trigger.c ee7e178fb9188f44b532cebd449a7c1df90fb684 -F src/update.c d3076782c887c10e882996550345da9c4c9f9dea +F src/update.c 28d2d098b43a2c70dae399896ea8a02f622410ef F src/utf.c 890c67dcfcc7a74623c95baac7535aadfe265e84 F src/util.c 0af2e515dc0dabacec931bca39525f6c3f1c5455 F src/vacuum.c 587a52bb8833d7ac15af8916f25437e2575028bd @@ -250,7 +250,7 @@ F src/vtab.c bb8ea3a26608bb1357538a5d2fc72beba6638998 F src/wal.c 9294df6f96aae5909ae1a9b733fd1e1b4736978b F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b -F src/where.c b4d98014de3ce6e0e9a63ba16018fff89dc72d73 +F src/where.c b95276a535d9096088ee3cbc3eee25652f1b0c93 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00 @@ -1013,7 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P d8b7ab37120ac20e60b6a600cd0e5b34a09cf97a -R 1216a31c3d13954b6b3320ccc0d31427 -U drh -Z 34330edabbd56fc5c7c7902f48b24346 +P e5c3190c27b69dc50f348c849a81b79031b2fb67 +R 1a9f451faf8fb885437a56c112ab8ef2 +U dan +Z 18419d426568216b7681f94d1ac9fe1c diff --git a/manifest.uuid b/manifest.uuid index cc0fb09dfe..fc85ed8c69 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e5c3190c27b69dc50f348c849a81b79031b2fb67 \ No newline at end of file +a3e26038a1d9f3331239f777c67d1920d904aab0 \ No newline at end of file diff --git a/src/delete.c b/src/delete.c index eead4856b1..44e5995a69 100644 --- a/src/delete.c +++ b/src/delete.c @@ -371,7 +371,7 @@ void sqlite3DeleteFrom( */ sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet); pWInfo = sqlite3WhereBegin( - pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK + pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0 ); if( pWInfo==0 ) goto delete_from_cleanup; regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0); diff --git a/src/fkey.c b/src/fkey.c index 82e4cdc471..9db3a71c38 100644 --- a/src/fkey.c +++ b/src/fkey.c @@ -560,7 +560,7 @@ static void fkScanChildren( ** clause. If the constraint is not deferred, throw an exception for ** each row found. Otherwise, for deferred constraints, increment the ** deferred constraint counter by nIncr for each row selected. */ - pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0); + pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0); if( nIncr>0 && pFKey->isDeferred==0 ){ sqlite3ParseToplevel(pParse)->mayAbort = 1; } diff --git a/src/select.c b/src/select.c index a4bb2d4969..b3860b0e38 100644 --- a/src/select.c +++ b/src/select.c @@ -4024,7 +4024,7 @@ int sqlite3Select( ExprList *pDist = (isDistinct ? p->pEList : 0); /* Begin the database scan. */ - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0,0); if( pWInfo==0 ) goto select_end; if( pWInfo->nRowOut < p->nSelectRow ) p->nSelectRow = pWInfo->nRowOut; @@ -4197,7 +4197,7 @@ int sqlite3Select( ** in the right order to begin with. */ sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0, 0); if( pWInfo==0 ) goto select_end; if( pGroupBy==0 ){ /* The optimizer is able to deliver rows in group by order so @@ -4466,7 +4466,7 @@ int sqlite3Select( ** of output. */ resetAccumulator(pParse, &sAggInfo); - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, 0, flag); + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax,0,flag,0); if( pWInfo==0 ){ sqlite3ExprListDelete(db, pDel); goto select_end; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 5cb10ca920..aa554a23ac 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2807,7 +2807,8 @@ Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, #endif void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); -WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**,ExprList*,u16); +WhereInfo *sqlite3WhereBegin( + Parse*,SrcList*,Expr*,ExprList**,ExprList*,u16,int); void sqlite3WhereEnd(WhereInfo*); int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); diff --git a/src/update.c b/src/update.c index 73d22690b5..96ba4df83d 100644 --- a/src/update.c +++ b/src/update.c @@ -313,7 +313,7 @@ void sqlite3Update( */ sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid); pWInfo = sqlite3WhereBegin( - pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED + pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, 0 ); if( pWInfo==0 ) goto update_cleanup; okOnePass = pWInfo->okOnePass; diff --git a/src/where.c b/src/where.c index cbe94b561d..05420c9fb2 100644 --- a/src/where.c +++ b/src/where.c @@ -4297,8 +4297,8 @@ static Bitmask codeOneLoopStart( */ WhereClause *pOrWc; /* The OR-clause broken out into subterms */ SrcList *pOrTab; /* Shortened table list or OR-clause generation */ - Index *pCov = 0; /* Potential covering index (or NULL) */ - int iCovCur = 0; /* Cursor used to open pCov */ + Index *pCov = 0; /* Potential covering index (or NULL) */ + int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */ int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */ int regRowset = 0; /* Register for RowSet object */ @@ -4394,7 +4394,7 @@ static Bitmask codeOneLoopStart( /* Loop through table entries that match term pOrTerm. */ pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | - WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY); + WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur); assert( pSubWInfo || pParse->nErr || pParse->db->mallocFailed ); if( pSubWInfo ){ WhereLevel *pLvl; @@ -4426,21 +4426,17 @@ static Bitmask codeOneLoopStart( ** If the call to sqlite3WhereBegin() above resulted in a scan that ** uses an index, and this is either the first OR-connected term ** processed or the index is the same as that used by all previous - ** terms, set pCov to the candidate covering index and iCovCur to - ** the cursor number used to open it. Otherwise, set pCov to NULL - ** to indicate that no candidate covering index will be available. + ** terms, set pCov to the candidate covering index. Otherwise, set + ** pCov to NULL to indicate that no candidate covering index will + ** be available. */ pLvl = &pSubWInfo->a[0]; if( (pLvl->plan.wsFlags & WHERE_INDEXED)!=0 && (pLvl->plan.wsFlags & WHERE_TEMP_INDEX)==0 - && (pLvl->iIdxCur==pParse->nTab-1) - && (ii==0 || (pLvl->plan.u.pIdx==pCov && pLvl->iIdxCur==iCovCur)) + && (ii==0 || pLvl->plan.u.pIdx==pCov) ){ + assert( pLvl->iIdxCur==iCovCur ); pCov = pLvl->plan.u.pIdx; - iCovCur = pLvl->iIdxCur; - /* Decrement pParse->nTab in order to make cursor number iCovCur - ** available to the next OR-connected term. */ - pParse->nTab--; }else{ pCov = 0; } @@ -4450,11 +4446,6 @@ static Bitmask codeOneLoopStart( } } } - /* Increment pParse->nTab here to ensure that it really is larger than - ** the largest cursor number used by the VM (this may not be the case - ** if pParse->nTab was decremented by the final iteration of the loop - ** above). */ - pParse->nTab++; pLevel->pCovidx = pCov; pLevel->iIdxCur = iCovCur; if( pAndExpr ){ @@ -4674,7 +4665,8 @@ WhereInfo *sqlite3WhereBegin( Expr *pWhere, /* The WHERE clause */ ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */ ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */ - u16 wctrlFlags /* One of the WHERE_* flags defined in sqliteInt.h */ + u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */ + int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */ ){ int i; /* Loop counter */ int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */ @@ -4994,7 +4986,13 @@ WhereInfo *sqlite3WhereBegin( testcase( bestPlan.plan.wsFlags & WHERE_INDEXED ); testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX ); if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){ - pLevel->iIdxCur = pParse->nTab++; + if( (wctrlFlags & WHERE_ONETABLE_ONLY) + && (bestPlan.plan.wsFlags & WHERE_TEMP_INDEX)==0 + ){ + pLevel->iIdxCur = iIdxCur; + }else{ + pLevel->iIdxCur = pParse->nTab++; + } }else{ pLevel->iIdxCur = -1; } From 899339154eb7c3a4b1a079df9197f89ee7524468 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 24 Aug 2012 19:52:25 +0000 Subject: [PATCH 5/8] Add extra tests to whereD.test. FossilOrigin-Name: 7e961eef6b7260dd8deb8b3812218a874c382885 --- manifest | 12 +++++----- manifest.uuid | 2 +- test/whereD.test | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index c92077aba0..cb3aee71fc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sproblem\sto\sdo\swith\smulti-or\squeries\sand\sautomatic\sindexes. -D 2012-08-24T18:44:56.189 +C Add\sextra\stests\sto\swhereD.test. +D 2012-08-24T19:52:25.350 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -965,7 +965,7 @@ F test/where9.test ae98dc22ef9b6f2bc81e9f164e41b38faa9bda06 F test/whereA.test 24c234263c8fe358f079d5e57d884fb569d2da0a F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test 13ff5ec0dba407c0e0c075980c75b3275a6774e5 -F test/whereD.test 1322fdcfbcc5e6eb6bb3b5d69930e231da388cc6 +F test/whereD.test 85b8aa329439b81e6844f65763eec84ae8db1604 F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/win32lock.test b2a539e85ae6b2d78475e016a9636b4451dc7fb9 F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 @@ -1013,7 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P e5c3190c27b69dc50f348c849a81b79031b2fb67 -R 1a9f451faf8fb885437a56c112ab8ef2 +P a3e26038a1d9f3331239f777c67d1920d904aab0 +R 818ec06d567f4218c34d00c712e0fbb7 U dan -Z 18419d426568216b7681f94d1ac9fe1c +Z 17fe6aa0374a8f5f1fd6fa7c61adf7ad diff --git a/manifest.uuid b/manifest.uuid index fc85ed8c69..d1c3e69140 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3e26038a1d9f3331239f777c67d1920d904aab0 \ No newline at end of file +7e961eef6b7260dd8deb8b3812218a874c382885 \ No newline at end of file diff --git a/test/whereD.test b/test/whereD.test index e9269232a4..8bc8ef986f 100644 --- a/test/whereD.test +++ b/test/whereD.test @@ -96,4 +96,63 @@ do_execsql_test 2.2 { SELECT a, x FROM t1 JOIN t2 ON y=d OR x=7 ORDER BY a, x; } {1 3} + +# Similar to [do_execsql_test], except that two elements are appended +# to the result - the string "search" and the number of times test variable +# sqlite3_search_count is incremented by running the supplied SQL. e.g. +# +# do_searchcount_test 1.0 { SELECT * FROM t1 } {x y search 2} +# +proc do_searchcount_test {tn sql res} { + uplevel [subst -nocommands { + do_test $tn { + set ::sqlite_search_count 0 + concat [db eval {$sql}] search [set ::sqlite_search_count] + } [list $res] + }] +} + +do_execsql_test 3.0 { + CREATE TABLE t3(a, b, c); + CREATE UNIQUE INDEX i3 ON t3(a, b); + INSERT INTO t3 VALUES(1, 'one', 'i'); + INSERT INTO t3 VALUES(3, 'three', 'iii'); + INSERT INTO t3 VALUES(6, 'six', 'vi'); + INSERT INTO t3 VALUES(2, 'two', 'ii'); + INSERT INTO t3 VALUES(4, 'four', 'iv'); + INSERT INTO t3 VALUES(5, 'five', 'v'); + + CREATE TABLE t4(x PRIMARY KEY, y); + INSERT INTO t4 VALUES('a', 'one'); + INSERT INTO t4 VALUES('b', 'two'); +} + +do_searchcount_test 3.1 { + SELECT a, b FROM t3 WHERE (a=1 AND b='one') OR (a=2 AND b='two') +} {1 one 2 two search 2} + +do_searchcount_test 3.2 { + SELECT a, c FROM t3 WHERE (a=1 AND b='one') OR (a=2 AND b='two') +} {1 i 2 ii search 4} + +do_searchcount_test 3.4.1 { + SELECT y FROM t4 WHERE x='a' +} {one search 2} +do_searchcount_test 3.4.2 { + SELECT a, b FROM t3 WHERE + (a=1 AND b=(SELECT y FROM t4 WHERE x='a')) + OR (a=2 AND b='two') +} {1 one 2 two search 4} +do_searchcount_test 3.4.3 { + SELECT a, b FROM t3 WHERE + (a=2 AND b='two') + OR (a=1 AND b=(SELECT y FROM t4 WHERE x='a')) +} {2 two 1 one search 4} +do_searchcount_test 3.4.4 { + SELECT a, b FROM t3 WHERE + (a=2 AND b=(SELECT y FROM t4 WHERE x='b')) + OR (a=1 AND b=(SELECT y FROM t4 WHERE x='a')) +} {2 two 1 one search 6} + + finish_test From 606bb3a54e5098cc0ecca29a2241616e0d3d6c42 Mon Sep 17 00:00:00 2001 From: dan Date: Fri, 24 Aug 2012 19:58:18 +0000 Subject: [PATCH 6/8] Another test for whereD.test. FossilOrigin-Name: 29d586178dcfdb99eaf7ce768668ab0aa9898c83 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/whereD.test | 6 ++++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index cb3aee71fc..c3b5ff47b9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sextra\stests\sto\swhereD.test. -D 2012-08-24T19:52:25.350 +C Another\stest\sfor\swhereD.test. +D 2012-08-24T19:58:18.909 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -965,7 +965,7 @@ F test/where9.test ae98dc22ef9b6f2bc81e9f164e41b38faa9bda06 F test/whereA.test 24c234263c8fe358f079d5e57d884fb569d2da0a F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test 13ff5ec0dba407c0e0c075980c75b3275a6774e5 -F test/whereD.test 85b8aa329439b81e6844f65763eec84ae8db1604 +F test/whereD.test 304ccbe3c77e0d0764f37c91d43b8c4792a5e02f F test/wherelimit.test 5e9fd41e79bb2b2d588ed999d641d9c965619b31 F test/win32lock.test b2a539e85ae6b2d78475e016a9636b4451dc7fb9 F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 @@ -1013,7 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P a3e26038a1d9f3331239f777c67d1920d904aab0 -R 818ec06d567f4218c34d00c712e0fbb7 +P 7e961eef6b7260dd8deb8b3812218a874c382885 +R 4a4adcf19c2ce08ddfc8921697497bb6 U dan -Z 17fe6aa0374a8f5f1fd6fa7c61adf7ad +Z bec2b67844a62f1ca5d6df71780775af diff --git a/manifest.uuid b/manifest.uuid index d1c3e69140..3e3c51b7de 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7e961eef6b7260dd8deb8b3812218a874c382885 \ No newline at end of file +29d586178dcfdb99eaf7ce768668ab0aa9898c83 \ No newline at end of file diff --git a/test/whereD.test b/test/whereD.test index 8bc8ef986f..9942890180 100644 --- a/test/whereD.test +++ b/test/whereD.test @@ -154,5 +154,11 @@ do_searchcount_test 3.4.4 { OR (a=1 AND b=(SELECT y FROM t4 WHERE x='a')) } {2 two 1 one search 6} +do_searchcount_test 3.5.1 { + SELECT a, b FROM t3 WHERE (a=1 AND b='one') OR rowid=4 +} {1 one 2 two search 2} +do_searchcount_test 3.5.2 { + SELECT a, c FROM t3 WHERE (a=1 AND b='one') OR rowid=4 +} {1 i 2 ii search 2} finish_test From 7b36ba3da319786dea5deab70c8f8181ebdc2f8f Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Aug 2012 21:54:11 +0000 Subject: [PATCH 7/8] Remove a NEVER() that is in fact reachable on an OOM. This probably has nothing to do with the multi-or-covering-index change but just happened to be found while testing that change. FossilOrigin-Name: 5499af53ebcdc21ae288aa2347aa21f6891d79ef --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index c3b5ff47b9..a1afff8349 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Another\stest\sfor\swhereD.test. -D 2012-08-24T19:58:18.909 +C Remove\sa\sNEVER()\sthat\sis\sin\sfact\sreachable\son\san\sOOM.\s\sThis\sprobably\nhas\snothing\sto\sdo\swith\sthe\smulti-or-covering-index\schange\sbut\sjust\shappened\nto\sbe\sfound\swhile\stesting\sthat\schange. +D 2012-08-24T21:54:11.844 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -250,7 +250,7 @@ F src/vtab.c bb8ea3a26608bb1357538a5d2fc72beba6638998 F src/wal.c 9294df6f96aae5909ae1a9b733fd1e1b4736978b F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b -F src/where.c b95276a535d9096088ee3cbc3eee25652f1b0c93 +F src/where.c 27c9e43fecf88b843bf237564c7276ef51f67540 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00 @@ -1013,7 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P 7e961eef6b7260dd8deb8b3812218a874c382885 -R 4a4adcf19c2ce08ddfc8921697497bb6 -U dan -Z bec2b67844a62f1ca5d6df71780775af +P 29d586178dcfdb99eaf7ce768668ab0aa9898c83 +R 858bc4272f754092a91123cbacf06ab0 +U drh +Z 3f900117ffb7958920cf3a90738748c3 diff --git a/manifest.uuid b/manifest.uuid index 3e3c51b7de..1bf899989e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -29d586178dcfdb99eaf7ce768668ab0aa9898c83 \ No newline at end of file +5499af53ebcdc21ae288aa2347aa21f6891d79ef \ No newline at end of file diff --git a/src/where.c b/src/where.c index 05420c9fb2..27fb0f8fce 100644 --- a/src/where.c +++ b/src/where.c @@ -3622,7 +3622,7 @@ static int codeAllEqualityTerms( int r1; int k = pIdx->aiColumn[j]; pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx); - if( NEVER(pTerm==0) ) break; + if( pTerm==0 ) break; /* The following true for indices with redundant columns. ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */ testcase( (pTerm->wtFlags & TERM_CODED)!=0 ); From d40e208726918b770586cb0bf5cf7edabc17ee2a Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 24 Aug 2012 23:24:15 +0000 Subject: [PATCH 8/8] Move field WhereLevel.pCovidx inside the union to WhereLevel.u.pCovidx. FossilOrigin-Name: b722143d075979ba3d92b7b29e576ce2307187d1 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/sqliteInt.h | 2 +- src/where.c | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index a1afff8349..2bf121ccfb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Remove\sa\sNEVER()\sthat\sis\sin\sfact\sreachable\son\san\sOOM.\s\sThis\sprobably\nhas\snothing\sto\sdo\swith\sthe\smulti-or-covering-index\schange\sbut\sjust\shappened\nto\sbe\sfound\swhile\stesting\sthat\schange. -D 2012-08-24T21:54:11.844 +C Move\sfield\sWhereLevel.pCovidx\sinside\sthe\sunion\sto\sWhereLevel.u.pCovidx. +D 2012-08-24T23:24:15.128 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in abd5c10d21d1395f140d9e50ea999df8fa4d6376 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -180,7 +180,7 @@ F src/select.c a9d68e04f07348038ac279f3316ee8f8e146f59a F src/shell.c 076e1c90d594644f36027c8ecff9a392cf2d3a06 F src/sqlite.h.in f664797c68ced43c2ea2c541d4ec8e1e04ec68ac F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 -F src/sqliteInt.h d5d74494335876dad1853b36559367927fe5f1e7 +F src/sqliteInt.h 497e89baddee92a4769cbc2c169b654a223f75d6 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 35939e7e03abf1b7577ce311f48f682c40de3208 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -250,7 +250,7 @@ F src/vtab.c bb8ea3a26608bb1357538a5d2fc72beba6638998 F src/wal.c 9294df6f96aae5909ae1a9b733fd1e1b4736978b F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b -F src/where.c 27c9e43fecf88b843bf237564c7276ef51f67540 +F src/where.c 9a28820fb0ead5674d5b45dfdb32aef913fe40c3 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 0be144b453e0622a085fae8665c32f5676708e00 @@ -1013,7 +1013,7 @@ F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 67d8a99aceb56384a81b3f30d6c71743146d2cc9 -P 29d586178dcfdb99eaf7ce768668ab0aa9898c83 -R 858bc4272f754092a91123cbacf06ab0 +P 5499af53ebcdc21ae288aa2347aa21f6891d79ef +R d51bc6dccf316fa29f046fa529eea646 U drh -Z 3f900117ffb7958920cf3a90738748c3 +Z cc4f76d0f6e610d4f3bf10f9821bb4e6 diff --git a/manifest.uuid b/manifest.uuid index 1bf899989e..8a0b944a29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5499af53ebcdc21ae288aa2347aa21f6891d79ef \ No newline at end of file +b722143d075979ba3d92b7b29e576ce2307187d1 \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index aa554a23ac..19cd05eeb8 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1947,8 +1947,8 @@ struct WhereLevel { int addrInTop; /* Top of the IN loop */ } *aInLoop; /* Information about each nested IN operator */ } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */ + Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ } u; - Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR levels */ /* The following field is really not part of the current level. But ** we need a place to cache virtual table index information for each diff --git a/src/where.c b/src/where.c index 27fb0f8fce..a460abc2d7 100644 --- a/src/where.c +++ b/src/where.c @@ -4446,7 +4446,7 @@ static Bitmask codeOneLoopStart( } } } - pLevel->pCovidx = pCov; + pLevel->u.pCovidx = pCov; pLevel->iIdxCur = iCovCur; if( pAndExpr ){ pAndExpr->pLeft = 0; @@ -5277,7 +5277,7 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ if( pLevel->plan.wsFlags & WHERE_INDEXED ){ pIdx = pLevel->plan.u.pIdx; }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){ - pIdx = pLevel->pCovidx; + pIdx = pLevel->u.pCovidx; } if( pIdx && !db->mallocFailed){ int k, j, last;