diff options
author | dan <Dan Kennedy> | 2021-04-03 19:23:59 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2021-04-03 19:23:59 +0000 |
commit | f330d53ff32f33ebe77d40dd70ad7712f317e8a8 (patch) | |
tree | 23beb04e46e7c3c7a815c9a776843db418485cee /src/where.c | |
parent | 9af69ff547d76f1f8c7c4513fdb6c0ca1a32f9fc (diff) | |
download | sqlite-f330d53ff32f33ebe77d40dd70ad7712f317e8a8.tar.gz sqlite-f330d53ff32f33ebe77d40dd70ad7712f317e8a8.zip |
Fix a crash in handling queries of the form "SELECT aggregate(DISTINCT tbl.col) FROM ... LEFT JOIN tbl ...". Fixes a problem introduced by [ef4ac0ddd297bbd3].
FossilOrigin-Name: 0dcf808ddf23da834da724d88b1715ed06565f1f1290713ff42a3fcf6ffb802e
Diffstat (limited to 'src/where.c')
-rw-r--r-- | src/where.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/where.c b/src/where.c index ff6220b83..22ad55846 100644 --- a/src/where.c +++ b/src/where.c @@ -5025,9 +5025,7 @@ WhereInfo *sqlite3WhereBegin( /* Attempt to omit tables from the join that do not affect the result. ** For a table to not affect the result, the following must be true: ** - ** 1) The query must not be an aggregate. Or it must be an aggregate - ** that contains only one aggregate function with the DISTINCT - ** qualifier. e.g. "SELECT count(DISTINCT ...) FROM". + ** 1) The query must not be an aggregate. ** 2) The table must be the RHS of a LEFT JOIN. ** 3) Either the query must be DISTINCT, or else the ON or USING clause ** must contain a constraint that limits the scan of the table to @@ -5055,7 +5053,8 @@ WhereInfo *sqlite3WhereBegin( */ notReady = ~(Bitmask)0; if( pWInfo->nLevel>=2 - && pResultSet!=0 /* guarantees condition (1) above */ + && pResultSet!=0 /* these two combine to guarantee */ + && 0==(wctrlFlags & WHERE_AGG_DISTINCT) /* condition (1) above */ && OptimizationEnabled(db, SQLITE_OmitNoopJoin) ){ int i; |