Fossil SCM

Update to the version of SQLite that adds support for coroutines used to generate subqueries.

drh 2012-10-30 18:14 trunk
Commit bdbe6c74b82231e2d124b91e2f1c1abc7a23a307
2 files changed +85 -20 +1 -1
+85 -20
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673673
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674674
** [sqlite_version()] and [sqlite_source_id()].
675675
*/
676676
#define SQLITE_VERSION "3.7.15"
677677
#define SQLITE_VERSION_NUMBER 3007015
678
-#define SQLITE_SOURCE_ID "2012-10-26 19:22:45 e24ba5bee4424e99d0859ef652164ae1397a2378"
678
+#define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3"
679679
680680
/*
681681
** CAPI3REF: Run-Time Library Version Numbers
682682
** KEYWORDS: sqlite3_version, sqlite3_sourceid
683683
**
@@ -9868,11 +9868,11 @@
98689868
int flags; /* Miscellaneous flags. See below */
98699869
i64 lastRowid; /* ROWID of most recent insert (see above) */
98709870
unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
98719871
int errCode; /* Most recent error code (SQLITE_*) */
98729872
int errMask; /* & result codes with this before returning */
9873
- u8 dbOptFlags; /* Flags to enable/disable optimizations */
9873
+ u16 dbOptFlags; /* Flags to enable/disable optimizations */
98749874
u8 autoCommit; /* The auto-commit flag. */
98759875
u8 temp_store; /* 1: file 2: memory 0: default */
98769876
u8 mallocFailed; /* True if we have seen a malloc failure */
98779877
u8 dfltLockMode; /* Default locking-mode for attached dbs */
98789878
signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10013,11 +10013,12 @@
1001310013
#define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
1001410014
#define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
1001510015
#define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
1001610016
#define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
1001710017
#define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10018
-#define SQLITE_AllOpts 0x00ff /* All optimizations */
10018
+#define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10019
+#define SQLITE_AllOpts 0xffff /* All optimizations */
1001910020
1002010021
/*
1002110022
** Macros for testing whether or not optimizations are enabled or disabled.
1002210023
*/
1002310024
#ifndef SQLITE_OMIT_BUILTIN_TEST
@@ -10919,12 +10920,13 @@
1091910920
Table *pTab; /* An SQL table corresponding to zName */
1092010921
Select *pSelect; /* A SELECT statement used in place of a table name */
1092110922
int addrFillSub; /* Address of subroutine to manifest a subquery */
1092210923
int regReturn; /* Register holding return address of addrFillSub */
1092310924
u8 jointype; /* Type of join between this able and the previous */
10924
- u8 notIndexed; /* True if there is a NOT INDEXED clause */
10925
- u8 isCorrelated; /* True if sub-query is correlated */
10925
+ unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
10926
+ unsigned isCorrelated :1; /* True if sub-query is correlated */
10927
+ unsigned viaCoroutine :1; /* Implemented as a co-routine */
1092610928
#ifndef SQLITE_OMIT_EXPLAIN
1092710929
u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
1092810930
#endif
1092910931
int iCursor; /* The VDBE cursor number used to access this table */
1093010932
Expr *pOn; /* The ON clause of a join */
@@ -11144,18 +11146,19 @@
1114411146
1114511147
/*
1114611148
** Allowed values for Select.selFlags. The "SF" prefix stands for
1114711149
** "Select Flag".
1114811150
*/
11149
-#define SF_Distinct 0x01 /* Output should be DISTINCT */
11150
-#define SF_Resolved 0x02 /* Identifiers have been resolved */
11151
-#define SF_Aggregate 0x04 /* Contains aggregate functions */
11152
-#define SF_UsesEphemeral 0x08 /* Uses the OpenEphemeral opcode */
11153
-#define SF_Expanded 0x10 /* sqlite3SelectExpand() called on this */
11154
-#define SF_HasTypeInfo 0x20 /* FROM subqueries have Table metadata */
11155
-#define SF_UseSorter 0x40 /* Sort using a sorter */
11156
-#define SF_Values 0x80 /* Synthesized from VALUES clause */
11151
+#define SF_Distinct 0x0001 /* Output should be DISTINCT */
11152
+#define SF_Resolved 0x0002 /* Identifiers have been resolved */
11153
+#define SF_Aggregate 0x0004 /* Contains aggregate functions */
11154
+#define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11155
+#define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11156
+#define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11157
+#define SF_UseSorter 0x0040 /* Sort using a sorter */
11158
+#define SF_Values 0x0080 /* Synthesized from VALUES clause */
11159
+#define SF_Materialize 0x0100 /* Force materialization of views */
1115711160
1115811161
1115911162
/*
1116011163
** The results of a select can be distributed in several ways. The
1116111164
** "SRT" prefix means "SELECT Result Type".
@@ -13098,10 +13101,11 @@
1309813101
Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
1309913102
Bool isTable; /* True if a table requiring integer keys */
1310013103
Bool isIndex; /* True if an index containing keys only - no data */
1310113104
Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
1310213105
Bool isSorter; /* True if a new-style sorter */
13106
+ Bool multiPseudo; /* Multi-register pseudo-cursor */
1310313107
sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
1310413108
const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
1310513109
i64 seqCount; /* Sequence counter */
1310613110
i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
1310713111
i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
@@ -66065,10 +66069,15 @@
6606566069
VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ao.pCrsr, &u.ao.payloadSize);
6606666070
assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
6606766071
}
6606866072
}else if( ALWAYS(u.ao.pC->pseudoTableReg>0) ){
6606966073
u.ao.pReg = &aMem[u.ao.pC->pseudoTableReg];
66074
+ if( u.ao.pC->multiPseudo ){
66075
+ sqlite3VdbeMemShallowCopy(u.ao.pDest, u.ao.pReg+u.ao.p2, MEM_Ephem);
66076
+ Deephemeralize(u.ao.pDest);
66077
+ goto op_column_out;
66078
+ }
6607066079
assert( u.ao.pReg->flags & MEM_Blob );
6607166080
assert( memIsValid(u.ao.pReg) );
6607266081
u.ao.payloadSize = u.ao.pReg->n;
6607366082
u.ao.zRec = u.ao.pReg->z;
6607466083
u.ao.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
@@ -67170,16 +67179,17 @@
6717067179
pc--;
6717167180
#endif
6717267181
break;
6717367182
}
6717467183
67175
-/* Opcode: OpenPseudo P1 P2 P3 * *
67184
+/* Opcode: OpenPseudo P1 P2 P3 * P5
6717667185
**
6717767186
** Open a new cursor that points to a fake table that contains a single
6717867187
** row of data. The content of that one row in the content of memory
67179
-** register P2. In other words, cursor P1 becomes an alias for the
67180
-** MEM_Blob content contained in register P2.
67188
+** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
67189
+** MEM_Blob content contained in register P2. When P5==1, then the
67190
+** row is represented by P3 consecutive registers beginning with P2.
6718167191
**
6718267192
** A pseudo-table created by this opcode is used to hold a single
6718367193
** row output from the sorter so that the row can be decomposed into
6718467194
** individual columns using the OP_Column opcode. The OP_Column opcode
6718567195
** is the only cursor opcode that works with a pseudo-table.
@@ -67197,10 +67207,11 @@
6719767207
if( u.bb.pCx==0 ) goto no_mem;
6719867208
u.bb.pCx->nullRow = 1;
6719967209
u.bb.pCx->pseudoTableReg = pOp->p2;
6720067210
u.bb.pCx->isTable = 1;
6720167211
u.bb.pCx->isIndex = 0;
67212
+ u.bb.pCx->multiPseudo = pOp->p5;
6720267213
break;
6720367214
}
6720467215
6720567216
/* Opcode: Close P1 * * * *
6720667217
**
@@ -68185,11 +68196,11 @@
6818568196
#endif /* local variables moved into u.bn */
6818668197
6818768198
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
6818868199
u.bn.pC = p->apCsr[pOp->p1];
6818968200
assert( u.bn.pC!=0 );
68190
- assert( u.bn.pC->pseudoTableReg==0 );
68201
+ assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow );
6819168202
if( u.bn.pC->nullRow ){
6819268203
pOut->flags = MEM_Null;
6819368204
break;
6819468205
}else if( u.bn.pC->deferredMoveto ){
6819568206
u.bn.v = u.bn.pC->movetoTarget;
@@ -74553,10 +74564,11 @@
7455374564
pNewItem->jointype = pOldItem->jointype;
7455474565
pNewItem->iCursor = pOldItem->iCursor;
7455574566
pNewItem->addrFillSub = pOldItem->addrFillSub;
7455674567
pNewItem->regReturn = pOldItem->regReturn;
7455774568
pNewItem->isCorrelated = pOldItem->isCorrelated;
74569
+ pNewItem->viaCoroutine = pOldItem->viaCoroutine;
7455874570
pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
7455974571
pNewItem->notIndexed = pOldItem->notIndexed;
7456074572
pNewItem->pIndex = pOldItem->pIndex;
7456174573
pTab = pNewItem->pTab = pOldItem->pTab;
7456274574
if( pTab ){
@@ -84978,10 +84990,11 @@
8497884990
assert( pFrom->a[0].pUsing==0 );
8497984991
}else{
8498084992
sqlite3SelectDelete(db, pDup);
8498184993
}
8498284994
pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
84995
+ if( pDup ) pDup->selFlags |= SF_Materialize;
8498384996
}
8498484997
sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
8498584998
sqlite3Select(pParse, pDup, &dest);
8498684999
sqlite3SelectDelete(db, pDup);
8498785000
}
@@ -97943,12 +97956,21 @@
9794397956
SelectDest dest;
9794497957
Select *pSub = pItem->pSelect;
9794597958
int isAggSub;
9794697959
9794797960
if( pSub==0 ) continue;
97961
+
97962
+ /* Sometimes the code for a subquery will be generated more than
97963
+ ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
97964
+ ** for example. In that case, do not regenerate the code to manifest
97965
+ ** a view or the co-routine to implement a view. The first instance
97966
+ ** is sufficient, though the subroutine to manifest the view does need
97967
+ ** to be invoked again. */
9794897968
if( pItem->addrFillSub ){
97949
- sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
97969
+ if( pItem->viaCoroutine==0 ){
97970
+ sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
97971
+ }
9795097972
continue;
9795197973
}
9795297974
9795397975
/* Increment Parse.nHeight by the height of the largest expression
9795497976
** tree refered to by this, the parent select. The child select
@@ -97965,10 +97987,39 @@
9796597987
if( isAggSub ){
9796697988
isAgg = 1;
9796797989
p->selFlags |= SF_Aggregate;
9796897990
}
9796997991
i = -1;
97992
+ }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0
97993
+ && OptimizationEnabled(db, SQLITE_SubqCoroutine)
97994
+ ){
97995
+ /* Implement a co-routine that will return a single row of the result
97996
+ ** set on each invocation.
97997
+ */
97998
+ int addrTop;
97999
+ int addrEof;
98000
+ pItem->regReturn = ++pParse->nMem;
98001
+ addrEof = ++pParse->nMem;
98002
+ sqlite3VdbeAddOp0(v, OP_Goto);
98003
+ addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor);
98004
+ sqlite3VdbeChangeP5(v, 1);
98005
+ VdbeComment((v, "coroutine for %s", pItem->pTab->zName));
98006
+ pItem->addrFillSub = addrTop;
98007
+ sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof);
98008
+ sqlite3VdbeChangeP5(v, 1);
98009
+ sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
98010
+ explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
98011
+ sqlite3Select(pParse, pSub, &dest);
98012
+ pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
98013
+ pItem->viaCoroutine = 1;
98014
+ sqlite3VdbeChangeP2(v, addrTop, dest.iSdst);
98015
+ sqlite3VdbeChangeP3(v, addrTop, dest.nSdst);
98016
+ sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof);
98017
+ sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn);
98018
+ VdbeComment((v, "end %s", pItem->pTab->zName));
98019
+ sqlite3VdbeJumpHere(v, addrTop-1);
98020
+ sqlite3ClearTempRegCache(pParse);
9797098021
}else{
9797198022
/* Generate a subroutine that will fill an ephemeral table with
9797298023
** the content of this subquery. pItem->addrFillSub will point
9797398024
** to the address of the generated subroutine. pItem->regReturn
9797498025
** is a register allocated to hold the subroutine return address
@@ -103965,10 +104016,14 @@
103965104016
if( (p->cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0
103966104017
&& (p->cost.plan.wsFlags & WHERE_COVER_SCAN)==0
103967104018
){
103968104019
/* We already have some kind of index in use for this query. */
103969104020
return;
104021
+ }
104022
+ if( pSrc->viaCoroutine ){
104023
+ /* Cannot index a co-routine */
104024
+ return;
103970104025
}
103971104026
if( pSrc->notIndexed ){
103972104027
/* The NOT INDEXED clause appears in the SQL. */
103973104028
return;
103974104029
}
@@ -105143,11 +105198,11 @@
105143105198
** the SQL statement, then this function only considers plans using the
105144105199
** named index. If no such plan is found, then the returned cost is
105145105200
** SQLITE_BIG_DBL. If a plan is found that uses the named index,
105146105201
** then the cost is calculated in the usual way.
105147105202
**
105148
-** If a NOT INDEXED clause (pSrc->notIndexed!=0) was attached to the table
105203
+** If a NOT INDEXED clause was attached to the table
105149105204
** in the SELECT statement, then no indexes are considered. However, the
105150105205
** selected plan may still take advantage of the built-in rowid primary key
105151105206
** index.
105152105207
*/
105153105208
static void bestBtreeIndex(WhereBestIdx *p){
@@ -106170,10 +106225,20 @@
106170106225
if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
106171106226
pLevel->iLeftJoin = ++pParse->nMem;
106172106227
sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
106173106228
VdbeComment((v, "init LEFT JOIN no-match flag"));
106174106229
}
106230
+
106231
+ /* Special case of a FROM clause subquery implemented as a co-routine */
106232
+ if( pTabItem->viaCoroutine ){
106233
+ int regYield = pTabItem->regReturn;
106234
+ sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield);
106235
+ pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
106236
+ VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName));
106237
+ sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk);
106238
+ pLevel->op = OP_Goto;
106239
+ }else
106175106240
106176106241
#ifndef SQLITE_OMIT_VIRTUALTABLE
106177106242
if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106178106243
/* Case 0: The table is a virtual-table. Use the VFilter and VNext
106179106244
** to access the data.
@@ -115301,11 +115366,11 @@
115301115366
** with various optimizations disabled to verify that the same answer
115302115367
** is obtained in every case.
115303115368
*/
115304115369
case SQLITE_TESTCTRL_OPTIMIZATIONS: {
115305115370
sqlite3 *db = va_arg(ap, sqlite3*);
115306
- db->dbOptFlags = (u8)(va_arg(ap, int) & 0xff);
115371
+ db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
115307115372
break;
115308115373
}
115309115374
115310115375
#ifdef SQLITE_N_KEYWORD
115311115376
/* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord)
115312115377
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.15"
677 #define SQLITE_VERSION_NUMBER 3007015
678 #define SQLITE_SOURCE_ID "2012-10-26 19:22:45 e24ba5bee4424e99d0859ef652164ae1397a2378"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -9868,11 +9868,11 @@
9868 int flags; /* Miscellaneous flags. See below */
9869 i64 lastRowid; /* ROWID of most recent insert (see above) */
9870 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
9871 int errCode; /* Most recent error code (SQLITE_*) */
9872 int errMask; /* & result codes with this before returning */
9873 u8 dbOptFlags; /* Flags to enable/disable optimizations */
9874 u8 autoCommit; /* The auto-commit flag. */
9875 u8 temp_store; /* 1: file 2: memory 0: default */
9876 u8 mallocFailed; /* True if we have seen a malloc failure */
9877 u8 dfltLockMode; /* Default locking-mode for attached dbs */
9878 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10013,11 +10013,12 @@
10013 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10014 #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
10015 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10016 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10017 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10018 #define SQLITE_AllOpts 0x00ff /* All optimizations */
 
