/ Check-in [68557115]
Login

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

Overview
Comment:Reinsert an SCopy operation that was removed in (5523) because coverage testing indicated that it was dead code. Ticket #3324 shows that the code was not as dead as we thought it was. (CVS 5578)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6855711595b58d4b6fbaf9480720b788904d0e2d
User & Date: drh 2008-08-21 14:15:59
Context
2008-08-21
14:24
Add test cases to verify that ticket #3314 has been fixed. (CVS 5579) check-in: b46267ff user: drh tags: trunk
14:15
Reinsert an SCopy operation that was removed in (5523) because coverage testing indicated that it was dead code. Ticket #3324 shows that the code was not as dead as we thought it was. (CVS 5578) check-in: 68557115 user: drh tags: trunk
12:32
Patch to mkfunction to try and detect miscompiles. Add an unimportant assert back to pcache.c. (CVS 5577) check-in: a2f375ff 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.466 2008/08/20 16:35:10 drh Exp $
           15  +** $Id: select.c,v 1.467 2008/08/21 14:15:59 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Delete all the content of a Select structure but do not deallocate
    22     22   ** the select structure itself.
................................................................................
  3769   3769           sqlite3ExprCodeExprList(pParse, pGroupBy, regBase, 0);
  3770   3770           sqlite3VdbeAddOp2(v, OP_Sequence, sAggInfo.sortingIdx,regBase+nGroupBy);
  3771   3771           j = nGroupBy+1;
  3772   3772           for(i=0; i<sAggInfo.nColumn; i++){
  3773   3773             struct AggInfo_col *pCol = &sAggInfo.aCol[i];
  3774   3774             if( pCol->iSorterColumn>=j ){
  3775   3775               int r1 = j + regBase;
  3776         -#ifndef NDEBUG
  3777         -            int r2 = 
  3778         -#endif
  3779         -                     sqlite3ExprCodeGetColumn(pParse, 
         3776  +            int r2;
         3777  +
         3778  +            r2 = sqlite3ExprCodeGetColumn(pParse, 
  3780   3779                                  pCol->pTab, pCol->iColumn, pCol->iTable, r1, 0);
         3780  +            if( r1!=r2 ){
         3781  +              sqlite3VdbeAddOp2(v, OP_SCopy, r2, r1);
         3782  +            }
  3781   3783               j++;
  3782         -
  3783         -            /* sAggInfo.aCol[] only contains one entry per column.  So
  3784         -            ** The reference to pCol->iColumn,pCol->iTable must have been
  3785         -            ** the first reference to that column.  Hence, 
  3786         -            ** sqliteExprCodeGetColumn is guaranteed to put the result in
  3787         -            ** the column requested. 
  3788         -            */
  3789         -            assert( r1==r2 );
  3790   3784             }
  3791   3785           }
  3792   3786           regRecord = sqlite3GetTempReg(pParse);
  3793   3787           sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase, nCol, regRecord);
  3794   3788           sqlite3VdbeAddOp2(v, OP_IdxInsert, sAggInfo.sortingIdx, regRecord);
  3795   3789           sqlite3ReleaseTempReg(pParse, regRecord);
  3796   3790           sqlite3ReleaseTempRange(pParse, regBase, nCol);

Changes to test/select5.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: select5.test,v 1.19 2008/08/20 16:35:10 drh Exp $
           15  +# $Id: select5.test,v 1.20 2008/08/21 14:15:59 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   execsql {
................................................................................
   187    187       INSERT INTO t4 VALUES(5,NULL,NULL);
   188    188       INSERT INTO t4 VALUES(5,NULL,NULL);
   189    189       INSERT INTO t4 VALUES(6,7,8);
   190    190       SELECT max(x), count(x), y, z FROM t4 GROUP BY y, z ORDER BY 1
   191    191     }
   192    192   } {1 1 2 {} 2 1 3 {} 3 1 {} 5 4 2 {} 6 5 2 {} {} 6 1 7 8}
   193    193   
   194         -do_test select5.7.2 {
          194  +do_test select5-7.2 {
   195    195     execsql {
   196    196       SELECT count(*), count(x) as cnt FROM t4 GROUP BY y ORDER BY cnt;
   197    197     }
   198    198   } {1 1 1 1 1 1 5 5}
          199  +
          200  +# See ticket #3324.
          201  +#
          202  +do_test select5-8.1 {
          203  +  execsql {
          204  +    CREATE TABLE t8a(a,b);
          205  +    CREATE TABLE t8b(x);
          206  +    INSERT INTO t8a VALUES('one', 1);
          207  +    INSERT INTO t8a VALUES('one', 2);
          208  +    INSERT INTO t8a VALUES('two', 3);
          209  +    INSERT INTO t8a VALUES('one', NULL);
          210  +    INSERT INTO t8b(rowid,x) VALUES(1,111);
          211  +    INSERT INTO t8b(rowid,x) VALUES(2,222);
          212  +    INSERT INTO t8b(rowid,x) VALUES(3,333);
          213  +    SELECT a, count(b) FROM t8a, t8b WHERE b=t8b.rowid GROUP BY a ORDER BY a;
          214  +  }
          215  +} {one 2 two 1}
          216  +do_test select5-8.2 {
          217  +  execsql {
          218  +    SELECT a, count(b) FROM t8a, t8b WHERE b=+t8b.rowid GROUP BY a ORDER BY a;
          219  +  }
          220  +} {one 2 two 1}
          221  +do_test select5-8.3 {
          222  +  execsql {
          223  +    SELECT t8a.a, count(t8a.b) FROM t8a, t8b WHERE t8a.b=t8b.rowid
          224  +     GROUP BY 1 ORDER BY 1;
          225  +  }
          226  +} {one 2 two 1}
          227  +do_test select5-8.4 {
          228  +  execsql {
          229  +    SELECT a, count(*) FROM t8a, t8b WHERE b=+t8b.rowid GROUP BY a ORDER BY a;
          230  +  }
          231  +} {one 2 two 1}
          232  +do_test select5-8.5 {
          233  +  execsql {
          234  +    SELECT a, count(b) FROM t8a, t8b WHERE b<x GROUP BY a ORDER BY a;
          235  +  }
          236  +} {one 6 two 3}
          237  +do_test select5-8.6 {
          238  +  execsql {
          239  +    SELECT a, count(t8a.b) FROM t8a, t8b WHERE b=t8b.rowid 
          240  +     GROUP BY a ORDER BY 2;
          241  +  }
          242  +} {two 1 one 2}
          243  +do_test select5-8.7 {
          244  +  execsql {
          245  +    SELECT a, count(b) FROM t8a, t8b GROUP BY a ORDER BY 2;
          246  +  }
          247  +} {two 3 one 6}
          248  +do_test select5-8.8 {
          249  +  execsql {
          250  +    SELECT a, count(*) FROM t8a, t8b GROUP BY a ORDER BY 2;
          251  +  }
          252  +} {two 3 one 9}
          253  +
          254  +
          255  +
   199    256    
   200    257   finish_test