/ Check-in [cb78f7cb]
Login

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

Overview
Comment:Use OP_VColumn instead of OP_Column when querying virtual tables for values to save in aggregate context records. #2230. (CVS 3644)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:cb78f7cb0f0bf0c799a929fd6ea30f25e2a7b5d0
User & Date: danielk1977 2007-02-14 09:19:36
Context
2007-02-14
12:32
In the corrupt2.test script, change uses of (open ... a) to (open ... RDWR) to work around inconsistencies in behavior across various platforms. (CVS 3645) check-in: 50e86b03 user: drh tags: trunk
09:19
Use OP_VColumn instead of OP_Column when querying virtual tables for values to save in aggregate context records. #2230. (CVS 3644) check-in: cb78f7cb user: danielk1977 tags: trunk
2007-02-13
15:01
Add a new algorithm for handling INSERT which reduces fragmentation on a VACUUM. Ticket #2075. More testing needed. (CVS 3643) check-in: 9f56a878 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.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 routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.275 2007/02/07 13:09:46 drh Exp $
           15  +** $Id: expr.c,v 1.276 2007/02/14 09:19:36 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
  2271   2271                 if( pCol->iTable==pExpr->iTable &&
  2272   2272                     pCol->iColumn==pExpr->iColumn ){
  2273   2273                   break;
  2274   2274                 }
  2275   2275               }
  2276   2276               if( i>=pAggInfo->nColumn && (i = addAggInfoColumn(pAggInfo))>=0 ){
  2277   2277                 pCol = &pAggInfo->aCol[i];
         2278  +              pCol->pTab = pExpr->pTab;
  2278   2279                 pCol->iTable = pExpr->iTable;
  2279   2280                 pCol->iColumn = pExpr->iColumn;
  2280   2281                 pCol->iMem = pParse->nMem++;
  2281   2282                 pCol->iSorterColumn = -1;
  2282   2283                 pCol->pExpr = pExpr;
  2283   2284                 if( pAggInfo->pGroupBy ){
  2284   2285                   int j, n;

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.326 2007/02/01 23:02:45 drh Exp $
           15  +** $Id: select.c,v 1.327 2007/02/14 09:19:36 danielk1977 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.
................................................................................
  3143   3143           j = pGroupBy->nExpr+1;
  3144   3144           for(i=0; i<sAggInfo.nColumn; i++){
  3145   3145             struct AggInfo_col *pCol = &sAggInfo.aCol[i];
  3146   3146             if( pCol->iSorterColumn<j ) continue;
  3147   3147             if( pCol->iColumn<0 ){
  3148   3148               sqlite3VdbeAddOp(v, OP_Rowid, pCol->iTable, 0);
  3149   3149             }else{
  3150         -            sqlite3VdbeAddOp(v, OP_Column, pCol->iTable, pCol->iColumn);
         3150  +            Table *pTab = pCol->pTab;
         3151  +            int op = (pTab && IsVirtual(pTab)) ? OP_VColumn : OP_Column;
         3152  +            sqlite3VdbeAddOp(v, op, pCol->iTable, pCol->iColumn);
  3151   3153             }
  3152   3154             j++;
  3153   3155           }
  3154   3156           sqlite3VdbeAddOp(v, OP_MakeRecord, j, 0);
  3155   3157           sqlite3VdbeAddOp(v, OP_IdxInsert, sAggInfo.sortingIdx, 0);
  3156   3158           sqlite3WhereEnd(pWInfo);
  3157   3159           sqlite3VdbeAddOp(v, OP_Sort, sAggInfo.sortingIdx, addrEnd);

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.536 2007/02/13 12:49:24 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.537 2007/02/14 09:19:36 danielk1977 Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Extra interface definitions for those who need them
    21     21   */
................................................................................
   918    918                             ** from source tables rather than from accumulators */
   919    919     u8 useSortingIdx;       /* In direct mode, reference the sorting index rather
   920    920                             ** than the source table */
   921    921     int sortingIdx;         /* Cursor number of the sorting index */
   922    922     ExprList *pGroupBy;     /* The group by clause */
   923    923     int nSortingColumn;     /* Number of columns in the sorting index */
   924    924     struct AggInfo_col {    /* For each column used in source tables */
          925  +    Table *pTab;             /* Source table */
   925    926       int iTable;              /* Cursor number of the source table */
   926    927       int iColumn;             /* Column number within the source table */
   927    928       int iSorterColumn;       /* Column number in the sorting index */
   928    929       int iMem;                /* Memory location that acts as accumulator */
   929    930       Expr *pExpr;             /* The original expression */
   930    931     } *aCol;
   931    932     int nColumn;            /* Number of used entries in aCol[] */

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.588 2007/01/27 13:37:22 drh Exp $
           46  +** $Id: vdbe.c,v 1.589 2007/02/14 09:19:37 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "os.h"
    50     50   #include <ctype.h>
    51     51   #include "vdbeInt.h"
    52     52   
    53     53   /*
................................................................................
  1932   1932     **
  1933   1933     ** We also compute the number of columns in the record.  For cursors,
  1934   1934     ** the number of columns is stored in the Cursor.nField element.  For
  1935   1935     ** records on the stack, the next entry down on the stack is an integer
  1936   1936     ** which is the number of records.
  1937   1937     */
  1938   1938     pC = p->apCsr[p1];
         1939  +#ifndef SQLITE_OMIT_VIRTUALTABLE
         1940  +  assert( pC->pVtabCursor==0 );
         1941  +#endif
  1939   1942     assert( pC!=0 );
  1940   1943     if( pC->pCursor!=0 ){
  1941   1944       /* The record is stored in a B-Tree */
  1942   1945       rc = sqlite3VdbeCursorMoveto(pC);
  1943   1946       if( rc ) goto abort_due_to_error;
  1944   1947       zRec = 0;
  1945   1948       pCrsr = pC->pCursor;

Changes to test/vtab2.test.

     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     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.
    12     12   #
    13         -# $Id: vtab2.test,v 1.6 2006/08/13 19:04:19 drh Exp $
           13  +# $Id: vtab2.test,v 1.7 2007/02/14 09:19:37 danielk1977 Exp $
    14     14   
    15     15   set testdir [file dirname $argv0]
    16     16   source $testdir/tester.tcl
    17     17   
    18     18   ifcapable !vtab||!schema_pragmas {
    19     19     finish_test
    20     20     return
................................................................................
    32     32     main schema 2 cid        {} 0 {} 0 \
    33     33     main schema 3 name       {} 0 {} 0 \
    34     34     main schema 4 type       {} 0 {} 0 \
    35     35     main schema 5 not_null   {} 0 {} 0 \
    36     36     main schema 6 dflt_value {} 0 {} 0 \
    37     37     main schema 7 pk         {} 0 {} 0 \
    38     38   ]
           39  +
           40  +# See ticket #2230.
           41  +#
           42  +do_test vtab2-1.2 {
           43  +  execsql {
           44  +    SELECT length(tablename) FROM schema GROUP by tablename;
           45  +  }
           46  +} {6}
           47  +do_test vtab2-1.3 {
           48  +  execsql {
           49  +    SELECT tablename FROM schema GROUP by length(tablename);
           50  +  }
           51  +} {schema}
           52  +do_test vtab2-1.4 {
           53  +  execsql {
           54  +    SELECT length(tablename) FROM schema GROUP by length(tablename);
           55  +  }
           56  +} {6}
    39     57   
    40     58   register_tclvar_module [sqlite3_connection_pointer db]
    41     59   do_test vtab2-2.1 {
    42     60     set ::abc 123
    43     61     execsql {
    44     62       CREATE VIRTUAL TABLE vars USING tclvar;
    45     63       SELECT * FROM vars WHERE name='abc';