Aggregates with GROUP BY can sometimes return no result rows. (CVS 2674)

FossilOrigin-Name: 0c3e368d4766685b94a44f2c514e2dea806c297c
This commit is contained in:
drh 2005-09-08 12:57:28 +00:00
parent eb796a7c8f
commit 97571957a1
4 changed files with 25 additions and 11 deletions

View File

@ -1,5 +1,5 @@
C While\sdoing\sa\stransaction\scomment,\suse\sfdatasync()\sinstead\sof\sfsync()\sin\ncases\sthere\sthe\sfile\ssize\sis\sunchanged.\s(CVS\s2673)
D 2005-09-08T12:38:42
C Aggregates\swith\sGROUP\sBY\scan\ssometimes\sreturn\sno\sresult\srows.\s(CVS\s2674)
D 2005-09-08T12:57:28
F Makefile.in 12784cdce5ffc8dfb707300c34e4f1eb3b8a14f1
F Makefile.linux-gcc 06be33b2a9ad4f005a5f42b22c4a19dab3cbb5c7
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -63,7 +63,7 @@ F src/pragma.c 69413fbdc0c6aaa493a776ea52c1b3e6cf35dfb2
F src/prepare.c 86f0d8e744b8d956eff6bc40e29049efee017610
F src/printf.c c01e9ad473d79463fb1f483b1eca5c3cbed2a4e5
F src/random.c 90adff4e73a3b249eb4f1fc2a6ff9cf78c7233a4
F src/select.c 7e52f53ccf116456f1f5eebb5493973eda43c89a
F src/select.c 2bba89bb64cd41991e5843617e2851c29661638d
F src/shell.c b21daba017b8feef2fdc65ecde57f70209494217
F src/sqlite.h.in 461b2535550cf77aedfd44385da11ef7d63e57a2
F src/sqliteInt.h 0688a83d0a6d8a483666f742bceebe56a6f4d1bc
@ -199,7 +199,7 @@ F test/safety.test 907b64fee719554a3622853812af3886fddbbb4f
F test/schema.test 21cbe7dac652f6d7eb058f3dec369bdbf46bbde6
F test/select1.test 480233d4f5a81d7d59a55e40d05084d97e57ecdf
F test/select2.test f3c2678c3a9f3cf08ec4988a3845bda64be6d9e3
F test/select3.test f8372ca3e99c4f2cf2e25498603c6b3bf5306613
F test/select3.test 551e25e97baf4ed3ec1d3d99776f936517938e60
F test/select4.test c239f516aa31f42f2ef7c6d7cd01105f08f934ca
F test/select5.test 2dcd382d1d416bf984cd3030ca9f386488a51ab1
F test/select6.test 21b72c56e7cbcefd063fdf9bc6c89342aedabccf
@ -306,7 +306,7 @@ F www/tclsqlite.tcl 3df553505b6efcad08f91e9b975deb2e6c9bb955
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P bc723235e65eb4da7d2e4b18653f1173374cb407
R 07bc4f21cf6f17d7905a2bca119ba6c3
P 3c555a87493128620ac967faf7c63c2a58856e9e
R 6b6b6dcfe86fc8c820bc96221b7fd247
U drh
Z 65f2e95a5335cb7bacc36cdf222b2679
Z db9de90b9b51092ac5db6e1c74b63c06

View File

@ -1 +1 @@
3c555a87493128620ac967faf7c63c2a58856e9e
0c3e368d4766685b94a44f2c514e2dea806c297c

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.265 2005/09/08 01:58:43 drh Exp $
** $Id: select.c,v 1.266 2005/09/08 12:57:28 drh Exp $
*/
#include "sqliteInt.h"
@ -2920,7 +2920,7 @@ int sqlite3Select(
sqlite3VdbeAddOp(v, OP_MakeRecord, j, 0);
sqlite3VdbeAddOp(v, OP_IdxInsert, sAggInfo.sortingIdx, 0);
sqlite3WhereEnd(pWInfo);
sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, 0);
sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, addrEnd);
sAggInfo.useSortingIdx = 1;
}

View File

@ -12,7 +12,7 @@
# focus of this file is testing aggregate functions and the
# GROUP BY and HAVING clauses of SELECT statements.
#
# $Id: select3.test,v 1.14 2005/09/08 10:37:01 drh Exp $
# $Id: select3.test,v 1.15 2005/09/08 12:57:28 drh Exp $
set testdir [file dirname $argv0]
source $testdir/tester.tcl
@ -220,6 +220,20 @@ do_test select3-6.8 {
}
} {5 17 4 9 3 5 2 3 1 2 0 1}
# Sometimes an aggregate query can return no rows at all.
#
do_test select3-7.1 {
execsql {
CREATE TABLE t2(a,b);
INSERT INTO t2 VALUES(1,2);
SELECT a, sum(b) FROM t2 WHERE b=5 GROUP BY a;
}
} {}
do_test select3-7.2 {
execsql {
SELECT a, sum(b) FROM t2 WHERE b=5;
}
} {{} 0}
finish_test