/ Check-in [0c3e368d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Aggregates with GROUP BY can sometimes return no result rows. (CVS 2674)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0c3e368d4766685b94a44f2c514e2dea806c297c
User & Date: drh 2005-09-08 12:57:28
Context
2005-09-08
14:17
Remove a few unused variables detected by Borland C. Ticket #1412. (CVS 2675) check-in: cdfe372a user: drh tags: trunk
12:57
Aggregates with GROUP BY can sometimes return no result rows. (CVS 2674) check-in: 0c3e368d user: drh tags: trunk
12:38
While doing a transaction comment, use fdatasync() instead of fsync() in cases there the file size is unchanged. (CVS 2673) check-in: 3c555a87 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.265 2005/09/08 01:58:43 drh Exp $
           15  +** $Id: select.c,v 1.266 2005/09/08 12:57:28 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Allocate a new Select structure and return a pointer to that
    22     22   ** structure.
................................................................................
  2916   2916               sqlite3VdbeAddOp(v, OP_Column, pCol->iTable, pCol->iColumn);
  2917   2917             }
  2918   2918             j++;
  2919   2919           }
  2920   2920           sqlite3VdbeAddOp(v, OP_MakeRecord, j, 0);
  2921   2921           sqlite3VdbeAddOp(v, OP_IdxInsert, sAggInfo.sortingIdx, 0);
  2922   2922           sqlite3WhereEnd(pWInfo);
  2923         -        sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, 0);
         2923  +        sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, addrEnd);
  2924   2924           sAggInfo.useSortingIdx = 1;
  2925   2925         }
  2926   2926   
  2927   2927         /* Evaluate the current GROUP BY terms and store in b0, b1, b2...
  2928   2928         ** (b0 is memory location iBMem+0, b1 is iBMem+1, and so forth)
  2929   2929         ** Then compare the current GROUP BY terms against the GROUP BY terms
  2930   2930         ** from the previous row currently stored in a0, a1, a2...

Changes to test/select3.test.

     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # This file implements regression tests for SQLite library.  The
    12     12   # focus of this file is testing aggregate functions and the
    13     13   # GROUP BY and HAVING clauses of SELECT statements.
    14     14   #
    15         -# $Id: select3.test,v 1.14 2005/09/08 10:37:01 drh Exp $
           15  +# $Id: select3.test,v 1.15 2005/09/08 12:57:28 drh Exp $
    16     16   
    17     17   set testdir [file dirname $argv0]
    18     18   source $testdir/tester.tcl
    19     19   
    20     20   # Build some test data
    21     21   #
    22     22   do_test select3-1.0 {
................................................................................
   216    216   } {0 1 1 2 2 3 3 5 4 9 5 17}
   217    217   do_test select3-6.8 {
   218    218     execsql {
   219    219       SELECT log, min(n) FROM t1 GROUP BY log ORDER BY 1 DESC;
   220    220     }
   221    221   } {5 17 4 9 3 5 2 3 1 2 0 1}
   222    222   
          223  +# Sometimes an aggregate query can return no rows at all.
          224  +#
          225  +do_test select3-7.1 {
          226  +  execsql {
          227  +    CREATE TABLE t2(a,b);
          228  +    INSERT INTO t2 VALUES(1,2);
          229  +    SELECT a, sum(b) FROM t2 WHERE b=5 GROUP BY a;
          230  +  }
          231  +} {}
          232  +do_test select3-7.2 {
          233  +  execsql {
          234  +    SELECT a, sum(b) FROM t2 WHERE b=5;
          235  +  }
          236  +} {{} 0}
   223    237   
   224    238   
   225    239   finish_test