SQLite
Check-in [9dca18f5fe]
Not logged in
Overview
SHA1 Hash:9dca18f5fea84afbecb314ee1cdfb98430656af3
Date: 2012-10-30 18:09:46
User: drh
Comment:Enable the use of coroutines as an alternative to manifesting views used in a FROM clause.
Tags And Properties
Changes
hide diffs unified diffs patch

Changes to src/delete.c

108 pFrom->a[0].pSelect = pDup; 108 pFrom->a[0].pSelect = pDup; 109 assert( pFrom->a[0].pOn==0 ); 109 assert( pFrom->a[0].pOn==0 ); 110 assert( pFrom->a[0].pUsing==0 ); 110 assert( pFrom->a[0].pUsing==0 ); 111 }else{ 111 }else{ 112 sqlite3SelectDelete(db, pDup); 112 sqlite3SelectDelete(db, pDup); 113 } 113 } 114 pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); 114 pDup = sqlite3SelectNew(pParse, 0, pFrom, pWhere, 0, 0, 0, 0, 0, 0); > 115 if( pDup ) pDup->selFlags |= SF_Materialize; 115 } 116 } 116 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); 117 sqlite3SelectDestInit(&dest, SRT_EphemTab, iCur); 117 sqlite3Select(pParse, pDup, &dest); 118 sqlite3Select(pParse, pDup, &dest); 118 sqlite3SelectDelete(db, pDup); 119 sqlite3SelectDelete(db, pDup); 119 } 120 } 120 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ 121 #endif /* !defined(SQLITE_OMIT_VIEW) && !defined(SQLITE_OMIT_TRIGGER) */ 121 122

Changes to src/expr.c

935 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); 935 pNewItem->zName = sqlite3DbStrDup(db, pOldItem->zName); 936 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); 936 pNewItem->zAlias = sqlite3DbStrDup(db, pOldItem->zAlias); 937 pNewItem->jointype = pOldItem->jointype; 937 pNewItem->jointype = pOldItem->jointype; 938 pNewItem->iCursor = pOldItem->iCursor; 938 pNewItem->iCursor = pOldItem->iCursor; 939 pNewItem->addrFillSub = pOldItem->addrFillSub; 939 pNewItem->addrFillSub = pOldItem->addrFillSub; 940 pNewItem->regReturn = pOldItem->regReturn; 940 pNewItem->regReturn = pOldItem->regReturn; 941 pNewItem->isCorrelated = pOldItem->isCorrelated; 941 pNewItem->isCorrelated = pOldItem->isCorrelated; > 942 pNewItem->viaCoroutine = pOldItem->viaCoroutine; 942 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex); 943 pNewItem->zIndex = sqlite3DbStrDup(db, pOldItem->zIndex); 943 pNewItem->notIndexed = pOldItem->notIndexed; 944 pNewItem->notIndexed = pOldItem->notIndexed; 944 pNewItem->pIndex = pOldItem->pIndex; 945 pNewItem->pIndex = pOldItem->pIndex; 945 pTab = pNewItem->pTab = pOldItem->pTab; 946 pTab = pNewItem->pTab = pOldItem->pTab; 946 if( pTab ){ 947 if( pTab ){ 947 pTab->nRef++; 948 pTab->nRef++; 948 } 949 }

Changes to src/main.c

3015 ** operation N should be 0. The idea is that a test program (like the 3015 ** operation N should be 0. The idea is that a test program (like the 3016 ** SQL Logic Test or SLT test module) can run the same SQL multiple times 3016 ** SQL Logic Test or SLT test module) can run the same SQL multiple times 3017 ** with various optimizations disabled to verify that the same answer 3017 ** with various optimizations disabled to verify that the same answer 3018 ** is obtained in every case. 3018 ** is obtained in every case. 3019 */ 3019 */ 3020 case SQLITE_TESTCTRL_OPTIMIZATIONS: { 3020 case SQLITE_TESTCTRL_OPTIMIZATIONS: { 3021 sqlite3 *db = va_arg(ap, sqlite3*); 3021 sqlite3 *db = va_arg(ap, sqlite3*); 3022 db->dbOptFlags = (u8)(va_arg(ap, int) & 0xff); | 3022 db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff); 3023 break; 3023 break; 3024 } 3024 } 3025 3025 3026 #ifdef SQLITE_N_KEYWORD 3026 #ifdef SQLITE_N_KEYWORD 3027 /* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord) 3027 /* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord) 3028 ** 3028 ** 3029 ** If zWord is a keyword recognized by the parser, then return the 3029 ** If zWord is a keyword recognized by the parser, then return the

