diff options
author | drh <drh@noemail.net> | 2015-02-09 15:21:36 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-02-09 15:21:36 +0000 |
commit | 885a5b030ee3717b78bfb82d61e6ee38ef0892ea (patch) | |
tree | 83b3684c29d19c915596413505453176b0c9a9c0 /src/select.c | |
parent | 63f845734e7de67fb04ad1e8990c41850547ce07 (diff) | |
download | sqlite-885a5b030ee3717b78bfb82d61e6ee38ef0892ea.tar.gz sqlite-885a5b030ee3717b78bfb82d61e6ee38ef0892ea.zip |
Disable the query flattener for aggregate subqueries if the parent query
uses other subqueries in its result set or WHERE clause or ORDER BY clause.
Preliminary fix for ticket [2f7170d73bf9abf8]. However it still contains
a defect similar to the COLLATE problem of [ca0d20b6cddd].
FossilOrigin-Name: 0b7d65e3fda676d193347cb782854c28a48252af
Diffstat (limited to 'src/select.c')
-rw-r--r-- | src/select.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/select.c b/src/select.c index 058bf3d57..2c4c9e41f 100644 --- a/src/select.c +++ b/src/select.c @@ -3194,7 +3194,10 @@ static void substSelect( ** ** (1) The subquery and the outer query do not both use aggregates. ** -** (2) The subquery is not an aggregate or the outer query is not a join. +** (2) The subquery is not an aggregate or (2a) the outer query is not a join +** and (2b) the outer query does not use subqueries other than the one +** FROM-clause subquery that is a candidate for flattening. (2b is +** due to ticket [2f7170d73bf9abf80] from 2015-02-09.) ** ** (3) The subquery is not the right operand of a left outer join ** (Originally ticket #306. Strengthened by ticket #3300) @@ -3331,8 +3334,17 @@ static int flattenSubquery( iParent = pSubitem->iCursor; pSub = pSubitem->pSelect; assert( pSub!=0 ); - if( isAgg && subqueryIsAgg ) return 0; /* Restriction (1) */ - if( subqueryIsAgg && pSrc->nSrc>1 ) return 0; /* Restriction (2) */ + if( subqueryIsAgg ){ + if( isAgg ) return 0; /* Restriction (1) */ + if( pSrc->nSrc>1 ) return 0; /* Restriction (2a) */ + if( (p->pWhere && ExprHasProperty(p->pWhere,EP_Subquery)) + || sqlite3AnyExprListHasProperty(p->pEList,EP_Subquery) + || sqlite3AnyExprListHasProperty(p->pOrderBy,EP_Subquery) + ){ + return 0; /* Restriction (2b) */ + } + } + pSubSrc = pSub->pSrc; assert( pSubSrc ); /* Prior to version 3.1.2, when LIMIT and OFFSET had to be simple constants, |