diff options
author | drh <drh@noemail.net> | 2009-04-02 16:59:47 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2009-04-02 16:59:47 +0000 |
commit | e8902a70fe07fcbc3929ed1b44f46fd6dea418b8 (patch) | |
tree | 8c5f2f4800130474b1c03d7d42f9d53429e18b9f /src | |
parent | 3034e3d3649c71770a11de94d38412d4abd4ef98 (diff) | |
download | sqlite-e8902a70fe07fcbc3929ed1b44f46fd6dea418b8.tar.gz sqlite-e8902a70fe07fcbc3929ed1b44f46fd6dea418b8.zip |
Disable the query flattening optimization when the subquery is a compound
query with an ORDER BY clause. Ticket #3773 shows why that combination
does not work. (CVS 6437)
FossilOrigin-Name: 23f90d50737a36ebd17152dd4667948ce7049967
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/select.c b/src/select.c index b7f3c6382..08d9e416f 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.506 2009/03/31 03:41:57 shane Exp $ +** $Id: select.c,v 1.507 2009/04/02 16:59:47 drh Exp $ */ #include "sqliteInt.h" @@ -2555,6 +2555,12 @@ static void substSelect( ** (19) The subquery does not use LIMIT or the outer query does not ** have a WHERE clause. ** +** (20) If the sub-query is a compound select, then it must not use +** an ORDER BY clause. Ticket #3773. We could relax this constraint +** somewhat by saying that the terms of the ORDER BY clause must +** appear as unmodified result columns in the outer query. But +** have other optimizations in mind to deal with that case. +** ** 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. @@ -2665,6 +2671,9 @@ static int flattenSubquery( ** queries. */ if( pSub->pPrior ){ + if( pSub->pOrderBy ){ + return 0; /* Restriction 20 */ + } if( isAgg || (p->selFlags & SF_Distinct)!=0 || pSrc->nSrc!=1 ){ return 0; } |