aboutsummaryrefslogtreecommitdiff
path: root/src/where.c
diff options
context:
space:
mode:
authordrh <>2022-03-21 13:47:15 +0000
committerdrh <>2022-03-21 13:47:15 +0000
commit75c493f76789b3fa0fc44d56a276ceef8d2dfb4d (patch)
treea4954b5b6fed2a9a02291753cf2311e80d425a55 /src/where.c
parentef07f96fafcbfea99507cdd88950c66e459f54d8 (diff)
downloadsqlite-75c493f76789b3fa0fc44d56a276ceef8d2dfb4d.tar.gz
sqlite-75c493f76789b3fa0fc44d56a276ceef8d2dfb4d.zip
Fix the assert() that attempts to verify that the table-reference to
index-reference translator finds all required translations. [forum:/forumpost/929168fdd6|Forum post 929168fdd6]. FossilOrigin-Name: fa9bd1fce47e8db1cfc4cd8efd2c09f8711ea917ce7d116dc7226c575cb9a6d4
Diffstat (limited to 'src/where.c')
-rw-r--r--src/where.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/where.c b/src/where.c
index bfe9980a1..afa0d3038 100644
--- a/src/where.c
+++ b/src/where.c
@@ -5896,6 +5896,26 @@ whereBeginError:
}
#endif
+#ifdef SQLITE_DEBUG
+/*
+** Return true if cursor iCur is opened by instruction k of the
+** bytecode. Used inside of assert() only.
+*/
+static int cursorIsOpen(Vdbe *v, int iCur, int k){
+ while( k>=0 ){
+ VdbeOp *pOp = sqlite3VdbeGetOp(v,k--);
+ if( pOp->p1!=iCur ) continue;
+ if( pOp->opcode==OP_Close ) return 0;
+ if( pOp->opcode==OP_OpenRead ) return 1;
+ if( pOp->opcode==OP_OpenWrite ) return 1;
+ if( pOp->opcode==OP_OpenDup ) return 1;
+ if( pOp->opcode==OP_OpenAutoindex ) return 1;
+ if( pOp->opcode==OP_OpenEphemeral ) return 1;
+ }
+ return 0;
+}
+#endif /* SQLITE_DEBUG */
+
/*
** Generate the end of the WHERE loop. See comments on
** sqlite3WhereBegin() for additional information.
@@ -6166,12 +6186,15 @@ void sqlite3WhereEnd(WhereInfo *pWInfo){
pOp->p2 = x;
pOp->p1 = pLevel->iIdxCur;
OpcodeRewriteTrace(db, k, pOp);
+ }else{
+ /* Unable to translate the table reference into an index
+ ** reference. Verify that this is harmless - that the
+ ** table being referenced really is open.
+ */
+ assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0
+ || cursorIsOpen(v,pOp->p1,k)
+ );
}
- assert( (pLoop->wsFlags & WHERE_IDX_ONLY)==0 || x>=0
-#ifdef SQLITE_ENABLE_OFFSET_SQL_FUNC
- || pOp->opcode==OP_Offset
-#endif
- || pWInfo->eOnePass );
}else if( pOp->opcode==OP_Rowid ){
pOp->p1 = pLevel->iIdxCur;
pOp->opcode = OP_IdxRowid;