Allow creation of ephemeral pseudo-tables - pseudo-tables that copy a pointer to a row when inserted instead of copying the row data. (CVS 4924)

FossilOrigin-Name: 1a58a87023f7780aee813ac64dda1a80021002a7
This commit is contained in:
danielk1977 2008-03-27 17:59:01 +00:00
parent c9e8493e27
commit 9882d99993
6 changed files with 36 additions and 19 deletions

View File

@ -1,5 +1,5 @@
C Added\sthe\sspeed4p.test\sscript\sfor\stesting\sperformance\sof\sviews\sand\striggers.\s(CVS\s4923) C Allow\screation\sof\sephemeral\spseudo-tables\s-\spseudo-tables\sthat\scopy\sa\spointer\sto\sa\srow\swhen\sinserted\sinstead\sof\scopying\sthe\srow\sdata.\s(CVS\s4924)
D 2008-03-27T15:07:05 D 2008-03-27T17:59:02
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in cf434ce8ca902e69126ae0f94fc9f7dc7428a5fa F Makefile.in cf434ce8ca902e69126ae0f94fc9f7dc7428a5fa
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -135,7 +135,7 @@ F src/pragma.c 99cec6d99d0241436494aab15b05da97b0e70683
F src/prepare.c 185fb47f1fb3e45a345d523eb391d673f5eb367c F src/prepare.c 185fb47f1fb3e45a345d523eb391d673f5eb367c
F src/printf.c 05d2b44d7b5b80c8a4a09108ddad9c20e254370d F src/printf.c 05d2b44d7b5b80c8a4a09108ddad9c20e254370d
F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a F src/random.c 2b2db2de4ab491f5a14d3480466f8f4b5a5db74a
F src/select.c 5b5197016a0b751fdb78758370ba127175d3f786 F src/select.c f47faa4af940d0acd0cff92a1a77ebb27331a31a
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 22297fffa6f00a6c6d44020fa13b1184a1bb372d F src/shell.c 22297fffa6f00a6c6d44020fa13b1184a1bb372d
F src/sqlite.h.in b1ac824d9fc163a5d2226ebf5990b09a02a11117 F src/sqlite.h.in b1ac824d9fc163a5d2226ebf5990b09a02a11117
@ -174,11 +174,11 @@ F src/update.c 2aefd3c9277792e9fa2414dfe14202119fa49fe7
F src/utf.c 32b00d6e19010025e58f2ecb2f921d5e126771b4 F src/utf.c 32b00d6e19010025e58f2ecb2f921d5e126771b4
F src/util.c dba9e04121eb17ec4643d6ca231ff859452cf0e2 F src/util.c dba9e04121eb17ec4643d6ca231ff859452cf0e2
F src/vacuum.c 3524411bfb58aac0d87eadd3e5b7cd532772af30 F src/vacuum.c 3524411bfb58aac0d87eadd3e5b7cd532772af30
F src/vdbe.c 0068703495a197e7b77dbdff604b42896722a1cc F src/vdbe.c f8e6d7f96f27c273e252c475a54d485943f0bb24
F src/vdbe.h f72201a0657d5f3d6cc008d1f8d9cc65768518c9 F src/vdbe.h f72201a0657d5f3d6cc008d1f8d9cc65768518c9
F src/vdbeInt.h 2584494757e7d8e7015754d4017b36f758c2adef F src/vdbeInt.h 73a3162979585cc15d02e47cec2a1033df768246
F src/vdbeapi.c f74189e4cae0d93b2744386b9ac57f5ab60c5133 F src/vdbeapi.c f74189e4cae0d93b2744386b9ac57f5ab60c5133
F src/vdbeaux.c c77a88c97cf5836eb1f68ca6fea967569472712b F src/vdbeaux.c 0bdcfad81941f7f6b0b5f2f489d65804d4bdaf02
F src/vdbeblob.c cc713c142c3d4952b380c98ee035f850830ddbdb F src/vdbeblob.c cc713c142c3d4952b380c98ee035f850830ddbdb
F src/vdbefifo.c a30c237b2a3577e1415fb6e288cbb6b8ed1e5736 F src/vdbefifo.c a30c237b2a3577e1415fb6e288cbb6b8ed1e5736
F src/vdbemem.c d48a71d66a7afd564b6537ab7e7442f7729fa5af F src/vdbemem.c d48a71d66a7afd564b6537ab7e7442f7729fa5af
@ -619,7 +619,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 8c2f69521f13bc24cf005520efbe0589eeadd763 P adf7645f9a1e12389a7511d2adca9013b7f330fa
R 0fca44539a2917afad155100f6434a4c R c27119a978dd6220ce607704acf25a98
U drh U danielk1977
Z 074101a796f99fca1a50c6aac650887e Z 2fd91019f3a606466497fa3759b61fc9

View File

