1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Minor optimizations for sub-selects in EXISTS(...) expressions: Discard any DISTINCT or ORDER BY clauses and do not calculate any column values. (CVS 4658)

FossilOrigin-Name: fbd17a8976cc9b4dd7c7c903d8beade9a7ef095f
This commit is contained in:
danielk1977
2008-01-02 17:11:14 +00:00
parent 6c8c8ce0e2
commit 9ed1dfa802
4 changed files with 29 additions and 19 deletions

View File

@@ -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.376 2008/01/02 16:27:10 danielk1977 Exp $
** $Id: select.c,v 1.377 2008/01/02 17:11:14 danielk1977 Exp $
*/
#include "sqliteInt.h"
@@ -548,7 +548,10 @@ static int selectInnerLoop(
for(i=0; i<nColumn; i++){
sqlite3VdbeOp3Int(v, OP_Column, srcTab, i, iMem+i+1);
}
}else{
}else if( eDest!=SRT_Exists ){
/* If the destination is an EXISTS(...) expression, the actual
** values returned by the SELECT are not required.
*/
for(i=0; i<n; i++){
sqlite3ExprIntoReg(pParse, pEList->a[i].pExpr, iMem+i+1);
}
@@ -3143,6 +3146,13 @@ int sqlite3Select(
pOrderBy = p->pOrderBy;
if( IgnorableOrderby(pDest) ){
p->pOrderBy = 0;
/* In these cases the DISTINCT operator makes no difference to the
** results, so remove it if it were specified.
*/
assert(pDest->eDest==SRT_Exists || pDest->eDest==SRT_Union ||
pDest->eDest==SRT_Except || pDest->eDest==SRT_Discard);
p->isDistinct = 0;
}
if( sqlite3SelectResolve(pParse, p, 0) ){
goto select_end;