diff options
author | dan <Dan Kennedy> | 2024-10-11 20:36:26 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2024-10-11 20:36:26 +0000 |
commit | 14101a3c28d95680f615a47effad7813a0db353c (patch) | |
tree | 2b9324f48f38988ea068429687bbd5edf2c6f74f /src/where.c | |
parent | 4859bc9a9ffdb9fa555a57db3593ccb08a0be983 (diff) | |
download | sqlite-14101a3c28d95680f615a47effad7813a0db353c.tar.gz sqlite-14101a3c28d95680f615a47effad7813a0db353c.zip |
Experimental change to explain query plan to identify covering indexes on expressions.
FossilOrigin-Name: 3bb03a2891e30c58b66e3665a8877a8eab4a8bac57ee153d8d31358caeaf4b7c
Diffstat (limited to 'src/where.c')
-rw-r--r-- | src/where.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/where.c b/src/where.c index c2fc33824..e99cdb355 100644 --- a/src/where.c +++ b/src/where.c @@ -7441,14 +7441,28 @@ 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. - */ + }else if( pLoop->wsFlags & (WHERE_IDX_ONLY|WHERE_EXPRIDX) ){ if( pLoop->wsFlags & WHERE_IDX_ONLY ){ + /* An error. pLoop is supposed to be a covering index loop, + ** and yet the VM code refers to a column of the table that + ** is not part of the index. */ sqlite3ErrorMsg(pParse, "internal query planner error"); pParse->rc = SQLITE_INTERNAL; + }else{ + /* The WHERE_EXPRIDX flag is set by the planner when it is likely + ** that pLoop is a covering index loop, but it is not possible + ** to be 100% sure. In this case, any OP_Explain opcode + ** corresponding to this loop describes the index as a "COVERING + ** INDEX". But, pOp proves that pLoop is not actually a covering + ** index loop. So clear the WHERE_EXPRIDX flag and rewrite the + ** text that accompanies the OP_Explain opcode, if any. */ + pLoop->wsFlags &= ~WHERE_EXPRIDX; + sqlite3WhereAddExplainText(pParse, + pLevel->addrBody-1, + pTabList, + pLevel, + pWInfo->wctrlFlags + ); } } }else if( pOp->opcode==OP_Rowid ){ |