aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2011-09-16 01:34:43 +0000
committerdrh <drh@noemail.net>2011-09-16 01:34:43 +0000
commit48f2d3b10a5ac48ae2a1a24f77c7cb1aab6ea978 (patch)
tree0b02d36b1ecb60c458133c090c14df3c131b6151 /src/select.c
parent5b6a9ed49556deac6d48be80b6ef2816102f1951 (diff)
downloadsqlite-48f2d3b10a5ac48ae2a1a24f77c7cb1aab6ea978.tar.gz
sqlite-48f2d3b10a5ac48ae2a1a24f77c7cb1aab6ea978.zip
Add the new OP_Once opcode. Use it to clean up and simplify various
one-time initialization sections in the code, including the fix for ticket [002caede898ae]. FossilOrigin-Name: 7f00552b739fad79517b042a6ed61abe743a917b
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/select.c b/src/select.c
index 2ddc751b5..277f5c026 100644
--- a/src/select.c
+++ b/src/select.c
@@ -3831,7 +3831,7 @@ int sqlite3Select(
** is a register allocated to hold the subroutine return address
*/
int topAddr = sqlite3VdbeAddOp0(v, OP_Goto);
- int regOnce = 0;
+ int onceAddr = 0;
assert( pItem->addrFillSub==0 );
pItem->addrFillSub = topAddr+1;
pItem->regReturn = ++pParse->nMem;
@@ -3839,15 +3839,14 @@ int sqlite3Select(
/* If the subquery is no correlated and if we are not inside of
** a trigger, then we only need to compute the value of the subquery
** once. */
- regOnce = ++pParse->nMem;
- sqlite3VdbeAddOp1(v, OP_If, regOnce);
- sqlite3VdbeAddOp2(v, OP_Integer, 1, regOnce);
+ int regOnce = ++pParse->nMem;
+ onceAddr = sqlite3VdbeAddOp1(v, OP_Once, regOnce);
}
sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
sqlite3Select(pParse, pSub, &dest);
pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
- if( regOnce ) sqlite3VdbeJumpHere(v, topAddr+1);
+ if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
sqlite3VdbeAddOp1(v, OP_Return, pItem->regReturn);
sqlite3VdbeJumpHere(v, topAddr);
sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, topAddr+1);
@@ -3991,7 +3990,7 @@ int sqlite3Select(
** into an OP_Noop.
*/
if( addrSortIndex>=0 && pOrderBy==0 ){
- sqlite3VdbeChangeToNoop(v, addrSortIndex, 1);
+ sqlite3VdbeChangeToNoop(v, addrSortIndex);
p->addrOpenEphm[2] = -1;
}
@@ -4274,7 +4273,7 @@ int sqlite3Select(
sqlite3VdbeAddOp2(v, OP_SorterNext, sAggInfo.sortingIdx, addrTopOfLoop);
}else{
sqlite3WhereEnd(pWInfo);
- sqlite3VdbeChangeToNoop(v, addrSortingIdx, 1);
+ sqlite3VdbeChangeToNoop(v, addrSortingIdx);
}
/* Output the final row of result