diff options
author | drh <drh@noemail.net> | 2002-04-30 19:20:28 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2002-04-30 19:20:28 +0000 |
commit | 08192d5f766249cc0c4122ba43e08b6ccc57bc0b (patch) | |
tree | 7c4d9d14c1f26c5570597580e68e65432ad524c9 /src | |
parent | ef9f708e8f7df0821c2a46fc9948810f3ac19abf (diff) | |
download | sqlite-08192d5f766249cc0c4122ba43e08b6ccc57bc0b.tar.gz sqlite-08192d5f766249cc0c4122ba43e08b6ccc57bc0b.zip |
Fix for ticket #31: Do not attempt the flattening optimization if the
subselect does not contain a FROM clause. Handle the special case where
a WHERE clause is constant. (CVS 548)
FossilOrigin-Name: 24e4cf73d22bb41d26bf3c833f1854a9c90923e8
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 6 | ||||
-rw-r--r-- | src/where.c | 11 |
2 files changed, 13 insertions, 4 deletions
diff --git a/src/select.c b/src/select.c index 0f2fc609a..530a7a3dd 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.79 2002/04/23 17:10:18 drh Exp $ +** $Id: select.c,v 1.80 2002/04/30 19:20:29 drh Exp $ */ #include "sqliteInt.h" @@ -918,6 +918,8 @@ substExprList(ExprList *pList, int iTable, ExprList *pEList, int iSub){ ** (6) The subquery does not use aggregates or the outer query is not ** DISTINCT. ** +** (7) The subquery has a FROM clause. +** ** 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. @@ -947,7 +949,7 @@ int flattenSubquery(Select *p, int iFrom, int isAgg, int subqueryIsAgg){ if( subqueryIsAgg && pSrc->nId>1 ) return 0; pSubSrc = pSub->pSrc; assert( pSubSrc ); - if( pSubSrc->nId>1 ) return 0; + if( pSubSrc->nId!=1 ) return 0; if( pSub->isDistinct && pSrc->nId>1 ) return 0; if( pSub->isDistinct && isAgg ) return 0; if( p->isDistinct && subqueryIsAgg ) return 0; diff --git a/src/where.c b/src/where.c index 0d685137a..42b6bac4d 100644 --- a/src/where.c +++ b/src/where.c @@ -13,7 +13,7 @@ ** the WHERE clause of SQL statements. Also found here are subroutines ** to generate VDBE code to evaluate expressions. ** -** $Id: where.c,v 1.40 2002/04/02 13:26:11 drh Exp $ +** $Id: where.c,v 1.41 2002/04/30 19:20:29 drh Exp $ */ #include "sqliteInt.h" @@ -193,6 +193,14 @@ WhereInfo *sqliteWhereBegin( pWInfo->pTabList = pTabList; pWInfo->base = base; pWInfo->peakNTab = pWInfo->savedNTab = pParse->nTab; + pWInfo->iBreak = sqliteVdbeMakeLabel(v); + + /* Special case: a WHERE clause that is constant. Evaluate the + ** expression and either jump over all of the code or fall thru. + */ + if( pWhere && sqliteExprIsConstant(pWhere) ){ + sqliteExprIfFalse(pParse, pWhere, pWInfo->iBreak); + } /* Split the WHERE clause into as many as 32 separate subexpressions ** where each subexpression is separated by an AND operator. Any additional @@ -422,7 +430,6 @@ WhereInfo *sqliteWhereBegin( /* Generate the code to do the search */ loopMask = 0; - pWInfo->iBreak = sqliteVdbeMakeLabel(v); for(i=0; i<pTabList->nId; i++){ int j, k; int idx = aOrder[i]; |