-C Add\sa\stest\sto\ssavepoint.test\sthat\stests\sthat\snothing\sgoes\swrong\sif\san\sincremental\svacuum\soccurs\sinside\sa\ssavepoint.\s(CVS\s6057)
-D 2008-12-23T11:46:28
+C Multi-index\sOR-clause\soptimization\snow\sworks\sfor\ssimple\stests.\s\sThere\sare\nno\stest\sscripts\sfor\sit\syet,\sthough.\s\sAnd\sit\sis\sdisabled\sby\sdefault,\spending\nfurther\stesting\sand\soptimization.\s\sWe\sneed\sa\slot\sof\sboth.\s(CVS\s6058)
+D 2008-12-23T13:35:23
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 77635d0909c2067cee03889a1e04ce910d8fb809
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/shell.c 65d19f8996a160f288087e31810f24025439c62a
F src/sqlite.h.in 065a828e299960316aa34f05b9f0f10f33afe4c8
F src/sqlite3ext.h 1db7d63ab5de4b3e6b83dd03d1a4e64fef6d2a17
-F src/sqliteInt.h 24f71f7e2758516aa6b64e1f0ca02ee6e29344d3
+F src/sqliteInt.h 9411acda2959c3494bafb1ac98048a53ee920ea3
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c 23db1e5f27c03160987c122a078b4bb51ef0b2f8
F src/utf.c 1da9c832dba0fa8f865b5b902d93f420a1ee4245
F src/util.c ea62608f66f33a7e8322de83024ae37c415c0c7f
F src/vacuum.c 383d6297bddc011ab04a9eed110db6eaf523e8e9
-F src/vdbe.c e9a7825d25496343937852fa70b993ee217f924e
+F src/vdbe.c fb84f5ce769c74348d808cdc6fbba91aec54fe30
F src/vdbe.h 03516f28bf5aca00a53c4dccd6c313f96adb94f6
F src/vdbeInt.h e6e80a99ce634983b7cc2498843b4d2e5540900a
F src/vdbeapi.c 85c33cfbfa56249cbe627831610afafba754477d
F src/vdbemem.c f9c859ac17e2e05a0f249868ce4f191f69edd31d
F src/vtab.c e39e011d7443a8d574b1b9cde207a35522e6df43
F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
-F src/where.c 6e5de2421da8d9ed62a2fcf7df70df8301282936
+F src/where.c 50e47032adc8d16dc9d47223e961b662e28294f8
F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
F test/alias.test 597662c5d777a122f9a3df0047ea5c5bd383a911
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 0c53a4c2da31f91947f1347f1d33d0c83b843d26
-R 69a2575f1608bb2456de34d99c90c314
-U danielk1977
-Z a550b3819182c5fbaaf055096d0ff219
+P fc4f0621535e27eceb0b4b900a8c59dc06e84487
+R 89762139291a67475ddfc7f16b017b8d
+U drh
+Z b28b3f967fddc56af8e4e065924a72f1
** 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.340 2008/12/21 03:51:16 drh Exp $
+** $Id: where.c,v 1.341 2008/12/23 13:35:23 drh Exp $
*/
#include "sqliteInt.h"
struct WhereOrInfo {
WhereClause wc; /* Decomposition into subterms */
Bitmask indexable; /* Bitmask of all indexable tables in the clause */
- WherePlan *aPlan; /* Search plan for each subterm */
};
/*
static void whereOrInfoDelete(sqlite3 *db, WhereOrInfo *p){
if( p ){
whereClauseClear(&p->wc);
- sqlite3DbFree(db, p->aPlan);
sqlite3DbFree(db, p);
}
}
pTerm->wtFlags |= TERM_ORINFO;
pOrWc = &pOrInfo->wc;
whereClauseInit(pOrWc, pWC->pParse, pMaskSet);
- pOrInfo->aPlan = 0;
whereSplit(pOrWc, pExpr, TK_OR);
exprAnalyzeAll(pSrc, pOrWc);
if( db->mallocFailed ) return;
pTerm->eOperator = 0; /* case 1 trumps case 2 */
}
}
-
- /* If case 2 applies, allocate space for pOrInfo->aPlan
- */
- if( pTerm->eOperator==WO_OR ){
- pOrInfo->aPlan = sqlite3DbMallocRaw(db, pOrWc->nTerm*sizeof(WherePlan));
- }
}
#endif /* !SQLITE_OMIT_OR_OPTIMIZATION && !SQLITE_OMIT_SUBQUERY */
int eqTermMask; /* Mask of valid equality operators */
double cost; /* Cost of using pProbe */
double nRow; /* Estimated number of rows in result set */
+ int i; /* Loop counter */
+ Bitmask maskSrc; /* Bitmask for the pSrc table */
WHERETRACE(("bestIndex: tbl=%s notReady=%llx\n", pSrc->pTab->zName,notReady));
pProbe = pSrc->pTab->pIndex;
}
}
+#if SQLITE_ENABLE_MULTI_OR
+ /* Search for an OR-clause that can be used to look up the table.
+ */
+ maskSrc = getMask(pWC->pMaskSet, iCur);
+ for(i=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
+ WhereClause tempWC;
+ tempWC = *pWC;
+ tempWC.nSlot = 1;
+ if( pTerm->eOperator==WO_OR
+ && ((pTerm->prereqAll & ~maskSrc) & notReady)==0
+ && (pTerm->u.pOrInfo->indexable & maskSrc)!=0 ){
+ WhereClause *pOrWC = &pTerm->u.pOrInfo->wc;
+ WhereTerm *pOrTerm;
+ int j;
+ double rTotal = 0;
+ double nRow = 0;
+ for(j=0, pOrTerm=pOrWC->a; j<pOrWC->nTerm; j++, pOrTerm++){
+ WhereCost sTermCost;
+ if( pOrTerm->leftCursor!=iCur ) continue;
+ tempWC.a = pOrTerm;
+ bestIndex(pParse, &tempWC, pSrc, notReady, 0, &sTermCost);
+ if( sTermCost.plan.wsFlags==0 ){
+ rTotal = pCost->rCost;
+ break;
+ }
+ rTotal += sTermCost.rCost;
+ nRow += sTermCost.nRow;
+ }
+ if( rTotal<pCost->rCost ){
+ pCost->rCost = rTotal;
+ pCost->nRow = nRow;
+ pCost->plan.wsFlags = WHERE_MULTI_OR;
+ pCost->plan.u.pTerm = pTerm;
+ }
+ }
+ }
+#endif
+
/* If the pSrc table is the right table of a LEFT JOIN then we may not
** use an index to satisfy IS NULL constraints on that table. This is
** because columns might end up being NULL if the table does not match -
pLevel->p1 = iIdxCur;
disableTerm(pLevel, pRangeStart);
disableTerm(pLevel, pRangeEnd);
- }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
+ }else
+
+#if SQLITE_ENABLE_MULTI_OR
+ if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){
/* Case 4: Two or more separately indexed terms connected by OR
**
** Example:
WhereTerm *pTerm; /* The complete OR-clause */
WhereClause *pOrWc; /* The OR-clause broken out into subterms */
WhereTerm *pOrTerm; /* A single subterm within the OR-clause */
+ SrcList oneTab; /* Shortened table list */
pTerm = pLevel->plan.u.pTerm;
assert( pTerm!=0 );
pOrWc = &pTerm->u.pOrInfo->wc;
regRowset = sqlite3GetTempReg(pParse);
- sqlite3VdbeAddOp1(v, OP_Null, regRowset);
+ regNextRowid = sqlite3GetTempReg(pParse);
+ sqlite3VdbeAddOp2(v, OP_Null, 0, regRowset);
+ oneTab.nSrc = 1;
+ oneTab.nAlloc = 1;
+ oneTab.a[0] = *pTabItem;
for(j=0, pOrTerm=pOrWc->a; j<pOrWc->nTerm; j++, pOrTerm++){
+ WhereInfo *pSubWInfo;
if( pOrTerm->leftCursor!=iCur ) continue;
- /* fillRowSetFromIdx(pParse, regRowset, pTabItem, pOrTerm); */
+ pSubWInfo = sqlite3WhereBegin(pParse, &oneTab, pOrTerm->pExpr, 0, 0);
+ if( pSubWInfo ){
+ sqlite3VdbeAddOp2(v, OP_Rowid, oneTab.a[0].iCursor, regNextRowid);
+ sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowset, regNextRowid);
+ pSubWInfo->a[0].plan.wsFlags |= WHERE_IDX_ONLY;
+ sqlite3WhereEnd(pSubWInfo);
+ }
}
- regNextRowid = sqlite3GetTempReg(pParse);
sqlite3VdbeResolveLabel(v, addrCont);
addrCont =
sqlite3VdbeAddOp3(v, OP_RowSetRead, regRowset, addrBrk, regNextRowid);
sqlite3ReleaseTempReg(pParse, regNextRowid);
pLevel->op = OP_Goto;
pLevel->p2 = addrCont;
- }else{
+ }else
+#endif /* SQLITE_ENABLE_MULTI_OR */
+
+ {
/* Case 5: There is no usable index. We must do a complete
** scan of the entire table.
*/