Changes to src/select.c

3905 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){ 3905 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){ 3906 struct SrcList_item *pItem = &pTabList->a[i]; 3906 struct SrcList_item *pItem = &pTabList->a[i]; 3907 SelectDest dest; 3907 SelectDest dest; 3908 Select *pSub = pItem->pSelect; 3908 Select *pSub = pItem->pSelect; 3909 int isAggSub; 3909 int isAggSub; 3910 3910 3911 if( pSub==0 ) continue; 3911 if( pSub==0 ) continue; > 3912 > 3913 /* Sometimes the code for a subquery will be generated more than > 3914 ** once, if the subquery is part of the WHERE clause in a LEFT JOIN, > 3915 ** for example. In that case, do not regenerate the code to manifest > 3916 ** a view or the co-routine to implement a view. The first instance > 3917 ** is sufficient, though the subroutine to manifest the view does need > 3918 ** to be invoked again. */ 3912 if( pItem->addrFillSub ){ 3919 if( pItem->addrFillSub ){ > 3920 if( pItem->viaCoroutine==0 ){ 3913 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub); | 3921 sqlite3VdbeAddOp2(v, OP_Gosub, pItem->regReturn, pItem->addrFillSub); > 3922 } 3914 continue; 3923 continue; 3915 } 3924 } 3916 3925 3917 /* Increment Parse.nHeight by the height of the largest expression 3926 /* Increment Parse.nHeight by the height of the largest expression 3918 ** tree refered to by this, the parent select. The child select 3927 ** tree refered to by this, the parent select. The child select 3919 ** may contain expression trees of at most 3928 ** may contain expression trees of at most 3920 ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit 3929 ** (SQLITE_MAX_EXPR_DEPTH-Parse.nHeight) height. This is a bit ................................................................................................................................................................................ 3927 if( flattenSubquery(pParse, p, i, isAgg, isAggSub) ){ 3936 if( flattenSubquery(pParse, p, i, isAgg, isAggSub) ){ 3928 /* This subquery can be absorbed into its parent. */ 3937 /* This subquery can be absorbed into its parent. */ 3929 if( isAggSub ){ 3938 if( isAggSub ){ 3930 isAgg = 1; 3939 isAgg = 1; 3931 p->selFlags |= SF_Aggregate; 3940 p->selFlags |= SF_Aggregate; 3932 } 3941 } 3933 i = -1; 3942 i = -1; > 3943 }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0 > 3944 && OptimizationEnabled(db, SQLITE_SubqCoroutine) > 3945 ){ > 3946 /* Implement a co-routine that will return a single row of the result > 3947 ** set on each invocation. > 3948 */ > 3949 int addrTop; > 3950 int addrEof; > 3951 pItem->regReturn = ++pParse->nMem; > 3952 addrEof = ++pParse->nMem; > 3953 sqlite3VdbeAddOp0(v, OP_Goto); > 3954 addrTop = sqlite3VdbeAddOp1(v, OP_OpenPseudo, pItem->iCursor); > 3955 sqlite3VdbeChangeP5(v, 1); > 3956 VdbeComment((v, "coroutine for %s", pItem->pTab->zName)); > 3957 pItem->addrFillSub = addrTop; > 3958 sqlite3VdbeAddOp2(v, OP_Integer, 0, addrEof); > 3959 sqlite3VdbeChangeP5(v, 1); > 3960 sqlite3SelectDestInit(&dest, SRT_Coroutine, pItem->regReturn); > 3961 explainSetInteger(pItem->iSelectId, (u8)pParse->iNextSelectId); > 3962 sqlite3Select(pParse, pSub, &dest); > 3963 pItem->pTab->nRowEst = (unsigned)pSub->nSelectRow; > 3964 pItem->viaCoroutine = 1; > 3965 sqlite3VdbeChangeP2(v, addrTop, dest.iSdst); > 3966 sqlite3VdbeChangeP3(v, addrTop, dest.nSdst); > 3967 sqlite3VdbeAddOp2(v, OP_Integer, 1, addrEof); > 3968 sqlite3VdbeAddOp1(v, OP_Yield, pItem->regReturn); > 3969 VdbeComment((v, "end %s", pItem->pTab->zName)); > 3970 sqlite3VdbeJumpHere(v, addrTop-1); > 3971 sqlite3ClearTempRegCache(pParse); 3934 }else{ 3972 }else{ 3935 /* Generate a subroutine that will fill an ephemeral table with 3973 /* Generate a subroutine that will fill an ephemeral table with 3936 ** the content of this subquery. pItem->addrFillSub will point 3974 ** the content of this subquery. pItem->addrFillSub will point 3937 ** to the address of the generated subroutine. pItem->regReturn 3975 ** to the address of the generated subroutine. pItem->regReturn 3938 ** is a register allocated to hold the subroutine return address 3976 ** is a register allocated to hold the subroutine return address 3939 */ 3977 */ 3940 int topAddr; 3978 int topAddr;

Changes to src/sqliteInt.h

823 Db *aDb; /* All backends */ 823 Db *aDb; /* All backends */ 824 int nDb; /* Number of backends currently in use */ 824 int nDb; /* Number of backends currently in use */ 825 int flags; /* Miscellaneous flags. See below */ 825 int flags; /* Miscellaneous flags. See below */ 826 i64 lastRowid; /* ROWID of most recent insert (see above) */ 826 i64 lastRowid; /* ROWID of most recent insert (see above) */ 827 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ 827 unsigned int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */ 828 int errCode; /* Most recent error code (SQLITE_*) */ 828 int errCode; /* Most recent error code (SQLITE_*) */ 829 int errMask; /* & result codes with this before returning */ 829 int errMask; /* & result codes with this before returning */ 830 u8 dbOptFlags; /* Flags to enable/disable optimizations */ | 830 u16 dbOptFlags; /* Flags to enable/disable optimizations */ 831 u8 autoCommit; /* The auto-commit flag. */ 831 u8 autoCommit; /* The auto-commit flag. */ 832 u8 temp_store; /* 1: file 2: memory 0: default */ 832 u8 temp_store; /* 1: file 2: memory 0: default */ 833 u8 mallocFailed; /* True if we have seen a malloc failure */ 833 u8 mallocFailed; /* True if we have seen a malloc failure */ 834 u8 dfltLockMode; /* Default locking-mode for attached dbs */ 834 u8 dfltLockMode; /* Default locking-mode for attached dbs */ 835 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ 835 signed char nextAutovac; /* Autovac setting after VACUUM if >=0 */ 836 u8 suppressErr; /* Do not issue error messages if true */ 836 u8 suppressErr; /* Do not issue error messages if true */ 837 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ 837 u8 vtabOnConflict; /* Value to return for s3_vtab_on_conflict() */ ................................................................................................................................................................................ 968 #define SQLITE_ColumnCache 0x0002 /* Column cache */ 968 #define SQLITE_ColumnCache 0x0002 /* Column cache */ 969 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ 969 #define SQLITE_GroupByOrder 0x0004 /* GROUPBY cover of ORDERBY */ 970 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ 970 #define SQLITE_FactorOutConst 0x0008 /* Constant factoring */ 971 #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */ 971 #define SQLITE_IdxRealAsInt 0x0010 /* Store REAL as INT in indices */ 972 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ 972 #define SQLITE_DistinctOpt 0x0020 /* DISTINCT using indexes */ 973 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ 973 #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ 974 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ 974 #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ > 975 #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ 975 #define SQLITE_AllOpts 0x00ff /* All optimizations */ | 976 #define SQLITE_AllOpts 0xffff /* All optimizations */ 976 977 977 /* 978 /* 978 ** Macros for testing whether or not optimizations are enabled or disabled. 979 ** Macros for testing whether or not optimizations are enabled or disabled. 979 */ 980 */ 980 #ifndef SQLITE_OMIT_BUILTIN_TEST 981 #ifndef SQLITE_OMIT_BUILTIN_TEST 981 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0) 982 #define OptimizationDisabled(db, mask) (((db)->dbOptFlags&(mask))!=0) 982 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0) 983 #define OptimizationEnabled(db, mask) (((db)->dbOptFlags&(mask))==0) ................................................................................................................................................................................ 1874 char *zName; /* Name of the table */ 1875 char *zName; /* Name of the table */ 1875 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1876 char *zAlias; /* The "B" part of a "A AS B" phrase. zName is the "A" */ 1876 Table *pTab; /* An SQL table corresponding to zName */ 1877 Table *pTab; /* An SQL table corresponding to zName */ 1877 Select *pSelect; /* A SELECT statement used in place of a table name */ 1878 Select *pSelect; /* A SELECT statement used in place of a table name */ 1878 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1879 int addrFillSub; /* Address of subroutine to manifest a subquery */ 1879 int regReturn; /* Register holding return address of addrFillSub */ 1880 int regReturn; /* Register holding return address of addrFillSub */ 1880 u8 jointype; /* Type of join between this able and the previous */ 1881 u8 jointype; /* Type of join between this able and the previous */ 1881 u8 notIndexed; /* True if there is a NOT INDEXED clause */ | 1882 unsigned notIndexed :1; /* True if there is a NOT INDEXED clause */ 1882 u8 isCorrelated; /* True if sub-query is correlated */ | 1883 unsigned isCorrelated :1; /* True if sub-query is correlated */ > 1884 unsigned viaCoroutine :1; /* Implemented as a co-routine */ 1883 #ifndef SQLITE_OMIT_EXPLAIN 1885 #ifndef SQLITE_OMIT_EXPLAIN 1884 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */ 1886 u8 iSelectId; /* If pSelect!=0, the id of the sub-select in EQP */ 1885 #endif 1887 #endif 1886 int iCursor; /* The VDBE cursor number used to access this table */ 1888 int iCursor; /* The VDBE cursor number used to access this table */ 1887 Expr *pOn; /* The ON clause of a join */ 1889 Expr *pOn; /* The ON clause of a join */ 1888 IdList *pUsing; /* The USING clause of a join */ 1890 IdList *pUsing; /* The USING clause of a join */ 1889 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */ 1891 Bitmask colUsed; /* Bit N (1<<N) set if column N of pTab is used */ ................................................................................................................................................................................ 2099 Expr *pOffset; /* OFFSET expression. NULL means not used. */ 2101 Expr *pOffset; /* OFFSET expression. NULL means not used. */ 2100 }; 2102 }; 2101 2103 2102 /* 2104 /* 2103 ** Allowed values for Select.selFlags. The "SF" prefix stands for 2105 ** Allowed values for Select.selFlags. The "SF" prefix stands for 2104 ** "Select Flag". 2106 ** "Select Flag". 2105 */ 2107 */ 2106 #define SF_Distinct 0x01 /* Output should be DISTINCT */ | 2108 #define SF_Distinct 0x0001 /* Output should be DISTINCT */ 2107 #define SF_Resolved 0x02 /* Identifiers have been resolved */ | 2109 #define SF_Resolved 0x0002 /* Identifiers have been resolved */ 2108 #define SF_Aggregate 0x04 /* Contains aggregate functions */ | 2110 #define SF_Aggregate 0x0004 /* Contains aggregate functions */ 2109 #define SF_UsesEphemeral 0x08 /* Uses the OpenEphemeral opcode */ | 2111 #define SF_UsesEphemeral 0x0008 /* Uses the OpenEphemeral opcode */ 2110 #define SF_Expanded 0x10 /* sqlite3SelectExpand() called on this */ | 2112 #define SF_Expanded 0x0010 /* sqlite3SelectExpand() called on this */ 2111 #define SF_HasTypeInfo 0x20 /* FROM subqueries have Table metadata */ | 2113 #define SF_HasTypeInfo 0x0020 /* FROM subqueries have Table metadata */ 2112 #define SF_UseSorter 0x40 /* Sort using a sorter */ | 2114 #define SF_UseSorter 0x0040 /* Sort using a sorter */ 2113 #define SF_Values 0x80 /* Synthesized from VALUES clause */ | 2115 #define SF_Values 0x0080 /* Synthesized from VALUES clause */ > 2116 #define SF_Materialize 0x0100 /* Force materialization of views */ 2114 2117 2115 2118 2116 /* 2119 /* 2117 ** The results of a select can be distributed in several ways. The 2120 ** The results of a select can be distributed in several ways. The 2118 ** "SRT" prefix means "SELECT Result Type". 2121 ** "SRT" prefix means "SELECT Result Type". 2119 */ 2122 */ 2120 #define SRT_Union 1 /* Store result as keys in an index */ 2123 #define SRT_Union 1 /* Store result as keys in an index */

Changes to src/vdbe.c

2233 }else{ 2233 }else{ 2234 assert( sqlite3BtreeCursorIsValid(pCrsr) ); 2234 assert( sqlite3BtreeCursorIsValid(pCrsr) ); 2235 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &payloadSize); 2235 VVA_ONLY(rc =) sqlite3BtreeDataSize(pCrsr, &payloadSize); 2236 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ 2236 assert( rc==SQLITE_OK ); /* DataSize() cannot fail */ 2237 } 2237 } 2238 }else if( ALWAYS(pC->pseudoTableReg>0) ){ 2238 }else if( ALWAYS(pC->pseudoTableReg>0) ){ 2239 pReg = &aMem[pC->pseudoTableReg]; 2239 pReg = &aMem[pC->pseudoTableReg]; > 2240 if( pC->multiPseudo ){ > 2241 sqlite3VdbeMemShallowCopy(pDest, pReg+p2, MEM_Ephem); > 2242 Deephemeralize(pDest); > 2243 goto op_column_out; > 2244 } 2240 assert( pReg->flags & MEM_Blob ); 2245 assert( pReg->flags & MEM_Blob ); 2241 assert( memIsValid(pReg) ); 2246 assert( memIsValid(pReg) ); 2242 payloadSize = pReg->n; 2247 payloadSize = pReg->n; 2243 zRec = pReg->z; 2248 zRec = pReg->z; 2244 pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr; 2249 pC->cacheStatus = (pOp->p5&OPFLAG_CLEARCACHE) ? CACHE_STALE : p->cacheCtr; 2245 assert( payloadSize==0 || zRec!=0 ); 2250 assert( payloadSize==0 || zRec!=0 ); 2246 }else{ 2251 }else{ ................................................................................................................................................................................ 3314 #else 3319 #else 3315 pOp->opcode = OP_OpenEphemeral; 3320 pOp->opcode = OP_OpenEphemeral; 3316 pc--; 3321 pc--; 3317 #endif 3322 #endif 3318 break; 3323 break; 3319 } 3324 } 3320 3325 3321 /* Opcode: OpenPseudo P1 P2 P3 * * | 3326 /* Opcode: OpenPseudo P1 P2 P3 * P5 3322 ** 3327 ** 3323 ** Open a new cursor that points to a fake table that contains a single 3328 ** Open a new cursor that points to a fake table that contains a single 3324 ** row of data. The content of that one row in the content of memory 3329 ** row of data. The content of that one row in the content of memory 3325 ** register P2. In other words, cursor P1 becomes an alias for the | 3330 ** register P2 when P5==0. In other words, cursor P1 becomes an alias for the 3326 ** MEM_Blob content contained in register P2. | 3331 ** MEM_Blob content contained in register P2. When P5==1, then the > 3332 ** row is represented by P3 consecutive registers beginning with P2. 3327 ** 3333 ** 3328 ** A pseudo-table created by this opcode is used to hold a single 3334 ** A pseudo-table created by this opcode is used to hold a single 3329 ** row output from the sorter so that the row can be decomposed into 3335 ** row output from the sorter so that the row can be decomposed into 3330 ** individual columns using the OP_Column opcode. The OP_Column opcode 3336 ** individual columns using the OP_Column opcode. The OP_Column opcode 3331 ** is the only cursor opcode that works with a pseudo-table. 3337 ** is the only cursor opcode that works with a pseudo-table. 3332 ** 3338 ** 3333 ** P3 is the number of fields in the records that will be stored by 3339 ** P3 is the number of fields in the records that will be stored by ................................................................................................................................................................................ 3339 assert( pOp->p1>=0 ); 3345 assert( pOp->p1>=0 ); 3340 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); 3346 pCx = allocateCursor(p, pOp->p1, pOp->p3, -1, 0); 3341 if( pCx==0 ) goto no_mem; 3347 if( pCx==0 ) goto no_mem; 3342 pCx->nullRow = 1; 3348 pCx->nullRow = 1; 3343 pCx->pseudoTableReg = pOp->p2; 3349 pCx->pseudoTableReg = pOp->p2; 3344 pCx->isTable = 1; 3350 pCx->isTable = 1; 3345 pCx->isIndex = 0; 3351 pCx->isIndex = 0; > 3352 pCx->multiPseudo = pOp->p5; 3346 break; 3353 break; 3347 } 3354 } 3348 3355 3349 /* Opcode: Close P1 * * * * 3356 /* Opcode: Close P1 * * * * 3350 ** 3357 ** 3351 ** Close a cursor previously opened as P1. If P1 is not 3358 ** Close a cursor previously opened as P1. If P1 is not 3352 ** currently open, this instruction is a no-op. 3359 ** currently open, this instruction is a no-op. ................................................................................................................................................................................ 4303 i64 v; 4310 i64 v; 4304 sqlite3_vtab *pVtab; 4311 sqlite3_vtab *pVtab; 4305 const sqlite3_module *pModule; 4312 const sqlite3_module *pModule; 4306 4313 4307 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 4314 assert( pOp->p1>=0 && pOp->p1<p->nCursor ); 4308 pC = p->apCsr[pOp->p1]; 4315 pC = p->apCsr[pOp->p1]; 4309 assert( pC!=0 ); 4316 assert( pC!=0 ); 4310 assert( pC->pseudoTableReg==0 ); | 4317 assert( pC->pseudoTableReg==0 || pC->nullRow ); 4311 if( pC->nullRow ){ 4318 if( pC->nullRow ){ 4312 pOut->flags = MEM_Null; 4319 pOut->flags = MEM_Null; 4313 break; 4320 break; 4314 }else if( pC->deferredMoveto ){ 4321 }else if( pC->deferredMoveto ){ 4315 v = pC->movetoTarget; 4322 v = pC->movetoTarget; 4316 #ifndef SQLITE_OMIT_VIRTUALTABLE 4323 #ifndef SQLITE_OMIT_VIRTUALTABLE 4317 }else if( pC->pVtabCursor ){ 4324 }else if( pC->pVtabCursor ){

Changes to src/vdbeInt.h

59 Bool useRandomRowid; /* Generate new record numbers semi-randomly */ 59 Bool useRandomRowid; /* Generate new record numbers semi-randomly */ 60 Bool nullRow; /* True if pointing to a row with no data */ 60 Bool nullRow; /* True if pointing to a row with no data */ 61 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ 61 Bool deferredMoveto; /* A call to sqlite3BtreeMoveto() is needed */ 62 Bool isTable; /* True if a table requiring integer keys */ 62 Bool isTable; /* True if a table requiring integer keys */ 63 Bool isIndex; /* True if an index containing keys only - no data */ 63 Bool isIndex; /* True if an index containing keys only - no data */ 64 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */ 64 Bool isOrdered; /* True if the underlying table is BTREE_UNORDERED */ 65 Bool isSorter; /* True if a new-style sorter */ 65 Bool isSorter; /* True if a new-style sorter */ > 66 Bool multiPseudo; /* Multi-register pseudo-cursor */ 66 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ 67 sqlite3_vtab_cursor *pVtabCursor; /* The cursor for a virtual table */ 67 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */ 68 const sqlite3_module *pModule; /* Module for cursor pVtabCursor */ 68 i64 seqCount; /* Sequence counter */ 69 i64 seqCount; /* Sequence counter */ 69 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ 70 i64 movetoTarget; /* Argument to the deferred sqlite3BtreeMoveto() */ 70 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */ 71 i64 lastRowid; /* Last rowid from a Next or NextIdx operation */ 71 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */ 72 VdbeSorter *pSorter; /* Sorter object for OP_SorterOpen cursors */ 72 73

Changes to src/where.c

1816 return; 1816 return; 1817 } 1817 } 1818 if( (p->cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0 1818 if( (p->cost.plan.wsFlags & WHERE_NOT_FULLSCAN)!=0 1819 && (p->cost.plan.wsFlags & WHERE_COVER_SCAN)==0 1819 && (p->cost.plan.wsFlags & WHERE_COVER_SCAN)==0 1820 ){ 1820 ){ 1821 /* We already have some kind of index in use for this query. */ 1821 /* We already have some kind of index in use for this query. */ 1822 return; 1822 return; > 1823 } > 1824 if( pSrc->viaCoroutine ){ > 1825 /* Cannot index a co-routine */ > 1826 return; 1823 } 1827 } 1824 if( pSrc->notIndexed ){ 1828 if( pSrc->notIndexed ){ 1825 /* The NOT INDEXED clause appears in the SQL. */ 1829 /* The NOT INDEXED clause appears in the SQL. */ 1826 return; 1830 return; 1827 } 1831 } 1828 if( pSrc->isCorrelated ){ 1832 if( pSrc->isCorrelated ){ 1829 /* The source is a correlated sub-query. No point in indexing it. */ 1833 /* The source is a correlated sub-query. No point in indexing it. */ ................................................................................................................................................................................ 2994 ** 2998 ** 2995 ** If there was an INDEXED BY clause (pSrc->pIndex) attached to the table in 2999 ** If there was an INDEXED BY clause (pSrc->pIndex) attached to the table in 2996 ** the SQL statement, then this function only considers plans using the 3000 ** the SQL statement, then this function only considers plans using the 2997 ** named index. If no such plan is found, then the returned cost is 3001 ** named index. If no such plan is found, then the returned cost is 2998 ** SQLITE_BIG_DBL. If a plan is found that uses the named index, 3002 ** SQLITE_BIG_DBL. If a plan is found that uses the named index, 2999 ** then the cost is calculated in the usual way. 3003 ** then the cost is calculated in the usual way. 3000 ** 3004 ** 3001 ** If a NOT INDEXED clause (pSrc->notIndexed!=0) was attached to the table | 3005 ** If a NOT INDEXED clause was attached to the table 3002 ** in the SELECT statement, then no indexes are considered. However, the 3006 ** in the SELECT statement, then no indexes are considered. However, the 3003 ** selected plan may still take advantage of the built-in rowid primary key 3007 ** selected plan may still take advantage of the built-in rowid primary key 3004 ** index. 3008 ** index. 3005 */ 3009 */ 3006 static void bestBtreeIndex(WhereBestIdx *p){ 3010 static void bestBtreeIndex(WhereBestIdx *p){ 3007 Parse *pParse = p->pParse; /* The parsing context */ 3011 Parse *pParse = p->pParse; /* The parsing context */ 3008 WhereClause *pWC = p->pWC; /* The WHERE clause */ 3012 WhereClause *pWC = p->pWC; /* The WHERE clause */ ................................................................................................................................................................................ 4021 ** row of the left table of the join. 4025 ** row of the left table of the join. 4022 */ 4026 */ 4023 if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){ 4027 if( pLevel->iFrom>0 && (pTabItem[0].jointype & JT_LEFT)!=0 ){ 4024 pLevel->iLeftJoin = ++pParse->nMem; 4028 pLevel->iLeftJoin = ++pParse->nMem; 4025 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin); 4029 sqlite3VdbeAddOp2(v, OP_Integer, 0, pLevel->iLeftJoin); 4026 VdbeComment((v, "init LEFT JOIN no-match flag")); 4030 VdbeComment((v, "init LEFT JOIN no-match flag")); 4027 } 4031 } > 4032 > 4033 /* Special case of a FROM clause subquery implemented as a co-routine */ > 4034 if( pTabItem->viaCoroutine ){ > 4035 int regYield = pTabItem->regReturn; > 4036 sqlite3VdbeAddOp2(v, OP_Integer, pTabItem->addrFillSub-1, regYield); > 4037 pLevel->p2 = sqlite3VdbeAddOp1(v, OP_Yield, regYield); > 4038 VdbeComment((v, "next row of co-routine %s", pTabItem->pTab->zName)); > 4039 sqlite3VdbeAddOp2(v, OP_If, regYield+1, addrBrk); > 4040 pLevel->op = OP_Goto; > 4041 }else 4028 4042 4029 #ifndef SQLITE_OMIT_VIRTUALTABLE 4043 #ifndef SQLITE_OMIT_VIRTUALTABLE 4030 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){ 4044 if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){ 4031 /* Case 0: The table is a virtual-table. Use the VFilter and VNext 4045 /* Case 0: The table is a virtual-table. Use the VFilter and VNext 4032 ** to access the data. 4046 ** to access the data. 4033 */ 4047 */ 4034 int iReg; /* P3 Value for OP_VFilter */ 4048 int iReg; /* P3 Value for OP_VFilter */

Changes to test/minmax.test

295 ifcapable {compound && subquery} { 295 ifcapable {compound && subquery} { 296 do_test minmax-9.1 { 296 do_test minmax-9.1 { 297 execsql { 297 execsql { 298 SELECT max(rowid) FROM ( 298 SELECT max(rowid) FROM ( 299 SELECT max(rowid) FROM t4 UNION SELECT max(rowid) FROM t5 299 SELECT max(rowid) FROM t4 UNION SELECT max(rowid) FROM t5 300 ) 300 ) 301 } 301 } 302 } {1} | 302 } {{}} 303 do_test minmax-9.2 { 303 do_test minmax-9.2 { 304 execsql { 304 execsql { 305 SELECT max(rowid) FROM ( 305 SELECT max(rowid) FROM ( 306 SELECT max(rowid) FROM t4 EXCEPT SELECT max(rowid) FROM t5 306 SELECT max(rowid) FROM t4 EXCEPT SELECT max(rowid) FROM t5 307 ) 307 ) 308 } 308 } 309 } {{}} 309 } {{}}

Changes to test/minmax2.test

285 ifcapable {compound && subquery} { 285 ifcapable {compound && subquery} { 286 do_test minmax2-9.1 { 286 do_test minmax2-9.1 { 287 execsql { 287 execsql { 288 SELECT max(rowid) FROM ( 288 SELECT max(rowid) FROM ( 289 SELECT max(rowid) FROM t4 UNION SELECT max(rowid) FROM t5 289 SELECT max(rowid) FROM t4 UNION SELECT max(rowid) FROM t5 290 ) 290 ) 291 } 291 } 292 } {1} | 292 } {{}} 293 do_test minmax2-9.2 { 293 do_test minmax2-9.2 { 294 execsql { 294 execsql { 295 SELECT max(rowid) FROM ( 295 SELECT max(rowid) FROM ( 296 SELECT max(rowid) FROM t4 EXCEPT SELECT max(rowid) FROM t5 296 SELECT max(rowid) FROM t4 EXCEPT SELECT max(rowid) FROM t5 297 ) 297 ) 298 } 298 } 299 } {{}} 299 } {{}}

Changes to test/tkt-31338dca7e.test

87 INSERT INTO t2 VALUES(10,-8); 87 INSERT INTO t2 VALUES(10,-8); 88 CREATE INDEX t1a ON t1(a); 88 CREATE INDEX t1a ON t1(a); 89 CREATE INDEX t1b ON t1(b); 89 CREATE INDEX t1b ON t1(b); 90 CREATE TABLE t3(g); 90 CREATE TABLE t3(g); 91 INSERT INTO t3 VALUES(4); 91 INSERT INTO t3 VALUES(4); 92 CREATE TABLE t4(h); 92 CREATE TABLE t4(h); 93 INSERT INTO t4 VALUES(5); 93 INSERT INTO t4 VALUES(5); 94 | 94 95 SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h 95 SELECT * FROM t3 LEFT JOIN t1 ON d=g LEFT JOIN t4 ON c=h 96 WHERE (a=1 AND h=4) 96 WHERE (a=1 AND h=4) 97 OR (b IN ( 97 OR (b IN ( 98 SELECT x FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2) 98 SELECT x FROM (SELECT e+f AS x, e FROM t2 ORDER BY 1 LIMIT 2) 99 GROUP BY e 99 GROUP BY e 100 )); 100 )); 101 } 101 }

Changes to test/tkt3527.test

48 INSERT INTO Element VALUES(1,'Elem1'); 48 INSERT INTO Element VALUES(1,'Elem1'); 49 INSERT INTO Element VALUES(2,'Elem2'); 49 INSERT INTO Element VALUES(2,'Elem2'); 50 INSERT INTO Element VALUES(3,'Elem3'); 50 INSERT INTO Element VALUES(3,'Elem3'); 51 INSERT INTO Element VALUES(4,'Elem4'); 51 INSERT INTO Element VALUES(4,'Elem4'); 52 INSERT INTO Element VALUES(5,'Elem5'); 52 INSERT INTO Element VALUES(5,'Elem5'); 53 INSERT INTO ElemOr Values(3,4); 53 INSERT INTO ElemOr Values(3,4); 54 INSERT INTO ElemOr Values(3,5); 54 INSERT INTO ElemOr Values(3,5); 55 INSERT INTO ElemAnd VALUES(1,3,1,1,1); | 55 INSERT INTO ElemAnd VALUES(1,3,'a','b','c'); 56 INSERT INTO ElemAnd VALUES(1,2,1,1,1); | 56 INSERT INTO ElemAnd VALUES(1,2,'x','y','z'); 57 57 58 CREATE VIEW ElemView1 AS 58 CREATE VIEW ElemView1 AS 59 SELECT 59 SELECT 60 CAST(Element.Code AS VARCHAR(50)) AS ElemId, 60 CAST(Element.Code AS VARCHAR(50)) AS ElemId, 61 Element.Code AS ElemCode, 61 Element.Code AS ElemCode, 62 Element.Name AS ElemName, 62 Element.Name AS ElemName, 63 ElemAnd.Code AS InnerCode, 63 ElemAnd.Code AS InnerCode, ................................................................................................................................................................................ 108 FROM ElemView1 AS Element 108 FROM ElemView1 AS Element 109 JOIN ElemView1 AS InnerElem 109 JOIN ElemView1 AS InnerElem 110 ON Element.Level=0 AND Element.InnerCode=InnerElem.ElemCode 110 ON Element.Level=0 AND Element.InnerCode=InnerElem.ElemCode 111 ORDER BY ElemId, InnerCode; 111 ORDER BY ElemId, InnerCode; 112 112 113 SELECT * FROM ElemView1; 113 SELECT * FROM ElemView1; 114 } 114 } 115 } {1 1 Elem1 2 1 1 1 0 0 1 1 Elem1 3 1 1 1 0 0 3 3 Elem3 4 {} {} {} 0 1 3 3 Elem | 115 } {1 1 Elem1 2 x y z 0 0 1 1 Elem1 3 a b c 0 0 3 3 Elem3 4 {} {} {} 0 1 3 3 Elem 116 116 117 do_test tkt3527-1.2 { 117 do_test tkt3527-1.2 { 118 db eval { 118 db eval { 119 SELECT * FROM ElemView2; 119 SELECT * FROM ElemView2; 120 } 120 } 121 } {1 1 Elem1 2 1 1 1 0 0 1 1 Elem1 3 1 1 1 0 0 1.3 3 Elem3 4 {} {} {} 1 1 1.3 3 | 121 } {1 1 Elem1 2 x y z 0 0 1 1 Elem1 3 a b c 0 0 1.3 3 Elem3 4 {} {} {} 1 1 1.3 3 122 122 123 finish_test 123 finish_test