10019
10020 /*
10021 ** Macros for testing whether or not optimizations are enabled or disabled.
10022 */
10023 #ifndef SQLITE_OMIT_BUILTIN_TEST
@@ -10919,12 +10920,13 @@
10919 Table *pTab; /* An SQL table corresponding to zName */
10920 Select *pSelect; /* A SELECT statement used in place of a table name */
10921 int addrFillSub; /* Address of subroutine to manifest a subquery */
10922 int regReturn; /* Register holding return address of addrFillSub */
10923 u8 jointype; /* Type of join between this able and the previous */
10924 u8 notIndexed; /* True if there is a NOT INDEXED clause */
10925 u8 isCorrelated; /* True if sub-query is correlated */
 
10926 #ifndef SQLITE_OMIT_EXPLAIN
10927 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
10928 #endif
10929 int iCursor; /* The VDBE cursor number used to access this table */
10930 Expr *pOn; /* The ON clause of a join */
@@ -11144,18 +11146,19 @@
11144
11145 /*
11146 ** Allowed values for Select.selFlags. The "SF" prefix stands for
11147 ** "Select Flag".
11148 */
11149 #define SF_Distinct 0x01 /* Output should be DISTINCT */
11150 #define SF_Resolved 0x02 /* Identifiers have been resolved */
11151 #define SF_Aggregate 0x04 /* Contains aggregate functions */
11152 #define SF_UsesEphemeral 0x08 /* Uses the OpenEphemeral opcode */
11153 #define SF_Expanded 0x10 /* sqlite3SelectExpand() called on this */
11154 #define SF_HasTypeInfo 0x20 /* FROM subqueries have Table metadata */
11155 #define SF_UseSorter 0x40 /* Sort using a sorter */
11156 #define SF_Values 0x80 /* Synthesized from VALUES clause */
 
