mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-14 00:22:38 +03:00
Code size reductions in select.c. (CVS 2989)
FossilOrigin-Name: 3c2eee5e1f6c7d701a6d362a04cf896d44e97fd9
This commit is contained in:
100
src/select.c
100
src/select.c
@@ -12,11 +12,28 @@
|
||||
** This file contains C code routines that are called by the parser
|
||||
** to handle SELECT statements in SQLite.
|
||||
**
|
||||
** $Id: select.c,v 1.297 2006/01/21 22:19:55 drh Exp $
|
||||
** $Id: select.c,v 1.298 2006/01/22 00:42:09 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
|
||||
/*
|
||||
** Delete all the content of a Select structure but do not deallocate
|
||||
** the select structure itself.
|
||||
*/
|
||||
void clearSelect(Select *p){
|
||||
sqlite3ExprListDelete(p->pEList);
|
||||
sqlite3SrcListDelete(p->pSrc);
|
||||
sqlite3ExprDelete(p->pWhere);
|
||||
sqlite3ExprListDelete(p->pGroupBy);
|
||||
sqlite3ExprDelete(p->pHaving);
|
||||
sqlite3ExprListDelete(p->pOrderBy);
|
||||
sqlite3SelectDelete(p->pPrior);
|
||||
sqlite3ExprDelete(p->pLimit);
|
||||
sqlite3ExprDelete(p->pOffset);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Allocate a new Select structure and return a pointer to that
|
||||
** structure.
|
||||
@@ -33,40 +50,48 @@ Select *sqlite3SelectNew(
|
||||
Expr *pOffset /* OFFSET value. NULL means no offset */
|
||||
){
|
||||
Select *pNew;
|
||||
Select standin;
|
||||
pNew = sqliteMalloc( sizeof(*pNew) );
|
||||
assert( !pOffset || pLimit ); /* Can't have OFFSET without LIMIT. */
|
||||
if( pNew==0 ){
|
||||
sqlite3ExprListDelete(pEList);
|
||||
sqlite3SrcListDelete(pSrc);
|
||||
sqlite3ExprDelete(pWhere);
|
||||
sqlite3ExprListDelete(pGroupBy);
|
||||
sqlite3ExprDelete(pHaving);
|
||||
sqlite3ExprListDelete(pOrderBy);
|
||||
sqlite3ExprDelete(pLimit);
|
||||
sqlite3ExprDelete(pOffset);
|
||||
}else{
|
||||
if( pEList==0 ){
|
||||
pEList = sqlite3ExprListAppend(0, sqlite3Expr(TK_ALL,0,0,0), 0);
|
||||
}
|
||||
pNew->pEList = pEList;
|
||||
pNew->pSrc = pSrc;
|
||||
pNew->pWhere = pWhere;
|
||||
pNew->pGroupBy = pGroupBy;
|
||||
pNew->pHaving = pHaving;
|
||||
pNew->pOrderBy = pOrderBy;
|
||||
pNew->isDistinct = isDistinct;
|
||||
pNew->op = TK_SELECT;
|
||||
pNew->pLimit = pLimit;
|
||||
pNew->pOffset = pOffset;
|
||||
pNew->iLimit = -1;
|
||||
pNew->iOffset = -1;
|
||||
pNew->addrOpenVirt[0] = -1;
|
||||
pNew->addrOpenVirt[1] = -1;
|
||||
pNew->addrOpenVirt[2] = -1;
|
||||
pNew = &standin;
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
}
|
||||
if( pEList==0 ){
|
||||
pEList = sqlite3ExprListAppend(0, sqlite3Expr(TK_ALL,0,0,0), 0);
|
||||
}
|
||||
pNew->pEList = pEList;
|
||||
pNew->pSrc = pSrc;
|
||||
pNew->pWhere = pWhere;
|
||||
pNew->pGroupBy = pGroupBy;
|
||||
pNew->pHaving = pHaving;
|
||||
pNew->pOrderBy = pOrderBy;
|
||||
pNew->isDistinct = isDistinct;
|
||||
pNew->op = TK_SELECT;
|
||||
pNew->pLimit = pLimit;
|
||||
pNew->pOffset = pOffset;
|
||||
pNew->iLimit = -1;
|
||||
pNew->iOffset = -1;
|
||||
pNew->addrOpenVirt[0] = -1;
|
||||
pNew->addrOpenVirt[1] = -1;
|
||||
pNew->addrOpenVirt[2] = -1;
|
||||
if( pNew==&standin) {
|
||||
clearSelect(pNew);
|
||||
pNew = 0;
|
||||
}
|
||||
return pNew;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete the given Select structure and all of its substructures.
|
||||
*/
|
||||
void sqlite3SelectDelete(Select *p){
|
||||
if( p ){
|
||||
clearSelect(p);
|
||||
sqliteFree(p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Given 1 to 3 identifiers preceeding the JOIN keyword, determine the
|
||||
** type of join. Return an integer constant that expresses that type
|
||||
@@ -330,23 +355,6 @@ static int sqliteProcessJoin(Parse *pParse, Select *p){
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Delete the given Select structure and all of its substructures.
|
||||
*/
|
||||
void sqlite3SelectDelete(Select *p){
|
||||
if( p==0 ) return;
|
||||
sqlite3ExprListDelete(p->pEList);
|
||||
sqlite3SrcListDelete(p->pSrc);
|
||||
sqlite3ExprDelete(p->pWhere);
|
||||
sqlite3ExprListDelete(p->pGroupBy);
|
||||
sqlite3ExprDelete(p->pHaving);
|
||||
sqlite3ExprListDelete(p->pOrderBy);
|
||||
sqlite3SelectDelete(p->pPrior);
|
||||
sqlite3ExprDelete(p->pLimit);
|
||||
sqlite3ExprDelete(p->pOffset);
|
||||
sqliteFree(p);
|
||||
}
|
||||
|
||||
/*
|
||||
** Insert code into "v" that will push the record on the top of the
|
||||
** stack into the sorter.
|
||||
@@ -458,7 +466,7 @@ static int selectInnerLoop(
|
||||
/* If there was a LIMIT clause on the SELECT statement, then do the check
|
||||
** to see if this row should be output.
|
||||
*/
|
||||
hasDistinct = distinct>=0 && pEList && pEList->nExpr>0;
|
||||
hasDistinct = distinct>=0 && pEList->nExpr>0;
|
||||
if( pOrderBy==0 && !hasDistinct ){
|
||||
codeOffset(v, p, iContinue, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user