Make sure the min() and max() optimizer works correctly when there
is a LIMIT clause. Ticket #396. (CVS 1057) FossilOrigin-Name: c35e50717678703763c696e3e9b265add2ca6454
This commit is contained in:
parent
9347b20050
commit
e5f50722b4
14
manifest
14
manifest
@ -1,5 +1,5 @@
|
||||
C In\sthe\ssqlite\sshell,\schange\sthe\sname\sof\sfunction\sgetline()\sto\slocal_getline()\nto\savoid\sa\sclash\swith\sa\slibrary\sfunction.\s\sTicket\s#400.\s(CVS\s1056)
|
||||
D 2003-07-18T01:30:59
|
||||
C Make\ssure\sthe\smin()\sand\smax()\soptimizer\sworks\scorrectly\swhen\sthere\nis\sa\sLIMIT\sclause.\s\sTicket\s#396.\s(CVS\s1057)
|
||||
D 2003-07-19T00:44:14
|
||||
F Makefile.in 9ad23ed4ca97f9670c4496432e3fbd4b3760ebde
|
||||
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
|
||||
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
|
||||
@ -43,7 +43,7 @@ F src/parse.y 16aed0e3ed05445fa7f6a4209cc054208c7083c0
|
||||
F src/pragma.c 3b4f5a800e7a2145bc1930f323232e297d4eb782
|
||||
F src/printf.c 12e45d482ac8abcc6f786fc99e5bed7dd9a51af0
|
||||
F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
|
||||
F src/select.c 98385a4f8601aad67fc0532570fe48f9833d912e
|
||||
F src/select.c f1f3b2c2f4f30db30d03af2d0ec629ef32cb5a08
|
||||
F src/shell.c c2ba26c850874964f5ec1ebf6c43406f28e44c4a
|
||||
F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
|
||||
F src/sqlite.h.in 54619fa5df4c83b22def66bb3d24808fd03dcbae
|
||||
@ -95,7 +95,7 @@ F test/main.test 6a851b5992c4881a725a3d9647e629199df8de9d
|
||||
F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd
|
||||
F test/memdb.test cd4580f466f34c42354612a375c5adb90447e4c4
|
||||
F test/memleak.test a18e6810cae96d2f6f5136920267adbefc8e1e90
|
||||
F test/minmax.test b54ac3bc45460a4976b08ef363e05c032418726e
|
||||
F test/minmax.test 6d9b6d6ee34f42e2a58dffece1f76d35f446b3af
|
||||
F test/misc1.test c7dc2f2bd702d8283e885a64ec0714be26cfb051
|
||||
F test/misc2.test 36410e371d3924f7373988935219bda5a52cea4e
|
||||
F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162
|
||||
@ -168,7 +168,7 @@ F www/speed.tcl 2f6b1155b99d39adb185f900456d1d592c4832b3
|
||||
F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
|
||||
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
|
||||
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
|
||||
P 93a2c961b17d2459272e2d8654bd4b972f52fbe1
|
||||
R cea9e7eb8d5651e94a3de389de60c2cf
|
||||
P 558969ee8697180c74308f3f880d3240eb575af1
|
||||
R 90dfb91d095ee0113e81156a9aa2c6cc
|
||||
U drh
|
||||
Z afb3d221554241843a330036de61dbd9
|
||||
Z 4035d7869ab09e0fd1a4cac271ac32dd
|
||||
|
@ -1 +1 @@
|
||||
558969ee8697180c74308f3f880d3240eb575af1
|
||||
c35e50717678703763c696e3e9b265add2ca6454
|
27
src/select.c
27
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);
|
||||
|
@ -13,7 +13,7 @@
|
||||
# aggregate min() and max() functions and which are handled as
|
||||
# as a special case.
|
||||
#
|
||||
# $Id: minmax.test,v 1.5 2003/04/17 12:44:25 drh Exp $
|
||||
# $Id: minmax.test,v 1.6 2003/07/19 00:44:15 drh Exp $
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
@ -173,5 +173,44 @@ do_test minmax-5.5 {
|
||||
}
|
||||
} {999}
|
||||
|
||||
# Make sure the min(x) and max(x) optimizations work when there
|
||||
# is a LIMIT clause. Ticket #396.
|
||||
#
|
||||
do_test minmax-6.1 {
|
||||
execsql {
|
||||
SELECT min(a) FROM t2 LIMIT 1
|
||||
}
|
||||
} {1}
|
||||
do_test minmax-6.2 {
|
||||
execsql {
|
||||
SELECT max(a) FROM t2 LIMIT 3
|
||||
}
|
||||
} {22}
|
||||
do_test minmax-6.3 {
|
||||
execsql {
|
||||
SELECT min(a) FROM t2 LIMIT 0,100
|
||||
}
|
||||
} {1}
|
||||
do_test minmax-6.4 {
|
||||
execsql {
|
||||
SELECT max(a) FROM t2 LIMIT 1,100
|
||||
}
|
||||
} {}
|
||||
do_test minmax-6.5 {
|
||||
execsql {
|
||||
SELECT min(x) FROM t3 LIMIT 1
|
||||
}
|
||||
} {{}}
|
||||
do_test minmax-6.6 {
|
||||
execsql {
|
||||
SELECT max(x) FROM t3 LIMIT 0
|
||||
}
|
||||
} {}
|
||||
do_test minmax-6.7 {
|
||||
execsql {
|
||||
SELECT max(a) FROM t2 LIMIT 0
|
||||
}
|
||||
} {}
|
||||
|
||||
|
||||
finish_test
|
||||
|
Loading…
x
Reference in New Issue
Block a user