11157
11158
11159 /*
11160 ** The results of a select can be distributed in several ways. The
11161 ** "SRT" prefix means "SELECT Result Type".
@@ -13098,10 +13101,11 @@
13098 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13099 Bool isTable; /* True if a table requiring integer keys */
13100 Bool isIndex; /* True if an index containing keys only - no data */
13101 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
13102 Bool isSorter; /* True if a new-style sorter */
 
13103 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13104 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
13105 i64 seqCount; /* Sequence counter */
13106 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13107 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
@@ -66065,10 +66069,15 @@
66065 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ao.pCrsr, &u.ao.payloadSize);
66066 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
66067 }
66068 }else if( ALWAYS(u.ao.pC->pseudoTableReg>0) ){
66069 u.ao.pReg = &aMem[u.ao.pC->pseudoTableReg];
 
 
 
 
 
66070 assert( u.ao.pReg->flags & MEM_Blob );
66071 assert( memIsValid(u.ao.pReg) );
66072 u.ao.payloadSize = u.ao.pReg->n;
66073 u.ao.zRec = u.ao.pReg->z;
66074 u.ao.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
@@ -67170,16 +67179,17 @@
67170 pc--;
67171 #endif
67172 break;
67173 }
67174
67175 /* Opcode: OpenPseudo P1 P2 P3 * *
67176 **
67177 ** Open a new cursor that points to a fake table that contains a single
67178 ** row of data. The content of that one row in the content of memory
67179 ** register P2. In other words, cursor P1 becomes an alias for the
67180 ** MEM_Blob content contained in register P2.
 
67181 **
67182 ** A pseudo-table created by this opcode is used to hold a single
67183 ** row output from the sorter so that the row can be decomposed into
67184 ** individual columns using the OP_Column opcode. The OP_Column opcode
67185 ** is the only cursor opcode that works with a pseudo-table.
@@ -67197,10 +67207,11 @@
67197 if( u.bb.pCx==0 ) goto no_mem;
67198 u.bb.pCx->nullRow = 1;
67199 u.bb.pCx->pseudoTableReg = pOp->p2;
67200 u.bb.pCx->isTable = 1;
67201 u.bb.pCx->isIndex = 0;
 
67202 break;
67203 }
67204
67205 /* Opcode: Close P1 * * * *
67206 **
@@ -68185,11 +68196,11 @@
68185 #endif /* local variables moved into u.bn */
68186
68187 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68188 u.bn.pC = p->apCsr[pOp->p1];
68189 assert( u.bn.pC!=0 );
68190 assert( u.bn.pC->pseudoTableReg==0 );
68191 if( u.bn.pC->nullRow ){
68192 pOut->flags = MEM_Null;
68193 break;
68194 }else if( u.bn.pC->deferredMoveto ){
68195 u.bn.v = u.bn.pC->movetoTarget;
@@ -74553,10 +74564,11 @@
74553 pNewItem->jointype = pOldItem->jointype;
74554 pNewItem->iCursor = pOldItem->iCursor;
74555 pNewItem->addrFillSub = pOldItem->addrFillSub;
74556 pNewItem->regReturn = pOldItem->regReturn;
74557 pNewItem->isCorrelated = pOldItem->isCorrelated;
 
74558 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
74559 pNewItem->notIndexed = pOldItem->notIndexed;
74560 pNewItem->pIndex = pOldItem->pIndex;
74561 pTab = pNewItem->pTab = pOldItem->pTab;
74562 if( pTab ){
@@ -84978,10 +84990,11 @@
84978 assert( pFrom->a[0].pUsing==0 );
84979 }else{
84980 sqlite3SelectDelete(db, pDup);
84981 }
84982 pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
 
84983 }
84984 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
84985 sqlite3Select(pParse, pDup, &dest);
84986 sqlite3SelectDelete(db, pDup);
84987 }
@@ -97943,12 +97956,21 @@
97943 SelectDest dest;
97944 Select *pSub = pItem->pSelect;
97945 int isAggSub;
97946
97947 if( pSub==0 ) continue;
 
 
 
 
 
 
 
