-C Registerify\sthe\sSRT_Subroutine\sdestination\sfor\sSELECT\sresults.\s(CVS\s4690)
-D 2008-01-06T00:25:22
+C Comment\schanges\sin\sselect.c.\s(CVS\s4691)
+D 2008-01-07T10:16:41
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/prepare.c f1bb8eb642082e618a359c08e3e107490eafe0e3
F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910
F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da
-F src/select.c 3dc81bc22d54b4b08a825f926587e1f96ded57c3
+F src/select.c 31faeb619940082085e75f4cbef3f44c5e0f12d5
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 5391e889384d2062249f668110d64ed16f601c4b
F src/sqlite.h.in 2a7e3776534bbe6ff2cdc058f3abebe91e7e429f
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 6bb1b1bc1858028b743a4f660d42d5e9595dc022
-R b9dfb6958eba47fbda8ba22262d4cfe6
-U drh
-Z 16b2a7371bc928893099feda1e3b8325
+P 8201f71729c3afbb41764cea3cda65b03150cb0c
+R e1386487a1716925644579ddb593d24b
+U danielk1977
+Z f79dec53250d0fbc0e2807bb20650e3c
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
-** $Id: select.c,v 1.390 2008/01/06 00:25:22 drh Exp $
+** $Id: select.c,v 1.391 2008/01/07 10:16:41 danielk1977 Exp $
*/
#include "sqliteInt.h"
** it is, or 0 otherwise. At present, a query is considered to be
** a min()/max() query if:
**
-** 1. The result set contains exactly one element, either
-** min(x) or max(x), where x is a column identifier.
+** 1. There is a single object in the FROM clause.
+**
+** 2. There is a single expression in the result set, and it is
+** either min(x) or max(x), where x is a column reference.
*/
static int minMaxQuery(Parse *pParse, Select *p){
Expr *pExpr;
ExprList *pDel = 0;
u8 flag;
+ /* Check if the query is of one of the following forms:
+ **
+ ** SELECT min(x) FROM ...
+ ** SELECT max(x) FROM ...
+ **
+ ** If it is, then ask the code in where.c to attempt to sort results
+ ** as if there was an "ORDER ON x" or "ORDER ON x DESC" clause.
+ ** If where.c is able to produce results sorted in this order, then
+ ** add vdbe code to break out of the processing loop after the
+ ** first iteration (since the first iteration of the loop is
+ ** guaranteed to operate on the row with the minimum or maximum
+ ** value of x, the only row required).
+ **
+ ** A special flag must be passed to sqlite3WhereBegin() to slightly
+ ** modify behaviour as follows:
+ **
+ ** + If the query is a "SELECT min(x)", then the loop coded by
+ ** where.c should not iterate over any values with a NULL value
+ ** for x.
+ **
+ ** + The optimizer code in where.c (the thing that decides which
+ ** index or indices to use) should place a different priority on
+ ** satisfying the 'ORDER BY' clause than it does in other cases.
+ ** Refer to code and comments in where.c for details.
+ */
flag = minMaxQuery(pParse, p);
if( flag ){
pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->pList);