From 0817d0dfc26c0e456f915974115adf6c5785c209 Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Wed, 14 Feb 2007 09:19:36 +0000 Subject: [PATCH] Use OP_VColumn instead of OP_Column when querying virtual tables for values to save in aggregate context records. #2230. (CVS 3644) FossilOrigin-Name: cb78f7cb0f0bf0c799a929fd6ea30f25e2a7b5d0 --- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/expr.c | 3 ++- src/select.c | 6 ++++-- src/sqliteInt.h | 3 ++- src/vdbe.c | 5 ++++- test/vtab2.test | 20 +++++++++++++++++++- 7 files changed, 43 insertions(+), 18 deletions(-) diff --git a/manifest b/manifest index 53d18c3912..51b36bbbc0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\snew\salgorithm\sfor\shandling\sINSERT\swhich\sreduces\sfragmentation\son\na\sVACUUM.\s\sTicket\s#2075.\s\sMore\stesting\sneeded.\s(CVS\s3643) -D 2007-02-13T15:01:11 +C Use\sOP_VColumn\sinstead\sof\sOP_Column\swhen\squerying\svirtual\stables\sfor\svalues\sto\ssave\sin\saggregate\scontext\srecords.\s#2230.\s(CVS\s3644) +D 2007-02-14T09:19:36 F Makefile.in 7fa74bf4359aa899da5586e394d17735f221315f F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -65,7 +65,7 @@ F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 F src/date.c 393c73fc027597e008dcd81454544659e978b05c F src/delete.c 151d08386bf9c9e7f92f6b9106c71efec2def184 F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b -F src/expr.c dfd25ae8f8f2ebf3d8dea605a5cea959946aabb7 +F src/expr.c a7c2369b2ba300aac4fadaf61e14c1dabaaf5d34 F src/func.c b7e1e220a6795ecae7649815145ea5f8644dfa5f F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 @@ -92,12 +92,12 @@ F src/pragma.c 5091300911670ddaa552bfa12c45cbca1bb7e7d6 F src/prepare.c 484389c6811415b8f23d259ac9c029613e1c72c3 F src/printf.c aade23a789d7cc88b397ec0d33a0a01a33a7a9c1 F src/random.c 6119474a6f6917f708c1dee25b9a8e519a620e88 -F src/select.c 63b2163f35fd2570a02dab5759979644c4405f1c +F src/select.c 05081fdfdb5f6a1397079097e02f9a76a9ce4019 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c d13ca007cd18192c07a668aeddcdd6a9fe639be9 F src/sqlite.h.in 6b7383baf76070214f6381f603328ca9b22a7fae F src/sqlite3ext.h 011c75fd6459a61454514af07c7a4f1f5c767f27 -F src/sqliteInt.h 409dfff7f08135017aa2dfb65245dfc7b1db7099 +F src/sqliteInt.h f70998732d5fc3f9517e48606faf0e2417d08014 F src/table.c 6d0da66dde26ee75614ed8f584a1996467088d06 F src/tclsqlite.c cd2b3b86ab07c0e0779f6c6e71e72c6c7dc1e704 F src/test1.c cb314bfa3e9251b545fa3669ec80a8c8a0a86310 @@ -121,7 +121,7 @@ F src/update.c bdfcf3600f129bd5f06094781ab41cd7b7f5ab25 F src/utf.c 67ecb1032bc0b42c105e88d65ef9d9f626eb0e1f F src/util.c 91d4cb189476906639ae611927d939691d1365f6 F src/vacuum.c b4569b08aaa5afb141af3f76d0315745db4e9e4b -F src/vdbe.c b5a2ad31c177b6c2d5fedb2ed180b9b57058398b +F src/vdbe.c 21bde8cca95beb4a5553c8bfbff720db0556199e F src/vdbe.h 0025259af1939fb264a545816c69e4b5b8d52691 F src/vdbeInt.h 13ba07121cf534d5b80130d2f5eb0a4937a36bba F src/vdbeapi.c 2d1e6843af8705a1172e54a418d2a3d5febd1dd7 @@ -347,7 +347,7 @@ F test/vacuum2.test 5aea8c88a65cb29f7d175296e7c819c6158d838c F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/view.test 852bd4101e6d171c46ad682eb5c5faf662b2eba4 F test/vtab1.test 03c4ad3180b78866993ef56af9d3b7c145ea4e4d -F test/vtab2.test 43763026b124e68785de05d3fbf957a4b5f81a0d +F test/vtab2.test 94bb3bf691ac10e34cf7dad46b1cf94b861d513c F test/vtab3.test f38d6d7d19f08bffdadce4d5b8cba078f8118587 F test/vtab4.test a9d7104d41a787754a734740d7aa61c807a69f87 F test/vtab5.test 9fb8f335651afe8f870011e2f68e5b00c5ad03cd @@ -432,7 +432,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 06c22de25472eba439d7f05879eb13756c4e34a8 -R 8ff634a3ba4b64ceb6f5689bb048183d -U drh -Z 882c862138cfb7c09b76716a7634fa06 +P 9f56a878cbbc715262b3a48ee696148dbd7bf1d2 +R 3bcc628e20e838b5d5987694cda2fbe9 +U danielk1977 +Z fb0e16af78c5a0c7a2b4eab04562998c diff --git a/manifest.uuid b/manifest.uuid index 0b9115aad1..733c211b51 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9f56a878cbbc715262b3a48ee696148dbd7bf1d2 \ No newline at end of file +cb78f7cb0f0bf0c799a929fd6ea30f25e2a7b5d0 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index ced48d851a..530118ba2f 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.275 2007/02/07 13:09:46 drh Exp $ +** $Id: expr.c,v 1.276 2007/02/14 09:19:36 danielk1977 Exp $ */ #include "sqliteInt.h" #include @@ -2275,6 +2275,7 @@ static int analyzeAggregate(void *pArg, Expr *pExpr){ } if( i>=pAggInfo->nColumn && (i = addAggInfoColumn(pAggInfo))>=0 ){ pCol = &pAggInfo->aCol[i]; + pCol->pTab = pExpr->pTab; pCol->iTable = pExpr->iTable; pCol->iColumn = pExpr->iColumn; pCol->iMem = pParse->nMem++; diff --git a/src/select.c b/src/select.c index 57194b9c74..4a9c6f5e95 100644 --- a/src/select.c +++ b/src/select.c @@ -12,7 +12,7 @@ ** This file contains C code routines that are called by the parser ** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.326 2007/02/01 23:02:45 drh Exp $ +** $Id: select.c,v 1.327 2007/02/14 09:19:36 danielk1977 Exp $ */ #include "sqliteInt.h" @@ -3147,7 +3147,9 @@ int sqlite3Select( if( pCol->iColumn<0 ){ sqlite3VdbeAddOp(v, OP_Rowid, pCol->iTable, 0); }else{ - sqlite3VdbeAddOp(v, OP_Column, pCol->iTable, pCol->iColumn); + Table *pTab = pCol->pTab; + int op = (pTab && IsVirtual(pTab)) ? OP_VColumn : OP_Column; + sqlite3VdbeAddOp(v, op, pCol->iTable, pCol->iColumn); } j++; } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index f638b5592e..737511ab69 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.536 2007/02/13 12:49:24 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.537 2007/02/14 09:19:36 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -922,6 +922,7 @@ struct AggInfo { ExprList *pGroupBy; /* The group by clause */ int nSortingColumn; /* Number of columns in the sorting index */ struct AggInfo_col { /* For each column used in source tables */ + Table *pTab; /* Source table */ int iTable; /* Cursor number of the source table */ int iColumn; /* Column number within the source table */ int iSorterColumn; /* Column number in the sorting index */ diff --git a/src/vdbe.c b/src/vdbe.c index ff3c8e1ca5..10856eaecb 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.588 2007/01/27 13:37:22 drh Exp $ +** $Id: vdbe.c,v 1.589 2007/02/14 09:19:37 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -1936,6 +1936,9 @@ case OP_Column: { ** which is the number of records. */ pC = p->apCsr[p1]; +#ifndef SQLITE_OMIT_VIRTUALTABLE + assert( pC->pVtabCursor==0 ); +#endif assert( pC!=0 ); if( pC->pCursor!=0 ){ /* The record is stored in a B-Tree */ diff --git a/test/vtab2.test b/test/vtab2.test index 909a273e23..641444a38c 100644 --- a/test/vtab2.test +++ b/test/vtab2.test @@ -10,7 +10,7 @@ #*********************************************************************** # This file implements regression tests for SQLite library. # -# $Id: vtab2.test,v 1.6 2006/08/13 19:04:19 drh Exp $ +# $Id: vtab2.test,v 1.7 2007/02/14 09:19:37 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl @@ -37,6 +37,24 @@ do_test vtab2-1.1 { main schema 7 pk {} 0 {} 0 \ ] +# See ticket #2230. +# +do_test vtab2-1.2 { + execsql { + SELECT length(tablename) FROM schema GROUP by tablename; + } +} {6} +do_test vtab2-1.3 { + execsql { + SELECT tablename FROM schema GROUP by length(tablename); + } +} {schema} +do_test vtab2-1.4 { + execsql { + SELECT length(tablename) FROM schema GROUP by length(tablename); + } +} {6} + register_tclvar_module [sqlite3_connection_pointer db] do_test vtab2-2.1 { set ::abc 123