-C Fix\sa\sproblem\swith\ssavepoint\sand\sincremental-vacuum.\s(CVS\s6066)
-D 2008-12-27T15:23:13
+C Simplify\sthe\sVM\scode\sthat\simplements\sWHERE\sclaues.\s(CVS\s6067)
+D 2008-12-28T16:55:25
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 2362e805d375c547f6d91d4732da8f93e1e668af
+F src/sqliteInt.h 85c72545ac3195bb7d9aefc8377f91123594c59c
F src/sqliteLimit.h f435e728c6b620ef7312814d660a81f9356eb5c8
F src/status.c 237b193efae0cf6ac3f0817a208de6c6c6ef6d76
F src/table.c 23db1e5f27c03160987c122a078b4bb51ef0b2f8
F src/vdbemem.c f9c859ac17e2e05a0f249868ce4f191f69edd31d
F src/vtab.c e39e011d7443a8d574b1b9cde207a35522e6df43
F src/walker.c 488c2660e13224ff70c0c82761118efb547f8f0d
-F src/where.c b273a232aa6e7616bb6025a80276c8aff8df2b22
+F src/where.c f41330e71f3dde12cc6631ae9f75c9869b92c32b
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 a1b1f6cd7d2c060bd75ce39347e1220b872806ed
-R 1a9ec7089b4909b30df347c1e2ee32e6
-U danielk1977
-Z 75549ad37a08cbb85b58f7a2c8f6829a
+P 08352f9ea9d2a1759320efc46e418079000855cb
+R b27114cf38ee45f9d895c0015e5cf61b
+U drh
+Z 5701aac5e9c50a29a7e1c4535e66ab21
** 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.344 2008/12/24 11:25:40 danielk1977 Exp $
+** $Id: where.c,v 1.345 2008/12/28 16:55:25 drh Exp $
*/
#include "sqliteInt.h"
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
int sqlite3WhereTrace = 0;
#endif
-#if 1
+#if 0
# define WHERETRACE(X) if(sqlite3WhereTrace) sqlite3DebugPrintf X
#else
# define WHERETRACE(X)
** The index has as many as three equality constraints, but in this
** example, the third "c" value is an inequality. So only two
** constraints are coded. This routine will generate code to evaluate
-** a==5 and b IN (1,2,3). The current values for a and b will be left
-** on the stack - a is the deepest and b the shallowest.
+** a==5 and b IN (1,2,3). The current values for a and b will be stored
+** in consecutive registers and the index of the first register is returned.
**
** In the example above nEq==2. But this subroutine works for any value
** of nEq including 0. If nEq==0, this routine is nearly a no-op.
WhereTerm *pTerm; /* A single constraint term */
int j; /* Loop counter */
int regBase; /* Base register */
+ int nReg; /* Number of registers to allocate */
/* This module is only called on query plans that use an index. */
assert( pLevel->plan.wsFlags & WHERE_INDEXED );
pIdx = pLevel->plan.u.pIdx;
/* Figure out how many memory cells we will need then allocate them.
- ** We always need at least one used to store the loop terminator
- ** value. If there are IN operators we'll need one for each == or
- ** IN constraint.
*/
regBase = pParse->nMem + 1;
- pParse->nMem += pLevel->plan.nEq + 1 + nExtraReg;
+ nReg = pLevel->plan.nEq + nExtraReg;
+ pParse->nMem += nReg;
/* Evaluate the equality constraints
*/
assert( (pTerm->wtFlags & TERM_CODED)==0 );
r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j);
if( r1!=regBase+j ){
- sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
+ if( nReg==1 ){
+ sqlite3ReleaseTempReg(pParse, regBase);
+ regBase = r1;
+ }else{
+ sqlite3VdbeAddOp2(v, OP_SCopy, r1, regBase+j);
+ }
}
testcase( pTerm->eOperator & WO_ISNULL );
testcase( pTerm->eOperator & WO_IN );
int nConstraint; /* Number of constraint terms */
Index *pIdx; /* The index we will be using */
int iIdxCur; /* The VDBE cursor for the index */
- int op;
+ int nExtraReg = 0; /* Number of extra registers needed */
+ int op; /* Instruction opcode */
pIdx = pLevel->plan.u.pIdx;
iIdxCur = pLevel->iIdxCur;
k = pIdx->aiColumn[nEq]; /* Column for inequality constraints */
- /* Generate code to evaluate all constraint terms using == or IN
- ** and store the values of those terms in an array of registers
- ** starting at regBase.
- */
- regBase = codeAllEqualityTerms(pParse, pLevel, pWC, notReady, 2);
- addrNxt = pLevel->addrNxt;
-
/* If this loop satisfies a sort order (pOrderBy) request that
** was passed to this function to implement a "SELECT min(x) ..."
** query, then the caller will only allow the loop to run for
/* assert( pOrderBy->nExpr==1 ); */
/* assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] ); */
isMinQuery = 1;
+ nExtraReg = 1;
}
/* Find any inequality constraint terms for the start and end
*/
if( pLevel->plan.wsFlags & WHERE_TOP_LIMIT ){
pRangeEnd = findTerm(pWC, iCur, k, notReady, (WO_LT|WO_LE), pIdx);
+ nExtraReg = 1;
}
if( pLevel->plan.wsFlags & WHERE_BTM_LIMIT ){
pRangeStart = findTerm(pWC, iCur, k, notReady, (WO_GT|WO_GE), pIdx);
+ nExtraReg = 1;
}
+ /* Generate code to evaluate all constraint terms using == or IN
+ ** and store the values of those terms in an array of registers
+ ** starting at regBase.
+ */
+ regBase = codeAllEqualityTerms(pParse, pLevel, pWC, notReady, nExtraReg);
+ addrNxt = pLevel->addrNxt;
+
+
/* If we are doing a reverse order scan on an ascending index, or
** a forward order scan on a descending index, interchange the
** start and end terms (pRangeStart and pRangeEnd).
testcase( op==OP_Noop );
testcase( op==OP_IdxGE );
testcase( op==OP_IdxLT );
- sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
- SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
- sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
+ if( op!=OP_Noop ){
+ sqlite3VdbeAddOp4(v, op, iIdxCur, addrNxt, regBase,
+ SQLITE_INT_TO_PTR(nConstraint), P4_INT32);
+ sqlite3VdbeChangeP5(v, endEq!=bRev ?1:0);
+ }
/* If there are inequality constraints, check that the value
** of the table column that the inequality contrains is not NULL.
WhereInfo *pSubWInfo;
if( pOrTerm->leftCursor!=iCur ) continue;
pSubWInfo = sqlite3WhereBegin(pParse, &oneTab, pOrTerm->pExpr, 0,
- WHERE_FILL_ROWSET, regOrRowset);
+ WHERE_FILL_ROWSET | WHERE_OMIT_OPEN | WHERE_OMIT_CLOSE,
+ regOrRowset);
if( pSubWInfo ){
- pSubWInfo->a[0].plan.wsFlags |= WHERE_IDX_ONLY;
sqlite3WhereEnd(pSubWInfo);
}
}
pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
pWInfo->regRowSet = (wctrlFlags & WHERE_FILL_ROWSET) ? regRowSet : -1;
pWInfo->pWC = pWC = (WhereClause*)&pWInfo->a[pWInfo->nLevel];
+ pWInfo->wctrlFlags = wctrlFlags;
pMaskSet = (WhereMaskSet*)&pWC[1];
/* Split the WHERE clause into separate subexpressions where each
(const char*)pTab->pVtab, P4_VTAB);
}else
#endif
- if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
+ if( (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0
+ && (wctrlFlags & WHERE_OMIT_OPEN)==0 ){
int op = pWInfo->okOnePass ? OP_OpenWrite : OP_OpenRead;
sqlite3OpenTable(pParse, pTabItem->iCursor, iDb, pTab, op);
if( !pWInfo->okOnePass && pTab->nCol<BMS ){
Table *pTab = pTabItem->pTab;
assert( pTab!=0 );
if( (pTab->tabFlags & TF_Ephemeral)!=0 || pTab->pSelect ) continue;
- if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
- sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
- }
- if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
- sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
+ if( (pWInfo->wctrlFlags & WHERE_OMIT_CLOSE)==0 ){
+ if( !pWInfo->okOnePass && (pLevel->plan.wsFlags & WHERE_IDX_ONLY)==0 ){
+ sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor);
+ }
+ if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){
+ sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur);
+ }
}
/* If this scan uses an index, make code substitutions to read data