97948 if( pItem->addrFillSub ){
97949 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
 
 
97950 continue;
97951 }
97952
97953 /* Increment Parse.nHeight by the height of the largest expression
97954 ** tree refered to by this, the parent select. The child select
@@ -97965,10 +97987,39 @@
97965 if( isAggSub ){
97966 isAgg = 1;
97967 p->selFlags |= SF_Aggregate;
97968 }
97969 i = -1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97970 }else{
97971 /* Generate a subroutine that will fill an ephemeral table with
97972 ** the content of this subquery. pItem->addrFillSub will point
97973 ** to the address of the generated subroutine. pItem->regReturn
97974 ** is a register allocated to hold the subroutine return address
@@ -103965,10 +104016,14 @@
103965 if( (p->cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0
103966 && (p->cost.plan.wsFlags & WHERE_COVER_SCAN)==0
103967 ){
103968 /* We already have some kind of index in use for this query. */
103969 return;
 
 
 
 
103970 }
103971 if( pSrc->notIndexed ){
103972 /* The NOT INDEXED clause appears in the SQL. */
103973 return;
103974 }
@@ -105143,11 +105198,11 @@
105143 ** the SQL statement, then this function only considers plans using the
105144 ** named index. If no such plan is found, then the returned cost is
105145 ** SQLITE_BIG_DBL. If a plan is found that uses the named index,
105146 ** then the cost is calculated in the usual way.
105147 **
105148 ** If a NOT INDEXED clause (pSrc->notIndexed!=0) was attached to the table
105149 ** in the SELECT statement, then no indexes are considered. However, the
105150 ** selected plan may still take advantage of the built-in rowid primary key
105151 ** index.
105152 */
105153 static void bestBtreeIndex(WhereBestIdx *p){
@@ -106170,10 +106225,20 @@
106170 if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
106171 pLevel->iLeftJoin = ++pParse->nMem;
106172 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
106173 VdbeComment((v, "init LEFT JOIN no-match flag"));
106174 }
 
 
 
 
 
 
 
 
 
 
106175
106176 #ifndef SQLITE_OMIT_VIRTUALTABLE
106177 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106178 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
106179 ** to access the data.
@@ -115301,11 +115366,11 @@
115301 ** with various optimizations disabled to verify that the same answer
115302 ** is obtained in every case.
115303 */
115304 case SQLITE_TESTCTRL_OPTIMIZATIONS: {
115305 sqlite3 *db = va_arg(ap, sqlite3*);
115306 db->dbOptFlags = (u8)(va_arg(ap, int) & 0xff);
115307 break;
115308 }
115309
115310 #ifdef SQLITE_N_KEYWORD
115311 /* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord)
115312
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -673,11 +673,11 @@
673 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
674 ** [sqlite_version()] and [sqlite_source_id()].
675 */
676 #define SQLITE_VERSION "3.7.15"
677 #define SQLITE_VERSION_NUMBER 3007015
678 #define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3"
679
680 /*
681 ** CAPI3REF: Run-Time Library Version Numbers
682 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
683 **
@@ -9868,11 +9868,11 @@
9868 int flags; /* Miscellaneous flags. See below */
9869 i64 lastRowid; /* ROWID of most recent insert (see above) */
9870 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
9871 int errCode; /* Most recent error code (SQLITE_*) */
9872 int errMask; /* & result codes with this before returning */
9873 u16 dbOptFlags; /* Flags to enable/disable optimizations */
9874 u8 autoCommit; /* The auto-commit flag. */
9875 u8 temp_store; /* 1: file 2: memory 0: default */
9876 u8 mallocFailed; /* True if we have seen a malloc failure */
9877 u8 dfltLockMode; /* Default locking-mode for attached dbs */
9878 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */
@@ -10013,11 +10013,12 @@
10013 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */
10014 #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */
10015 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */
10016 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */
10017 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */
10018 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */
10019 #define SQLITE_AllOpts 0xffff /* All optimizations */
10020
10021 /*
10022 ** Macros for testing whether or not optimizations are enabled or disabled.
10023 */
10024 #ifndef SQLITE_OMIT_BUILTIN_TEST
@@ -10919,12 +10920,13 @@
10920 Table *pTab; /* An SQL table corresponding to zName */
10921 Select *pSelect; /* A SELECT statement used in place of a table name */
10922 int addrFillSub; /* Address of subroutine to manifest a subquery */
10923 int regReturn; /* Register holding return address of addrFillSub */
10924 u8 jointype; /* Type of join between this able and the previous */
10925 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */
10926 unsigned isCorrelated :1; /* True if sub-query is correlated */
10927 unsigned viaCoroutine :1; /* Implemented as a co-routine */
10928 #ifndef SQLITE_OMIT_EXPLAIN
10929 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */
10930 #endif
10931 int iCursor; /* The VDBE cursor number used to access this table */
10932 Expr *pOn; /* The ON clause of a join */
@@ -11144,18 +11146,19 @@
11146
11147 /*
11148 ** Allowed values for Select.selFlags. The "SF" prefix stands for
11149 ** "Select Flag".
11150 */
11151 #define SF_Distinct 0x0001 /* Output should be DISTINCT */
11152 #define SF_Resolved 0x0002 /* Identifiers have been resolved */
11153 #define SF_Aggregate 0x0004 /* Contains aggregate functions */
11154 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */
11155 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */
11156 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */
11157 #define SF_UseSorter 0x0040 /* Sort using a sorter */
11158 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11159 #define SF_Materialize 0x0100 /* Force materialization of views */
11160
11161
11162 /*
11163 ** The results of a select can be distributed in several ways. The
11164 ** "SRT" prefix means "SELECT Result Type".
@@ -13098,10 +13101,11 @@
13101 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */
13102 Bool isTable; /* True if a table requiring integer keys */
13103 Bool isIndex; /* True if an index containing keys only - no data */
13104 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */
13105 Bool isSorter; /* True if a new-style sorter */
13106 Bool multiPseudo; /* Multi-register pseudo-cursor */
13107 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */
13108 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */
13109 i64 seqCount; /* Sequence counter */
13110 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */
13111 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */
@@ -66065,10 +66069,15 @@
66069 VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ao.pCrsr, &u.ao.payloadSize);
66070 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */
66071 }
66072 }else if( ALWAYS(u.ao.pC->pseudoTableReg>0) ){
66073 u.ao.pReg = &aMem[u.ao.pC->pseudoTableReg];
66074 if( u.ao.pC->multiPseudo ){
66075 sqlite3VdbeMemShallowCopy(u.ao.pDest, u.ao.pReg+u.ao.p2, MEM_Ephem);
66076 Deephemeralize(u.ao.pDest);
66077 goto op_column_out;
66078 }
66079 assert( u.ao.pReg->flags & MEM_Blob );
66080 assert( memIsValid(u.ao.pReg) );
66081 u.ao.payloadSize = u.ao.pReg->n;
66082 u.ao.zRec = u.ao.pReg->z;
66083 u.ao.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr;
@@ -67170,16 +67179,17 @@
67179 pc--;
67180 #endif
67181 break;
67182 }
67183
67184 /* Opcode: OpenPseudo P1 P2 P3 * P5
67185 **
67186 ** Open a new cursor that points to a fake table that contains a single
67187 ** row of data. The content of that one row in the content of memory
67188 ** register P2 when P5==0. In other words, cursor P1 becomes an alias for the
67189 ** MEM_Blob content contained in register P2. When P5==1, then the
67190 ** row is represented by P3 consecutive registers beginning with P2.
67191 **
67192 ** A pseudo-table created by this opcode is used to hold a single
67193 ** row output from the sorter so that the row can be decomposed into
67194 ** individual columns using the OP_Column opcode. The OP_Column opcode
67195 ** is the only cursor opcode that works with a pseudo-table.
@@ -67197,10 +67207,11 @@
67207 if( u.bb.pCx==0 ) goto no_mem;
67208 u.bb.pCx->nullRow = 1;
67209 u.bb.pCx->pseudoTableReg = pOp->p2;
67210 u.bb.pCx->isTable = 1;
67211 u.bb.pCx->isIndex = 0;
67212 u.bb.pCx->multiPseudo = pOp->p5;
67213 break;
67214 }
67215
67216 /* Opcode: Close P1 * * * *
67217 **
@@ -68185,11 +68196,11 @@
68196 #endif /* local variables moved into u.bn */
68197
68198 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
68199 u.bn.pC = p->apCsr[pOp->p1];
68200 assert( u.bn.pC!=0 );
68201 assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow );
68202 if( u.bn.pC->nullRow ){
68203 pOut->flags = MEM_Null;
68204 break;
68205 }else if( u.bn.pC->deferredMoveto ){
68206 u.bn.v = u.bn.pC->movetoTarget;
@@ -74553,10 +74564,11 @@
74564 pNewItem->jointype = pOldItem->jointype;
74565 pNewItem->iCursor = pOldItem->iCursor;
74566 pNewItem->addrFillSub = pOldItem->addrFillSub;
74567 pNewItem->regReturn = pOldItem->regReturn;
74568 pNewItem->isCorrelated = pOldItem->isCorrelated;
74569 pNewItem->viaCoroutine = pOldItem->viaCoroutine;
74570 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex);
74571 pNewItem->notIndexed = pOldItem->notIndexed;
74572 pNewItem->pIndex = pOldItem->pIndex;
74573 pTab = pNewItem->pTab = pOldItem->pTab;
74574 if( pTab ){
@@ -84978,10 +84990,11 @@
84990 assert( pFrom->a[0].pUsing==0 );
84991 }else{
84992 sqlite3SelectDelete(db, pDup);
84993 }
84994 pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0);
84995 if( pDup ) pDup->selFlags |= SF_Materialize;
84996 }
84997 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur);
84998 sqlite3Select(pParse, pDup, &dest);
84999 sqlite3SelectDelete(db, pDup);
85000 }
@@ -97943,12 +97956,21 @@
97956 SelectDest dest;
97957 Select *pSub = pItem->pSelect;
97958 int isAggSub;
97959
97960 if( pSub==0 ) continue;
97961
97962 /* Sometimes the code for a subquery will be generated more than
97963 ** once, if the subquery is part of the WHERE clause in a LEFT JOIN,
97964 ** for example. In that case, do not regenerate the code to manifest
97965 ** a view or the co-routine to implement a view. The first instance
97966 ** is sufficient, though the subroutine to manifest the view does need
97967 ** to be invoked again. */
97968 if( pItem->addrFillSub ){
97969 if( pItem->viaCoroutine==0 ){
97970 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub);
97971 }
97972 continue;
97973 }
97974
97975 /* Increment Parse.nHeight by the height of the largest expression
97976 ** tree refered to by this, the parent select. The child select
@@ -97965,10 +97987,39 @@
97987 if( isAggSub ){
97988 isAgg = 1;
97989 p->selFlags |= SF_Aggregate;
97990 }
97991 i = -1;
97992 }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0
97993 && OptimizationEnabled(db, SQLITE_SubqCoroutine)
97994 ){
97995 /* Implement a co-routine that will return a single row of the result
97996 ** set on each invocation.
97997 */
97998 int addrTop;
97999 int addrEof;
98000 pItem->regReturn = ++pParse->nMem;
98001 addrEof = ++pParse->nMem;
98002 sqlite3VdbeAddOp0(v, OP_Goto);
98003 addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor);
98004 sqlite3VdbeChangeP5(v, 1);
98005 VdbeComment((v, "coroutine for %s", pItem->pTab->zName));
98006 pItem->addrFillSub = addrTop;
98007 sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof);
98008 sqlite3VdbeChangeP5(v, 1);
98009 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn);
98010 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId);
98011 sqlite3Select(pParse, pSub, &dest);
98012 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow;
98013 pItem->viaCoroutine = 1;
98014 sqlite3VdbeChangeP2(v, addrTop, dest.iSdst);
98015 sqlite3VdbeChangeP3(v, addrTop, dest.nSdst);
98016 sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof);
98017 sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn);
98018 VdbeComment((v, "end %s", pItem->pTab->zName));
98019 sqlite3VdbeJumpHere(v, addrTop-1);
98020 sqlite3ClearTempRegCache(pParse);
98021 }else{
98022 /* Generate a subroutine that will fill an ephemeral table with
98023 ** the content of this subquery. pItem->addrFillSub will point
98024 ** to the address of the generated subroutine. pItem->regReturn
98025 ** is a register allocated to hold the subroutine return address
@@ -103965,10 +104016,14 @@
104016 if( (p->cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0
104017 && (p->cost.plan.wsFlags & WHERE_COVER_SCAN)==0
104018 ){
104019 /* We already have some kind of index in use for this query. */
104020 return;
104021 }
104022 if( pSrc->viaCoroutine ){
104023 /* Cannot index a co-routine */
104024 return;
104025 }
104026 if( pSrc->notIndexed ){
104027 /* The NOT INDEXED clause appears in the SQL. */
104028 return;
104029 }
@@ -105143,11 +105198,11 @@
105198 ** the SQL statement, then this function only considers plans using the
105199 ** named index. If no such plan is found, then the returned cost is
105200 ** SQLITE_BIG_DBL. If a plan is found that uses the named index,
105201 ** then the cost is calculated in the usual way.
105202 **
105203 ** If a NOT INDEXED clause was attached to the table
105204 ** in the SELECT statement, then no indexes are considered. However, the
105205 ** selected plan may still take advantage of the built-in rowid primary key
105206 ** index.
105207 */
105208 static void bestBtreeIndex(WhereBestIdx *p){
@@ -106170,10 +106225,20 @@
106225 if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){
106226 pLevel->iLeftJoin = ++pParse->nMem;
106227 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin);
106228 VdbeComment((v, "init LEFT JOIN no-match flag"));
106229 }
106230
106231 /* Special case of a FROM clause subquery implemented as a co-routine */
106232 if( pTabItem->viaCoroutine ){
106233 int regYield = pTabItem->regReturn;
106234 sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield);
106235 pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield);
106236 VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName));
106237 sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk);
106238 pLevel->op = OP_Goto;
106239 }else
106240
106241 #ifndef SQLITE_OMIT_VIRTUALTABLE
106242 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
106243 /* Case 0: The table is a virtual-table. Use the VFilter and VNext
106244 ** to access the data.
@@ -115301,11 +115366,11 @@
115366 ** with various optimizations disabled to verify that the same answer
115367 ** is obtained in every case.
115368 */
115369 case SQLITE_TESTCTRL_OPTIMIZATIONS: {
115370 sqlite3 *db = va_arg(ap, sqlite3*);
115371 db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
115372 break;
115373 }
115374
115375 #ifdef SQLITE_N_KEYWORD
115376 /* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord)
115377
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.7.15"
111111
#define SQLITE_VERSION_NUMBER 3007015
112
-#define SQLITE_SOURCE_ID "2012-10-26 19:22:45 e24ba5bee4424e99d0859ef652164ae1397a2378"
112
+#define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.15"
111 #define SQLITE_VERSION_NUMBER 3007015
112 #define SQLITE_SOURCE_ID "2012-10-26 19:22:45 e24ba5bee4424e99d0859ef652164ae1397a2378"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.7.15"
111 #define SQLITE_VERSION_NUMBER 3007015
112 #define SQLITE_SOURCE_ID "2012-10-30 18:09:46 9dca18f5fea84afbecb314ee1cdfb98430656af3"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button