/ Check-in [090b2917]
Login

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

Overview
Comment:Fix a broken assert() in where.c.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1:090b29177fbc9faa83b560d92ddc3710d291776e
User & Date: dan 2011-07-02 06:44:05
Context
2011-07-02
09:46
Merge experimental changes improving optimization of DISTINCT queries with the trunk. check-in: 45e581bf user: dan tags: trunk
06:44
Fix a broken assert() in where.c. Closed-Leaf check-in: 090b2917 user: dan tags: experimental
2011-07-01
18:43
Merge latest trunk changes with experimental branch. check-in: e56be74e user: dan tags: experimental
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  1509   1509     /* If there is more than one table or sub-select in the FROM clause of
  1510   1510     ** this query, then it will not be possible to show that the DISTINCT 
  1511   1511     ** clause is redundant. */
  1512   1512     if( pTabList->nSrc!=1 ) return 0;
  1513   1513     iBase = pTabList->a[0].iCursor;
  1514   1514     pTab = pTabList->a[0].pTab;
  1515   1515   
  1516         -  /* If any of the expressions is an IPK column, then return true. */
         1516  +  /* If any of the expressions is an IPK column on table iBase, then return 
         1517  +  ** true. Note: The (p->iTable==iBase) part of this test may be false if the
         1518  +  ** current SELECT is a correlated sub-query.
         1519  +  */
  1517   1520     for(i=0; i<pDistinct->nExpr; i++){
  1518   1521       Expr *p = pDistinct->a[i].pExpr;
  1519         -    assert( p->op!=TK_COLUMN || p->iTable==iBase );
  1520         -    if( p->op==TK_COLUMN && p->iColumn<0 ) return 1;
         1522  +    if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
  1521   1523     }
  1522   1524   
  1523   1525     /* Loop through all indices on the table, checking each to see if it makes
  1524   1526     ** the DISTINCT qualifier redundant. It does so if:
  1525   1527     **
  1526   1528     **   1. The index is itself UNIQUE, and
  1527   1529     **

Changes to test/distinct.test.

   152    152     8   "b COLLATE nocase FROM t1"                           {}      {b}
   153    153     9   "b COLLATE nocase FROM t1 ORDER BY b COLLATE nocase" {}      {B}
   154    154   } {
   155    155     do_execsql_test    2.$tn.1 "SELECT DISTINCT $sql" $res
   156    156     do_temptables_test 2.$tn.2 "SELECT DISTINCT $sql" $temptables
   157    157   }
   158    158   
          159  +do_execsql_test 2.A {
          160  +  SELECT (SELECT DISTINCT o.a FROM t1 AS i) FROM t1 AS o;
          161  +} {a A a A}
   159    162   
   160    163   
   161    164   
   162    165   
   163    166   finish_test