Fossil SCM
Update to the version of SQLite that adds support for coroutines used to generate subqueries.
Commit
bdbe6c74b82231e2d124b91e2f1c1abc7a23a307
Parent
c7b2b2ed3ce6b25…
2 files changed
+85
-20
+1
-1
+85
-20
| --- src/sqlite3.c | ||
| +++ src/sqlite3.c | ||
| @@ -673,11 +673,11 @@ | ||
| 673 | 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | 675 | */ |
| 676 | 676 | #define SQLITE_VERSION "3.7.15" |
| 677 | 677 | #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" | |
| 679 | 679 | |
| 680 | 680 | /* |
| 681 | 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | 683 | ** |
| @@ -9868,11 +9868,11 @@ | ||
| 9868 | 9868 | int flags; /* Miscellaneous flags. See below */ |
| 9869 | 9869 | i64 lastRowid; /* ROWID of most recent insert (see above) */ |
| 9870 | 9870 | unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ |
| 9871 | 9871 | int errCode; /* Most recent error code (SQLITE_*) */ |
| 9872 | 9872 | int errMask; /* & result codes with this before returning */ |
| 9873 | - u8 dbOptFlags; /* Flags to enable/disable optimizations */ | |
| 9873 | + u16 dbOptFlags; /* Flags to enable/disable optimizations */ | |
| 9874 | 9874 | u8 autoCommit; /* The auto-commit flag. */ |
| 9875 | 9875 | u8 temp_store; /* 1: file 2: memory 0: default */ |
| 9876 | 9876 | u8 mallocFailed; /* True if we have seen a malloc failure */ |
| 9877 | 9877 | u8 dfltLockMode; /* Default locking-mode for attached dbs */ |
| 9878 | 9878 | signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ |
| @@ -10013,11 +10013,12 @@ | ||
| 10013 | 10013 | #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ |
| 10014 | 10014 | #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */ |
| 10015 | 10015 | #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ |
| 10016 | 10016 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10017 | 10017 | #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 */ | |
| 10019 | 10020 | |
| 10020 | 10021 | /* |
| 10021 | 10022 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 10022 | 10023 | */ |
| 10023 | 10024 | #ifndef SQLITE_OMIT_BUILTIN_TEST |
| @@ -10919,12 +10920,13 @@ | ||
| 10919 | 10920 | Table *pTab; /* An SQL table corresponding to zName */ |
| 10920 | 10921 | Select *pSelect; /* A SELECT statement used in place of a table name */ |
| 10921 | 10922 | int addrFillSub; /* Address of subroutine to manifest a subquery */ |
| 10922 | 10923 | int regReturn; /* Register holding return address of addrFillSub */ |
| 10923 | 10924 | 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 */ | |
| 10926 | 10928 | #ifndef SQLITE_OMIT_EXPLAIN |
| 10927 | 10929 | u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */ |
| 10928 | 10930 | #endif |
| 10929 | 10931 | int iCursor; /* The VDBE cursor number used to access this table */ |
| 10930 | 10932 | Expr *pOn; /* The ON clause of a join */ |
| @@ -11144,18 +11146,19 @@ | ||
| 11144 | 11146 | |
| 11145 | 11147 | /* |
| 11146 | 11148 | ** Allowed values for Select.selFlags. The "SF" prefix stands for |
| 11147 | 11149 | ** "Select Flag". |
| 11148 | 11150 | */ |
| 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 */ | |
| 11157 | 11160 | |
| 11158 | 11161 | |
| 11159 | 11162 | /* |
| 11160 | 11163 | ** The results of a select can be distributed in several ways. The |
| 11161 | 11164 | ** "SRT" prefix means "SELECT Result Type". |
| @@ -13098,10 +13101,11 @@ | ||
| 13098 | 13101 | Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ |
| 13099 | 13102 | Bool isTable; /* True if a table requiring integer keys */ |
| 13100 | 13103 | Bool isIndex; /* True if an index containing keys only - no data */ |
| 13101 | 13104 | Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */ |
| 13102 | 13105 | Bool isSorter; /* True if a new-style sorter */ |
| 13106 | + Bool multiPseudo; /* Multi-register pseudo-cursor */ | |
| 13103 | 13107 | sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ |
| 13104 | 13108 | const sqlite3_module *pModule; /* Module for cursor pVtabCursor */ |
| 13105 | 13109 | i64 seqCount; /* Sequence counter */ |
| 13106 | 13110 | i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ |
| 13107 | 13111 | i64 lastRowid; /* Last rowid from a Next or NextIdx operation */ |
| @@ -66065,10 +66069,15 @@ | ||
| 66065 | 66069 | VVA_ONLY(rc =) sqlite3BtreeDataSize(u.ao.pCrsr, &u.ao.payloadSize); |
| 66066 | 66070 | assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ |
| 66067 | 66071 | } |
| 66068 | 66072 | }else if( ALWAYS(u.ao.pC->pseudoTableReg>0) ){ |
| 66069 | 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 | + } | |
| 66070 | 66079 | assert( u.ao.pReg->flags & MEM_Blob ); |
| 66071 | 66080 | assert( memIsValid(u.ao.pReg) ); |
| 66072 | 66081 | u.ao.payloadSize = u.ao.pReg->n; |
| 66073 | 66082 | u.ao.zRec = u.ao.pReg->z; |
| 66074 | 66083 | u.ao.pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr; |
| @@ -67170,16 +67179,17 @@ | ||
| 67170 | 67179 | pc--; |
| 67171 | 67180 | #endif |
| 67172 | 67181 | break; |
| 67173 | 67182 | } |
| 67174 | 67183 | |
| 67175 | -/* Opcode: OpenPseudo P1 P2 P3 * * | |
| 67184 | +/* Opcode: OpenPseudo P1 P2 P3 * P5 | |
| 67176 | 67185 | ** |
| 67177 | 67186 | ** Open a new cursor that points to a fake table that contains a single |
| 67178 | 67187 | ** 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. | |
| 67181 | 67191 | ** |
| 67182 | 67192 | ** A pseudo-table created by this opcode is used to hold a single |
| 67183 | 67193 | ** row output from the sorter so that the row can be decomposed into |
| 67184 | 67194 | ** individual columns using the OP_Column opcode. The OP_Column opcode |
| 67185 | 67195 | ** is the only cursor opcode that works with a pseudo-table. |
| @@ -67197,10 +67207,11 @@ | ||
| 67197 | 67207 | if( u.bb.pCx==0 ) goto no_mem; |
| 67198 | 67208 | u.bb.pCx->nullRow = 1; |
| 67199 | 67209 | u.bb.pCx->pseudoTableReg = pOp->p2; |
| 67200 | 67210 | u.bb.pCx->isTable = 1; |
| 67201 | 67211 | u.bb.pCx->isIndex = 0; |
| 67212 | + u.bb.pCx->multiPseudo = pOp->p5; | |
| 67202 | 67213 | break; |
| 67203 | 67214 | } |
| 67204 | 67215 | |
| 67205 | 67216 | /* Opcode: Close P1 * * * * |
| 67206 | 67217 | ** |
| @@ -68185,11 +68196,11 @@ | ||
| 68185 | 68196 | #endif /* local variables moved into u.bn */ |
| 68186 | 68197 | |
| 68187 | 68198 | assert( pOp->p1>=0 && pOp->p1<p->nCursor ); |
| 68188 | 68199 | u.bn.pC = p->apCsr[pOp->p1]; |
| 68189 | 68200 | assert( u.bn.pC!=0 ); |
| 68190 | - assert( u.bn.pC->pseudoTableReg==0 ); | |
| 68201 | + assert( u.bn.pC->pseudoTableReg==0 || u.bn.pC->nullRow ); | |
| 68191 | 68202 | if( u.bn.pC->nullRow ){ |
| 68192 | 68203 | pOut->flags = MEM_Null; |
| 68193 | 68204 | break; |
| 68194 | 68205 | }else if( u.bn.pC->deferredMoveto ){ |
| 68195 | 68206 | u.bn.v = u.bn.pC->movetoTarget; |
| @@ -74553,10 +74564,11 @@ | ||
| 74553 | 74564 | pNewItem->jointype = pOldItem->jointype; |
| 74554 | 74565 | pNewItem->iCursor = pOldItem->iCursor; |
| 74555 | 74566 | pNewItem->addrFillSub = pOldItem->addrFillSub; |
| 74556 | 74567 | pNewItem->regReturn = pOldItem->regReturn; |
| 74557 | 74568 | pNewItem->isCorrelated = pOldItem->isCorrelated; |
| 74569 | + pNewItem->viaCoroutine = pOldItem->viaCoroutine; | |
| 74558 | 74570 | pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex); |
| 74559 | 74571 | pNewItem->notIndexed = pOldItem->notIndexed; |
| 74560 | 74572 | pNewItem->pIndex = pOldItem->pIndex; |
| 74561 | 74573 | pTab = pNewItem->pTab = pOldItem->pTab; |
| 74562 | 74574 | if( pTab ){ |
| @@ -84978,10 +84990,11 @@ | ||
| 84978 | 84990 | assert( pFrom->a[0].pUsing==0 ); |
| 84979 | 84991 | }else{ |
| 84980 | 84992 | sqlite3SelectDelete(db, pDup); |
| 84981 | 84993 | } |
| 84982 | 84994 | pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); |
| 84995 | + if( pDup ) pDup->selFlags |= SF_Materialize; | |
| 84983 | 84996 | } |
| 84984 | 84997 | sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); |
| 84985 | 84998 | sqlite3Select(pParse, pDup, &dest); |
| 84986 | 84999 | sqlite3SelectDelete(db, pDup); |
| 84987 | 85000 | } |
| @@ -97943,12 +97956,21 @@ | ||
| 97943 | 97956 | SelectDest dest; |
| 97944 | 97957 | Select *pSub = pItem->pSelect; |
| 97945 | 97958 | int isAggSub; |
| 97946 | 97959 | |
| 97947 | 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. */ | |
| 97948 | 97968 | 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 | + } | |
| 97950 | 97972 | continue; |
| 97951 | 97973 | } |
| 97952 | 97974 | |
| 97953 | 97975 | /* Increment Parse.nHeight by the height of the largest expression |
| 97954 | 97976 | ** tree refered to by this, the parent select. The child select |
| @@ -97965,10 +97987,39 @@ | ||
| 97965 | 97987 | if( isAggSub ){ |
| 97966 | 97988 | isAgg = 1; |
| 97967 | 97989 | p->selFlags |= SF_Aggregate; |
| 97968 | 97990 | } |
| 97969 | 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); | |
| 97970 | 98021 | }else{ |
| 97971 | 98022 | /* Generate a subroutine that will fill an ephemeral table with |
| 97972 | 98023 | ** the content of this subquery. pItem->addrFillSub will point |
| 97973 | 98024 | ** to the address of the generated subroutine. pItem->regReturn |
| 97974 | 98025 | ** is a register allocated to hold the subroutine return address |
| @@ -103965,10 +104016,14 @@ | ||
| 103965 | 104016 | if( (p->cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0 |
| 103966 | 104017 | && (p->cost.plan.wsFlags & WHERE_COVER_SCAN)==0 |
| 103967 | 104018 | ){ |
| 103968 | 104019 | /* We already have some kind of index in use for this query. */ |
| 103969 | 104020 | return; |
| 104021 | + } | |
| 104022 | + if( pSrc->viaCoroutine ){ | |
| 104023 | + /* Cannot index a co-routine */ | |
| 104024 | + return; | |
| 103970 | 104025 | } |
| 103971 | 104026 | if( pSrc->notIndexed ){ |
| 103972 | 104027 | /* The NOT INDEXED clause appears in the SQL. */ |
| 103973 | 104028 | return; |
| 103974 | 104029 | } |
| @@ -105143,11 +105198,11 @@ | ||
| 105143 | 105198 | ** the SQL statement, then this function only considers plans using the |
| 105144 | 105199 | ** named index. If no such plan is found, then the returned cost is |
| 105145 | 105200 | ** SQLITE_BIG_DBL. If a plan is found that uses the named index, |
| 105146 | 105201 | ** then the cost is calculated in the usual way. |
| 105147 | 105202 | ** |
| 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 | |
| 105149 | 105204 | ** in the SELECT statement, then no indexes are considered. However, the |
| 105150 | 105205 | ** selected plan may still take advantage of the built-in rowid primary key |
| 105151 | 105206 | ** index. |
| 105152 | 105207 | */ |
| 105153 | 105208 | static void bestBtreeIndex(WhereBestIdx *p){ |
| @@ -106170,10 +106225,20 @@ | ||
| 106170 | 106225 | if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){ |
| 106171 | 106226 | pLevel->iLeftJoin = ++pParse->nMem; |
| 106172 | 106227 | sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin); |
| 106173 | 106228 | VdbeComment((v, "init LEFT JOIN no-match flag")); |
| 106174 | 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 | |
| 106175 | 106240 | |
| 106176 | 106241 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 106177 | 106242 | if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){ |
| 106178 | 106243 | /* Case 0: The table is a virtual-table. Use the VFilter and VNext |
| 106179 | 106244 | ** to access the data. |
| @@ -115301,11 +115366,11 @@ | ||
| 115301 | 115366 | ** with various optimizations disabled to verify that the same answer |
| 115302 | 115367 | ** is obtained in every case. |
| 115303 | 115368 | */ |
| 115304 | 115369 | case SQLITE_TESTCTRL_OPTIMIZATIONS: { |
| 115305 | 115370 | sqlite3 *db = va_arg(ap, sqlite3*); |
| 115306 | - db->dbOptFlags = (u8)(va_arg(ap, int) & 0xff); | |
| 115371 | + db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff); | |
| 115307 | 115372 | break; |
| 115308 | 115373 | } |
| 115309 | 115374 | |
| 115310 | 115375 | #ifdef SQLITE_N_KEYWORD |
| 115311 | 115376 | /* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord) |
| 115312 | 115377 |
| --- 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 @@ | ||
| 107 | 107 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 108 | 108 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 109 | 109 | */ |
| 110 | 110 | #define SQLITE_VERSION "3.7.15" |
| 111 | 111 | #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" | |
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | ** CAPI3REF: Run-Time Library Version Numbers |
| 116 | 116 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 117 | 117 | ** |
| 118 | 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-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 |