1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

The original column-cache implementation from check-in [ab1edcc7fedcf279]

(merged to trunk at [771fe35074b50b8d]) is unsound.  This check-in fixes
the issue.  Had to give back a little performance, the optimization is still
a overall win.

FossilOrigin-Name: ec95e970fb737adf0fab3cb4363040b036949e5eb966fc2d030a20f95e2bde60
This commit is contained in:
drh
2023-07-31 20:02:11 +00:00
parent 1f097a2f29
commit 98ab970bac
4 changed files with 23 additions and 9 deletions

View File

@@ -708,6 +708,8 @@ static SQLITE_NOINLINE int vdbeColumnFromOverflow(
int iCol, /* The column to read */
int t, /* The serial-type code for the column value */
i64 iOffset, /* Offset to the start of the content value */
u32 cacheStatus, /* Current Vdbe.cacheCtr value */
u32 colCacheCtr, /* Current value of the column cache counter */
Mem *pDest /* Store the value into this register. */
){
int rc;
@@ -733,6 +735,8 @@ static SQLITE_NOINLINE int vdbeColumnFromOverflow(
pCache = pC->pCache;
if( pCache->pCValue==0
|| pCache->iCol!=iCol
|| pCache->cacheStatus!=cacheStatus
|| pCache->colCacheCtr!=colCacheCtr
|| pCache->iOffset!=sqlite3BtreeOffset(pC->uc.pCursor)
){
if( pCache->pCValue ) sqlite3RCStrUnref(pCache->pCValue);
@@ -744,6 +748,8 @@ static SQLITE_NOINLINE int vdbeColumnFromOverflow(
pBuf[len+1] = 0;
pBuf[len+2] = 0;
pCache->iCol = iCol;
pCache->cacheStatus = cacheStatus;
pCache->colCacheCtr = colCacheCtr;
pCache->iOffset = sqlite3BtreeOffset(pC->uc.pCursor);
}else{
pBuf = pCache->pCValue;
@@ -814,6 +820,7 @@ int sqlite3VdbeExec(
Mem *pIn2 = 0; /* 2nd input operand */
Mem *pIn3 = 0; /* 3rd input operand */
Mem *pOut = 0; /* Output operand */
u32 colCacheCtr = 0; /* Column cache counter */
#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
u64 *pnCycle = 0;
int bStmtScanStatus = IS_STMT_SCANSTATUS(db)!=0;
@@ -3162,7 +3169,8 @@ op_column_restart:
*/
sqlite3VdbeSerialGet((u8*)sqlite3CtypeMap, t, pDest);
}else{
rc = vdbeColumnFromOverflow(pC, p2, t, aOffset[p2], pDest);
rc = vdbeColumnFromOverflow(pC, p2, t, aOffset[p2],
p->cacheCtr, colCacheCtr, pDest);
if( rc ){
if( rc==SQLITE_NOMEM ) goto no_mem;
if( rc==SQLITE_TOOBIG ) goto too_big;
@@ -5700,6 +5708,7 @@ case OP_Insert: {
);
pC->deferredMoveto = 0;
pC->cacheStatus = CACHE_STALE;
colCacheCtr++;
/* Invoke the update-hook if required. */
if( rc ) goto abort_due_to_error;
@@ -5860,6 +5869,7 @@ case OP_Delete: {
rc = sqlite3BtreeDelete(pC->uc.pCursor, pOp->p5);
pC->cacheStatus = CACHE_STALE;
colCacheCtr++;
pC->seekResult = 0;
if( rc ) goto abort_due_to_error;
@@ -6431,6 +6441,7 @@ case OP_IdxInsert: { /* in2 */
);
assert( pC->deferredMoveto==0 );
pC->cacheStatus = CACHE_STALE;
colCacheCtr++;
if( rc) goto abort_due_to_error;
break;
}
@@ -6506,6 +6517,7 @@ case OP_IdxDelete: {
assert( pC->deferredMoveto==0 );
pC->cacheStatus = CACHE_STALE;
pC->seekResult = 0;
colCacheCtr++;
break;
}