aboutsummaryrefslogtreecommitdiff
path: root/src/wherecode.c
diff options
context:
space:
mode:
authordrh <>2022-03-03 15:59:22 +0000
committerdrh <>2022-03-03 15:59:22 +0000
commitc9bcc5aab787e65ef1593d5b0943ad7b4bf4645b (patch)
tree3c03e912781891a3fd099719ddf9900a6386ca6e /src/wherecode.c
parent1902516d16d24506a7ae8ce3ac776bbad78c539e (diff)
downloadsqlite-c9bcc5aab787e65ef1593d5b0943ad7b4bf4645b.tar.gz
sqlite-c9bcc5aab787e65ef1593d5b0943ad7b4bf4645b.zip
Fix for the problem identified in
[forum:/forumpost/0cd8e058bf|forum post 0cd8e058bf]: When evaluating an multi-index OR, do not push down auxiliary WHERE clause terms that involve subqueries into the OR-subqueries. Otherwise, the covering-index optimizer might convert table-references into index-references for the particular OR index that is active for the branch in which the subquery subroutine is coded, and those index-references will not work if the subquery subroutine is invoked from a different OR branch that uses a different index. FossilOrigin-Name: 61a1c6dbd089979cbeb8b0c0c5ee1ab1abcb466be1d21a3a851be73c27e67a6c
Diffstat (limited to 'src/wherecode.c')
-rw-r--r--src/wherecode.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/wherecode.c b/src/wherecode.c
index 214912917..ff82ffc1a 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -2345,6 +2345,14 @@ Bitmask sqlite3WhereCodeOneLoopStart(
** the initialization of the right-hand operand of the vector comparison
** might not occur, or might occur only in an OR branch that is not
** taken. dbsqlfuzz 80a9fade844b4fb43564efc972bcb2c68270f5d1.
+ **
+ ** 2022-03-03: Do not push down expressions that involve subqueries.
+ ** The subquery might get coded as a subroutine. Any table-references
+ ** in the subquery might be resolved to index-references for the index on
+ ** the OR branch in which the subroutine is coded. But if the subroutine
+ ** is invoked from a different OR branch that uses a different index, such
+ ** index-references will not work. tag-20220303a
+ ** https://sqlite.org/forum/forumpost/36937b197273d403
*/
if( pWC->nTerm>1 ){
int iTerm;
@@ -2357,8 +2365,8 @@ Bitmask sqlite3WhereCodeOneLoopStart(
if( (pWC->a[iTerm].wtFlags & (TERM_VIRTUAL|TERM_CODED|TERM_SLICE))!=0 ){
continue;
}
- if( (pWC->a[iTerm].eOperator & WO_ALL)==0 ) continue;
- testcase( pWC->a[iTerm].wtFlags & TERM_ORINFO );
+ if( (pWC->a[iTerm].eOperator & WO_SINGLE)==0 ) continue;
+ if( ExprHasProperty(pExpr, EP_Subquery) ) continue; /* tag-20220303a */
pExpr = sqlite3ExprDup(db, pExpr, 0);
pAndExpr = sqlite3ExprAnd(pParse, pAndExpr, pExpr);
}