/ Check-in [37116550]
Login

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

Overview
Comment:Bug fix in the new COUNT(DISTINCT) logic. Ticket #1420. (CVS 2689)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 37116550d33d8e3bdc15cd9998b9d2b97dec312b
User & Date: drh 2005-09-12 23:03:17
Context
2005-09-13
00:00
Automatically set the NDEBUG preprocessor macro unless SQLITE_DEBUG is set. In this way, assert() statements become opt-in rather than opt-out. (CVS 2690) check-in: 2ec2bd85 user: drh tags: trunk
2005-09-12
23:03
Bug fix in the new COUNT(DISTINCT) logic. Ticket #1420. (CVS 2689) check-in: 37116550 user: drh tags: trunk
2005-09-11
11:56
COUNT(DISTINCT x) is now fully functional, though it could benefit from additional testing. (CVS 2688) check-in: 2f397bd8 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/select.c.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.268 2005/09/11 11:56:28 drh Exp $
*/
#include "sqliteInt.h"


/*
** Allocate a new Select structure and return a pointer to that
** structure.
................................................................................
      sqlite3ExprCodeExprList(pParse, pList);
    }else{
      nArg = 0;
    }
    if( pF->iDistinct>=0 ){
      addrNext = sqlite3VdbeMakeLabel(v);
      assert( nArg==1 );
      codeDistinct(v, pF->iDistinct, addrNext, 1, 1);
    }
    if( pF->pFunc->needCollSeq ){
      CollSeq *pColl = 0;
      struct ExprList_item *pItem;
      int j;
      for(j=0, pItem=pList->a; !pColl && j<pList->nExpr; j++, pItem++){
        pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);







|







 







|







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
....
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.269 2005/09/12 23:03:17 drh Exp $
*/
#include "sqliteInt.h"


/*
** Allocate a new Select structure and return a pointer to that
** structure.
................................................................................
      sqlite3ExprCodeExprList(pParse, pList);
    }else{
      nArg = 0;
    }
    if( pF->iDistinct>=0 ){
      addrNext = sqlite3VdbeMakeLabel(v);
      assert( nArg==1 );
      codeDistinct(v, pF->iDistinct, addrNext, 1, 2);
    }
    if( pF->pFunc->needCollSeq ){
      CollSeq *pColl = 0;
      struct ExprList_item *pItem;
      int j;
      for(j=0, pItem=pList->a; !pColl && j<pList->nExpr; j++, pItem++){
        pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);

Changes to test/distinctagg.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
30
31
32
33
34
35
36













37
38
39
40
41
42
43
44
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is the DISTINCT modifier on aggregate functions.
#
# $Id: distinctagg.test,v 1.1 2005/09/11 11:56:28 drh Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test distinctagg-1.1 {
  execsql {
................................................................................
  }
} {1 2 3 3}
do_test distinctagg-1.2 {
  execsql {
    SELECT b, count(distinct c) FROM t1 GROUP BY b ORDER BY b
  }
} {2 1 3 2}














do_test distinctagg-2.1 {
  catchsql {
    SELECT count(distinct) FROM t1;
  }
} {1 {DISTINCT in aggregate must be followed by an expression}}

finish_test







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>








7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this script is the DISTINCT modifier on aggregate functions.
#
# $Id: distinctagg.test,v 1.2 2005/09/12 23:03:17 drh Exp $


set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test distinctagg-1.1 {
  execsql {
................................................................................
  }
} {1 2 3 3}
do_test distinctagg-1.2 {
  execsql {
    SELECT b, count(distinct c) FROM t1 GROUP BY b ORDER BY b
  }
} {2 1 3 2}
do_test distinctagg-1.3 {
  execsql {
    INSERT INTO t1 SELECT a+1, b+3, c+5 FROM t1;
    INSERT INTO t1 SELECT a+2, b+6, c+10 FROM t1;
    INSERT INTO t1 SELECT a+4, b+12, c+20 FROM t1;
    SELECT count(*), count(distinct a), count(distinct b) FROM t1
  }
} {24 8 16}
do_test distinctagg-1.4 {
  execsql {
    SELECT a, count(distinct c) FROM t1 GROUP BY a ORDER BY a
  }
} {1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3}

do_test distinctagg-2.1 {
  catchsql {
    SELECT count(distinct) FROM t1;
  }
} {1 {DISTINCT in aggregate must be followed by an expression}}

finish_test