aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2003-07-19 00:44:14 +0000
committerdrh <drh@noemail.net>2003-07-19 00:44:14 +0000
commite5f50722b49705ce9eb00d46e758e5936c19c67f (patch)
tree516e085b0144d276be644e6596efb5ec4766099a /src/select.c
parent9347b200502a1eb5c410aada4083ea3d4c2501c9 (diff)
downloadsqlite-e5f50722b49705ce9eb00d46e758e5936c19c67f.tar.gz
sqlite-e5f50722b49705ce9eb00d46e758e5936c19c67f.zip
Make sure the min() and max() optimizer works correctly when there
is a LIMIT clause. Ticket #396. (CVS 1057) FossilOrigin-Name: c35e50717678703763c696e3e9b265add2ca6454
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/select.c b/src/select.c
index 5c5c2e84d..b5d1727f2 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.143 2003/07/16 11:51:36 drh Exp $
+** $Id: select.c,v 1.144 2003/07/19 00:44:14 drh Exp $
*/
#include "sqliteInt.h"
@@ -1852,13 +1852,13 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
if( pIdx==0 ) return 0;
}
- /* Identify column names if we will be using the callback. This
+ /* Identify column types if we will be using the callback. This
** step is skipped if the output is going to a table or a memory cell.
+ ** The column names have already been generated in the calling function.
*/
v = sqliteGetVdbe(pParse);
if( v==0 ) return 0;
if( eDest==SRT_Callback ){
- generateColumnNames(pParse, p->pSrc, p->pEList);
generateColumnTypes(pParse, p->pSrc, p->pEList);
}
@@ -2120,14 +2120,6 @@ int sqliteSelect(
}
}
- /* Check for the special case of a min() or max() function by itself
- ** in the result set.
- */
- if( simpleMinMaxQuery(pParse, p, eDest, iParm) ){
- rc = 0;
- goto select_end;
- }
-
/* Begin generating code.
*/
v = sqliteGetVdbe(pParse);
@@ -2173,6 +2165,14 @@ int sqliteSelect(
p->nOffset = iMem;
}
+ /* Check for the special case of a min() or max() function by itself
+ ** in the result set.
+ */
+ if( simpleMinMaxQuery(pParse, p, eDest, iParm) ){
+ rc = 0;
+ goto select_end;
+ }
+
/* Generate code for all sub-queries in the FROM clause
*/
for(i=0; i<pTabList->nSrc; i++){
@@ -2214,6 +2214,11 @@ int sqliteSelect(
/* Identify column types if we will be using a callback. This
** step is skipped if the output is going to a destination other
** than a callback.
+ **
+ ** We have to do this separately from the creation of column names
+ ** above because if the pTabList contains views then they will not
+ ** have been resolved and we will not know the column types until
+ ** now.
*/
if( eDest==SRT_Callback ){
generateColumnTypes(pParse, pTabList, pEList);