diff --git a/manifest b/manifest index a1804c7bf0..b27c436553 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\scompiler\swarning\sfixes. -D 2013-06-19T13:59:49.313 +C Add\sin\sthe\scost\sof\sdoing\sa\stable\slookup\son\sOR\ssearches.\s\sMake\stest\scase\nchanges\sto\sdeal\swith\sdifference\sin\sSTAT3\sbehavior. +D 2013-06-19T18:01:44.089 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -289,7 +289,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83 F src/wal.c 436bfceb141b9423c45119e68e444358ee0ed35d F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c 4fa43583d0a84b48f93b1e88f11adf2065be4e73 -F src/where.c 88884f3a0355ece00fa0d1a3566c4ed6fb5a8bed +F src/where.c ac9f8c4ee8ece1e8a4c93802792dbb0d629a7fa0 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1039,7 +1039,7 @@ F test/where6.test 5da5a98cec820d488e82708301b96cb8c18a258b F test/where7.test 5a4b0abc207d71da4deecd734ad8579e8dd40aa8 F test/where8.test f6b9559723564a042927ee0f22003ac9bed71b21 F test/where8m.test da346596e19d54f0aba35ebade032a7c47d79739 -F test/where9.test f5752185fc19a1ee826a2386a249f05dbc25979b +F test/where9.test 9a7fda4a4512abc26a855e8b2b6572b200f6019b F test/whereA.test 24c234263c8fe358f079d5e57d884fb569d2da0a F test/whereB.test 0def95db3bdec220a731c7e4bec5930327c1d8c5 F test/whereC.test d6f4ecd4fa2d9429681a5b22a25d2bda8e86ab8a @@ -1096,7 +1096,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 9d3ef3bd2c6281784a537a22a87279f420649935 -R 576d65f25fc5d448aeaee421b4a0d4ef +P 8d2ae8e2f343f82f6fba6d0e89cee7f15b444aa3 +R f44808387531e19eca9d858ab5ea40e0 U drh -Z 2fbaa2eda000406e9f5d447a3a6c804c +Z 1152d5230daa64158b83c69b1e514ae0 diff --git a/manifest.uuid b/manifest.uuid index 350fdf4563..6cc8090fec 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8d2ae8e2f343f82f6fba6d0e89cee7f15b444aa3 \ No newline at end of file +d97898e8e3990ae8c1882c9102b57692d8810730 \ No newline at end of file diff --git a/src/where.c b/src/where.c index f1cee90de1..b7dab2105d 100644 --- a/src/where.c +++ b/src/where.c @@ -630,8 +630,8 @@ static int whereClauseInsert(WhereClause *pWC, Expr *p, u8 wtFlags){ ** the WhereClause.a[] array. The slot[] array grows as needed to contain ** all terms of the WHERE clause. */ -static void whereSplit(WhereClause *pWC, Expr *pExpr, int op){ - pWC->op = (u8)op; +static void whereSplit(WhereClause *pWC, Expr *pExpr, u8 op){ + pWC->op = op; if( pExpr==0 ) return; if( pExpr->op!=op ){ whereClauseInsert(pWC, pExpr, 0); @@ -4516,6 +4516,7 @@ static int whereLoopAddBtree( pNew->iSortIdx = 0; pNew->rSetup = 0; pNew->prereq = mExtra; + pNew->nOut = rSize; pNew->u.btree.pIndex = pProbe; b = indexMightHelpWithOrderBy(pBuilder, pProbe, pSrc->iCursor); /* The ONEPASS_DESIRED flags never occurs together with ORDER BY */ @@ -4526,7 +4527,6 @@ static int whereLoopAddBtree( /* Full table scan */ pNew->iSortIdx = b ? iSortIdx : 0; - pNew->nOut = rSize; /* TUNING: Cost of full table scan is 3*(N + log2(N)). ** + The extra 3 factor is to encourage the use of indexed lookups ** over full scans. A smaller constant 2 is used for covering @@ -4549,7 +4549,6 @@ static int whereLoopAddBtree( ) ){ pNew->iSortIdx = b ? iSortIdx : 0; - pNew->nOut = rSize; if( m==0 ){ /* TUNING: Cost of a covering index scan is 2*(N + log2(N)). ** + The extra 2 factor is to encourage the use of indexed lookups @@ -4824,7 +4823,8 @@ static int whereLoopAddOr(WhereLoopBuilder *pBuilder, Bitmask mExtra){ pNew->aLTerm[0] = pTerm; pNew->wsFlags = WHERE_MULTI_OR; pNew->rSetup = 0; - pNew->rRun = rTotal; + /* TUNING: Multiple by 3.5 for the secondary table lookup */ + pNew->rRun = rTotal + 18; assert( 18==whereCost(7)-whereCost(2) ); pNew->nOut = nRow; pNew->prereq = prereq; memset(&pNew->u, 0, sizeof(pNew->u)); diff --git a/test/where9.test b/test/where9.test index 4ffcad1470..5b000d967e 100644 --- a/test/where9.test +++ b/test/where9.test @@ -598,7 +598,7 @@ do_test where9-6.3.5 { OR (b NOT NULL AND c IS NULL AND d NOT NULL) OR (b NOT NULL AND c NOT NULL AND d IS NULL) } -} {scan 0 sort 0} ;# DELETEs rows 90 91 92 97 +} {scan 98 sort 0} ;# DELETEs rows 90 91 92 97 do_test where9-6.3.6 { db eval { SELECT count(*) FROM t1 UNION ALL @@ -615,7 +615,7 @@ do_test where9-6.3.7 { OR (b NOT NULL AND +c IS NULL AND d NOT NULL) OR (b NOT NULL AND c NOT NULL AND d IS NULL) } -} {scan 0 sort 0} ;# Add 100 to rowids 90 91 92 97 +} {scan 98 sort 0} ;# Add 100 to rowids 90 91 92 97 do_test where9-6.3.8 { db eval { SELECT count(*) FROM t1 UNION ALL @@ -705,7 +705,7 @@ do_test where9-6.6.1 { OR (b NOT NULL AND +c IS NULL AND d NOT NULL) OR (b NOT NULL AND c NOT NULL AND d IS NULL) } -} {scan 0 sort 0} ;# DELETEs rows 90 91 92 97 +} {scan 98 sort 0} ;# DELETEs rows 90 91 92 97 do_test where9-6.6.2 { db eval { SELECT count(*) FROM t1 UNION ALL @@ -722,7 +722,7 @@ do_test where9-6.6.3 { OR (b NOT NULL AND +c IS NULL AND d NOT NULL) OR (b NOT NULL AND c NOT NULL AND d IS NULL) } -} {scan 0 sort 0} ;# Add 100 to rowids 90 91 92 97 +} {scan 98 sort 0} ;# Add 100 to rowids 90 91 92 97 do_test where9-6.6.4 { db eval { SELECT count(*) FROM t1 UNION ALL @@ -781,23 +781,44 @@ do_test where9-6.8.2 { OR (b NOT NULL AND c NOT NULL AND d IS NULL) } } {1 {no query solution}} -do_test where9-6.8.3 { - catchsql { - UPDATE t1 INDEXED BY t1b SET a=a+100 - WHERE (b IS NULL AND c NOT NULL AND d NOT NULL) - OR (b NOT NULL AND c IS NULL AND d NOT NULL) - OR (b NOT NULL AND c NOT NULL AND d IS NULL) - } -} {0 {}} -do_test where9-6.8.4 { - catchsql { - DELETE FROM t1 INDEXED BY t1b - WHERE (b IS NULL AND c NOT NULL AND d NOT NULL) - OR (b NOT NULL AND c IS NULL AND d NOT NULL) - OR (b NOT NULL AND c NOT NULL AND d IS NULL) - } -} {0 {}} - +ifcapable stat3 { + # When STAT3 is enabled, the "b NOT NULL" terms get translated + # into b>NULL, which can be satified by the index t1b. It is a very + # expensive way to do the query, but it works, and so a solution is possible. + do_test where9-6.8.3-stat3 { + catchsql { + UPDATE t1 INDEXED BY t1b SET a=a+100 + WHERE (b IS NULL AND c NOT NULL AND d NOT NULL) + OR (b NOT NULL AND c IS NULL AND d NOT NULL) + OR (b NOT NULL AND c NOT NULL AND d IS NULL) + } + } {0 {}} + do_test where9-6.8.4-stat3 { + catchsql { + DELETE FROM t1 INDEXED BY t1b + WHERE (b IS NULL AND c NOT NULL AND d NOT NULL) + OR (b NOT NULL AND c IS NULL AND d NOT NULL) + OR (b NOT NULL AND c NOT NULL AND d IS NULL) + } + } {0 {}} +} else { + do_test where9-6.8.3 { + catchsql { + UPDATE t1 INDEXED BY t1b SET a=a+100 + WHERE (b IS NULL AND c NOT NULL AND d NOT NULL) + OR (b NOT NULL AND c IS NULL AND d NOT NULL) + OR (b NOT NULL AND c NOT NULL AND d IS NULL) + } + } {1 {no query solution}} + do_test where9-6.8.4 { + catchsql { + DELETE FROM t1 INDEXED BY t1b + WHERE (b IS NULL AND c NOT NULL AND d NOT NULL) + OR (b NOT NULL AND c IS NULL AND d NOT NULL) + OR (b NOT NULL AND c NOT NULL AND d IS NULL) + } + } {1 {no query solution}} +} ############################################################################ # Test cases where terms inside an OR series are combined with AND terms # external to the OR clause. In other words, cases where