mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-18 10:21:03 +03:00
Strengthen check-in [83da4d4104ee1870] by ignoring *all* WHERE-clause
constraints for a virtual table that is the right table of a LEFT JOIN, as such constraints are never useful. This fixes an issue discovered by Manuel Rigger. FossilOrigin-Name: 840de36df1aaeb4bad9a7c18e97cc560ba3b8c629c4520a05bc456d67b3347b9
This commit is contained in:
19
src/where.c
19
src/where.c
@@ -979,18 +979,13 @@ static sqlite3_index_info *allocateIndexInfo(
|
||||
testcase( pTerm->eOperator & WO_ALL );
|
||||
if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
|
||||
if( pTerm->wtFlags & TERM_VNULL ) continue;
|
||||
|
||||
/* tag-20191211-002: WHERE-clause constraints are not useful to the
|
||||
** right-hand table of a LEFT JOIN. See tag-20191211-001 for the
|
||||
** equivalent restriction for ordinary tables. */
|
||||
if( (pSrc->fg.jointype & JT_LEFT)!=0
|
||||
&& !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
|
||||
&& (pTerm->eOperator & (WO_IS|WO_ISNULL))
|
||||
){
|
||||
/* An "IS" term in the WHERE clause where the virtual table is the rhs
|
||||
** of a LEFT JOIN. Do not pass this term to the virtual table
|
||||
** implementation, as this can lead to incorrect results from SQL such
|
||||
** as:
|
||||
**
|
||||
** "LEFT JOIN vtab WHERE vtab.col IS NULL" */
|
||||
testcase( pTerm->eOperator & WO_ISNULL );
|
||||
testcase( pTerm->eOperator & WO_IS );
|
||||
continue;
|
||||
}
|
||||
assert( pTerm->u.leftColumn>=(-1) );
|
||||
@@ -2472,9 +2467,9 @@ static int whereLoopAddBtreeIndex(
|
||||
** to mix with a lower range bound from some other source */
|
||||
if( pTerm->wtFlags & TERM_LIKEOPT && pTerm->eOperator==WO_LT ) continue;
|
||||
|
||||
/* Do not allow constraints from the WHERE clause to be used by the
|
||||
** right table of a LEFT JOIN. Only constraints in the ON clause are
|
||||
** allowed */
|
||||
/* tag-20191211-001: Do not allow constraints from the WHERE clause to
|
||||
** be used by the right table of a LEFT JOIN. Only constraints in the
|
||||
** ON clause are allowed. See tag-20191211-002 for the vtab equivalent. */
|
||||
if( (pSrc->fg.jointype & JT_LEFT)!=0
|
||||
&& !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
|
||||
){
|
||||
|
||||
Reference in New Issue
Block a user