From: drh Date: Mon, 6 Nov 2006 15:10:05 +0000 (+0000) Subject: Fix a bug in the optimizer that was causing it to miss an OR optimization X-Git-Tag: version-3.6.10~2666 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=382765866baba1e650b4402c6594aaf34fcd69af;p=thirdparty%2Fsqlite.git Fix a bug in the optimizer that was causing it to miss an OR optimization opportunity. (CVS 3502) FossilOrigin-Name: 9bf153b54c6e9ba16914dedd9e2949f32d7550ea --- diff --git a/manifest b/manifest index 296a0bf098..e2a9a9fcf9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Modify\sMakefile.in\sto\sinstall\ssqlite3ext.h.\s(CVS\s3501) -D 2006-11-01T12:20:17 +C Fix\sa\sbug\sin\sthe\soptimizer\sthat\swas\scausing\sit\sto\smiss\san\sOR\soptimization\nopportunity.\s(CVS\s3502) +D 2006-11-06T15:10:05 F Makefile.in 8e14898d41a53033ecb687d93c9cd5d109fb9ae3 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -129,7 +129,7 @@ F src/vdbeaux.c 78c744f127df03ea63098ebb7dd7fe3eb303e284 F src/vdbefifo.c 9efb94c8c3f4c979ebd0028219483f88e57584f5 F src/vdbemem.c 26623176bf1c616aa478da958fac49502491a921 F src/vtab.c aa30e940058ea56a1b7a9a7019ec21d307316fb4 -F src/where.c 1c33e196807bfe1bd021988525cf4728916a4a44 +F src/where.c 6e215af5a7b1eb2fc1b9d6fa653064753a84757f F tclinstaller.tcl 046e3624671962dc50f0481d7c25b38ef803eb42 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/all.test 5df90d015ca63fcef2a4b62c24f7316b66c4bfd4 @@ -345,7 +345,7 @@ F test/vtab7.test 5f9ef9fb84733e928d5d0267c821072561b198d5 F test/vtab9.test 87afba55339b0c255e9697fbfb5bfb6120505d9d F test/vtab_err.test c07f7665dd90bc757f80f05e7951d826eda9bc48 F test/where.test ee7c9a6659b07e1ee61177f6e7ff71565ee2c9df -F test/where2.test a16476a5913e75cf65b38f2daa6157a6b7791394 +F test/where2.test 61d5b20d9bedc8788a773bbdc5b2ef887725928e F test/where3.test 3b5ad2c58069e12be2bd86bc5e211a82810521aa F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/lemon.c 4e62a7119a9da4c5178ec095784ca7d44c77ce71 @@ -419,7 +419,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P dbd0125c62457681689db48e1f0a752767855773 -R b2d3160a61eff3adb50a97d122db9c22 +P 35c8c4781736d45019d8b823b8517c24622d3313 +R 72648fe2d8ddbd1ade2ac2a1d6675f54 U drh -Z a3a19609508ddd620894806968863c6c +Z 542e53251a657546cd65151f3319f13c diff --git a/manifest.uuid b/manifest.uuid index 4fe0e3097d..60ff4f74e6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -35c8c4781736d45019d8b823b8517c24622d3313 \ No newline at end of file +9bf153b54c6e9ba16914dedd9e2949f32d7550ea \ No newline at end of file diff --git a/src/where.c b/src/where.c index cea97c14d6..700485ebf2 100644 --- a/src/where.c +++ b/src/where.c @@ -16,7 +16,7 @@ ** so is applicable. Because this module is responsible for selecting ** indices, you might also think of this module as the "query optimizer". ** -** $Id: where.c,v 1.231 2006/10/28 00:28:09 drh Exp $ +** $Id: where.c,v 1.232 2006/11/06 15:10:05 drh Exp $ */ #include "sqliteInt.h" @@ -727,16 +727,15 @@ static void exprAnalyze( if( ok ){ ExprList *pList = 0; Expr *pNew, *pDup; + Expr *pLeft = 0; for(i=sOr.nTerm-1, pOrTerm=sOr.a; i>=0 && ok; i--, pOrTerm++){ if( (pOrTerm->flags & TERM_OR_OK)==0 ) continue; pDup = sqlite3ExprDup(pOrTerm->pExpr->pRight); pList = sqlite3ExprListAppend(pList, pDup, 0); + pLeft = pOrTerm->pExpr->pLeft; } - pDup = sqlite3Expr(TK_COLUMN, 0, 0, 0); - if( pDup ){ - pDup->iTable = iCursor; - pDup->iColumn = iColumn; - } + assert( pLeft!=0 ); + pDup = sqlite3ExprDup(pLeft); pNew = sqlite3Expr(TK_IN, pDup, 0, 0); if( pNew ){ int idxNew; diff --git a/test/where2.test b/test/where2.test index b9b29f708e..b8eb296d37 100644 --- a/test/where2.test +++ b/test/where2.test @@ -12,7 +12,7 @@ # focus of this file is testing the use of indices in WHERE clauses # based on recent changes to the optimizer. # -# $Id: where2.test,v 1.9 2006/05/11 13:26:26 drh Exp $ +# $Id: where2.test,v 1.10 2006/11/06 15:10:06 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -451,4 +451,33 @@ ifcapable subquery { } } {} } + +# Make sure WHERE clauses of the form A=1 AND (B=2 OR B=3) are optimized +# when we have an index on A and B. +# +ifcapable or_opt { + do_test where2-9.1 { + execsql { + BEGIN; + CREATE TABLE t10(a,b,c); + INSERT INTO t10 VALUES(1,1,1); + INSERT INTO t10 VALUES(1,2,2); + INSERT INTO t10 VALUES(1,3,3); + } + for {set i 4} {$i<=1000} {incr i} { + execsql {INSERT INTO t10 VALUES(1,$i,$i)} + } + execsql { + CREATE INDEX i10 ON t10(a,b); + COMMIT; + SELECT count(*) FROM t10; + } + } 1000 + do_test where2-9.2 { + count { + SELECT * FROM t10 WHERE a=1 AND (b=2 OR b=3) + } + } {1 2 2 1 3 3 7} +} + finish_test