aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2008-02-15 14:33:03 +0000
committerdrh <drh@noemail.net>2008-02-15 14:33:03 +0000
commitc52e355de1b79a5047358c501f3f6fa70b7a0c5d (patch)
tree82aeebacba04e5db7204fefbfc131ee46289263e /src
parent52391cb406284740478d3337382c44852d658902 (diff)
downloadsqlite-c52e355de1b79a5047358c501f3f6fa70b7a0c5d.tar.gz
sqlite-c52e355de1b79a5047358c501f3f6fa70b7a0c5d.zip
Do not apply the query flattening optimization when the outer query is an
aggregate and the inner query contains an ORDER BY clause. Ticket #2943. (CVS 4791) FossilOrigin-Name: 6d33cbd99cb0db680767ceb31ec6345e90a805bc
Diffstat (limited to 'src')
-rw-r--r--src/select.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/src/select.c b/src/select.c
index a6ecc6fc8..856f1f057 100644
--- a/src/select.c
+++ b/src/select.c
@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.413 2008/02/13 18:25:27 danielk1977 Exp $
+** $Id: select.c,v 1.414 2008/02/15 14:33:04 drh Exp $
*/
#include "sqliteInt.h"
@@ -2417,6 +2417,10 @@ static void substSelect(
** subquery does not have both an ORDER BY and a LIMIT clause.
** (See ticket #2339)
**
+** (16) The outer query is not an aggregate or the subquery does
+** not contain ORDER BY. (Ticket #2942) This used to not matter
+** until we introduced the group_concat() function.
+**
** In this routine, the "p" parameter is a pointer to the outer query.
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
** uses aggregates and subqueryIsAgg is true if the subquery uses aggregates.
@@ -2474,6 +2478,7 @@ static int flattenSubquery(
if( (p->disallowOrderBy || p->pOrderBy) && pSub->pOrderBy ){
return 0; /* Restriction (11) */
}
+ if( isAgg && pSub->pOrderBy ) return 0; /* Restriction (16) */
/* Restriction 3: If the subquery is a join, make sure the subquery is
** not used as the right operand of an outer join. Examples of why this
@@ -3143,16 +3148,6 @@ int sqlite3Select(
}
#endif
- /* Check for the special case of a min() or max() function by itself
- ** in the result set.
- */
-#if 0
- if( simpleMinMaxQuery(pParse, p, pDest) ){
- rc = 0;
- goto select_end;
- }
-#endif
-
/* Check to see if this is a subquery that can be "flattened" into its parent.
** If flattening is a possiblity, do so and return immediately.
*/