diff options
author | drh <drh@noemail.net> | 2019-01-17 19:33:16 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2019-01-17 19:33:16 +0000 |
commit | aa0f2d0efad49391f44be9ee16c2df61a355c32c (patch) | |
tree | d814caeb5b2ce7465ff1cdd5fc2c951451f4132c /src | |
parent | f66da6ce8ed88e1d9275773d4199b31866c1c8a3 (diff) | |
download | sqlite-aa0f2d0efad49391f44be9ee16c2df61a355c32c.tar.gz sqlite-aa0f2d0efad49391f44be9ee16c2df61a355c32c.zip |
Add the SQLITE_ENABLE_EARLY_CURSOR_CLOSE compile-time option which causes
read cursors to be closed after their usefulness ends during a two-pass
UPDATE.
FossilOrigin-Name: 7def6c8edd85f19ee09038e01541f75b1f71ca39b9fb782b8f0fcac89207c353
Diffstat (limited to 'src')
-rw-r--r-- | src/where.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/where.c b/src/where.c index bb9787fce..8be95bcd2 100644 --- a/src/where.c +++ b/src/where.c @@ -5262,6 +5262,29 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){ continue; } +#ifdef SQLITE_ENABLE_EARLY_CURSOR_CLOSE + /* Close all of the cursors that were opened by sqlite3WhereBegin. + ** Except, do not close cursors that will be reused by the OR optimization + ** (WHERE_OR_SUBCLAUSE). And do not close the OP_OpenWrite cursors + ** created for the ONEPASS optimization. + */ + if( (pTab->tabFlags & TF_Ephemeral)==0 + && pTab->pSelect==0 + && (pWInfo->wctrlFlags & WHERE_OR_SUBCLAUSE)==0 + ){ + int ws = pLoop->wsFlags; + if( pWInfo->eOnePass==ONEPASS_OFF && (ws & WHERE_IDX_ONLY)==0 ){ + sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); + } + if( (ws & WHERE_INDEXED)!=0 + && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 + && pLevel->iIdxCur!=pWInfo->aiCurOnePass[1] + ){ + sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur); + } + } +#endif + /* If this scan uses an index, make VDBE code substitutions to read data ** from the index instead of from the table where possible. In some cases ** this optimization prevents the table from ever being read, which can |