@ -1 +1 @@
adf7645f9a1e12389a7511d2adca9013b7f330fa 1a58a87023f7780aee813ac64dda1a80021002a7

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser ** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite. ** to handle SELECT statements in SQLite.
** **
** $Id: select.c,v 1.421 2008/03/26 12:50:15 drh Exp $ ** $Id: select.c,v 1.422 2008/03/27 17:59:02 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -795,7 +795,7 @@ static void generateSortTail(
if( eDest==SRT_Callback || eDest==SRT_Subroutine ){ if( eDest==SRT_Callback || eDest==SRT_Subroutine ){
pseudoTab = pParse->nTab++; pseudoTab = pParse->nTab++;
sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, nColumn); sqlite3VdbeAddOp2(v, OP_SetNumColumns, 0, nColumn);
sqlite3VdbeAddOp2(v, OP_OpenPseudo, pseudoTab, 0); sqlite3VdbeAddOp2(v, OP_OpenPseudo, pseudoTab, eDest==SRT_Callback);
} }
addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, brk); addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, brk);
codeOffset(v, p, cont); codeOffset(v, p, cont);
@ -833,6 +833,7 @@ static void generateSortTail(
sqlite3VdbeAddOp2(v, OP_Integer, 1, regRowid); sqlite3VdbeAddOp2(v, OP_Integer, 1, regRowid);
sqlite3VdbeAddOp3(v, OP_Insert, pseudoTab, regRow, regRowid); sqlite3VdbeAddOp3(v, OP_Insert, pseudoTab, regRow, regRowid);
for(i=0; i<nColumn; i++){ for(i=0; i<nColumn; i++){
assert( regRow!=pDest->iMem+i );
sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iMem+i); sqlite3VdbeAddOp3(v, OP_Column, pseudoTab, i, pDest->iMem+i);
} }
if( eDest==SRT_Callback ){ if( eDest==SRT_Callback ){

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.718 2008/03/25 17:23:33 drh Exp $ ** $Id: vdbe.c,v 1.719 2008/03/27 17:59:02 danielk1977 Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@ -2684,7 +2684,7 @@ case OP_OpenEphemeral: {
break; break;
} }
/* Opcode: OpenPseudo P1 * * * * /* Opcode: OpenPseudo P1 P2 * * *
** **
** Open a new cursor that points to a fake table that contains a single ** Open a new cursor that points to a fake table that contains a single
** row of data. Any attempt to write a second row of data causes the ** row of data. Any attempt to write a second row of data causes the
@ -2695,6 +2695,14 @@ case OP_OpenEphemeral: {
** NEW or OLD tables in a trigger. Also used to hold the a single ** NEW or OLD tables in a trigger. Also used to hold the a single
** row output from the sorter so that the row can be decomposed into ** row output from the sorter so that the row can be decomposed into
** individual columns using the OP_Column opcode. ** individual columns using the OP_Column opcode.
**
** When OP_Insert is executed to insert a row in to the pseudo table,
** the pseudo-table cursor may or may not make it's own copy of the
** original row data. If P2 is 0, then the pseudo-table will copy the
** original row data. Otherwise, a pointer to the original memory cell
** is stored. In this case, the vdbe program must ensure that the
** memory cell containing the row data is not overwritten until the
** pseudo table is closed (or a new row is inserted into it).
*/ */
case OP_OpenPseudo: { case OP_OpenPseudo: {
int i = pOp->p1; int i = pOp->p1;
@ -2704,6 +2712,7 @@ case OP_OpenPseudo: {
if( pCx==0 ) goto no_mem; if( pCx==0 ) goto no_mem;
pCx->nullRow = 1; pCx->nullRow = 1;
pCx->pseudoTable = 1; pCx->pseudoTable = 1;
pCx->ephemPseudoTable = pOp->p2;
pCx->pIncrKey = &pCx->bogusIncrKey; pCx->pIncrKey = &pCx->bogusIncrKey;
pCx->isTable = 1; pCx->isTable = 1;
pCx->isIndex = 0; pCx->isIndex = 0;
@ -3276,13 +3285,17 @@ case OP_Insert: {
assert( pData->flags & (MEM_Blob|MEM_Str) ); assert( pData->flags & (MEM_Blob|MEM_Str) );
} }
if( pC->pseudoTable ){ if( pC->pseudoTable ){
sqlite3_free(pC->pData); if( !pC->ephemPseudoTable ){
sqlite3_free(pC->pData);
}
pC->iKey = iKey; pC->iKey = iKey;
pC->nData = pData->n; pC->nData = pData->n;
if( pData->flags & MEM_Dyn ){ if( pData->flags & MEM_Dyn ){
pC->pData = pData->z; pC->pData = pData->z;
pData->flags &= ~MEM_Dyn; if( !pC->ephemPseudoTable ){
pData->flags |= MEM_Ephem; pData->flags &= ~MEM_Dyn;
pData->flags |= MEM_Ephem;
}
}else{ }else{
pC->pData = sqlite3_malloc( pC->nData+2 ); pC->pData = sqlite3_malloc( pC->nData+2 );
if( !pC->pData ) goto no_mem; if( !pC->pData ) goto no_mem;

View File

@ -65,6 +65,7 @@ struct Cursor {
Bool nullRow; /* True if pointing to a row with no data */ Bool nullRow; /* True if pointing to a row with no data */
Bool nextRowidValid; /* True if the nextRowid field is valid */ Bool nextRowidValid; /* True if the nextRowid field is valid */
Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */ Bool pseudoTable; /* This is a NEW or OLD pseudo-tables of a trigger */
Bool ephemPseudoTable;
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
Bool isTable; /* True if a table requiring integer keys */ Bool isTable; /* True if a table requiring integer keys */
Bool isIndex; /* True if an index containing keys only - no data */ Bool isIndex; /* True if an index containing keys only - no data */

View File

@ -1081,7 +1081,9 @@ void sqlite3VdbeFreeCursor(Vdbe *p, Cursor *pCx){
p->inVtabMethod = 0; p->inVtabMethod = 0;
} }
#endif #endif
sqlite3_free(pCx->pData); if( !pCx->ephemPseudoTable ){
sqlite3_free(pCx->pData);
}
memset(pCx, 0, sizeof(Cursor)); memset(pCx, 0, sizeof(Cursor));
/* sqlite3_free(pCx->aType); */ /* sqlite3_free(pCx->aType); */
/* sqlite3_free(pCx); */ /* sqlite3_free(pCx); */