mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-18 10:21:03 +03:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user