| | @@ -452,11 +452,11 @@ |
| 452 | 452 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 453 | 453 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 454 | 454 | */ |
| 455 | 455 | #define SQLITE_VERSION "3.41.0" |
| 456 | 456 | #define SQLITE_VERSION_NUMBER 3041000 |
| 457 | | -#define SQLITE_SOURCE_ID "2023-01-27 07:53:49 eabb551b8b3d33fc3a327ecf7225436a3a3f616901e22c868fd76a5e3adc7b3f" |
| 457 | +#define SQLITE_SOURCE_ID "2023-02-03 14:57:40 c045d76b908a8c90d22511df7884e78d452b250db9ba70d4cb0935048a3c3ac4" |
| 458 | 458 | |
| 459 | 459 | /* |
| 460 | 460 | ** CAPI3REF: Run-Time Library Version Numbers |
| 461 | 461 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 462 | 462 | ** |
| | @@ -31543,10 +31543,17 @@ |
| 31543 | 31543 | sqlite3_str_appendf(&x, " CteUse=0x%p", pItem->u2.pCteUse); |
| 31544 | 31544 | } |
| 31545 | 31545 | if( pItem->fg.isOn || (pItem->fg.isUsing==0 && pItem->u3.pOn!=0) ){ |
| 31546 | 31546 | sqlite3_str_appendf(&x, " ON"); |
| 31547 | 31547 | } |
| 31548 | + if( pItem->fg.isTabFunc ) sqlite3_str_appendf(&x, " isTabFunc"); |
| 31549 | + if( pItem->fg.isCorrelated ) sqlite3_str_appendf(&x, " isCorrelated"); |
| 31550 | + if( pItem->fg.isMaterialized ) sqlite3_str_appendf(&x, " isMaterialized"); |
| 31551 | + if( pItem->fg.viaCoroutine ) sqlite3_str_appendf(&x, " viaCoroutine"); |
| 31552 | + if( pItem->fg.notCte ) sqlite3_str_appendf(&x, " notCte"); |
| 31553 | + if( pItem->fg.isNestedFrom ) sqlite3_str_appendf(&x, " isNestedFrom"); |
| 31554 | + |
| 31548 | 31555 | sqlite3StrAccumFinish(&x); |
| 31549 | 31556 | sqlite3TreeViewItem(pView, zLine, i<pSrc->nSrc-1); |
| 31550 | 31557 | n = 0; |
| 31551 | 31558 | if( pItem->pSelect ) n++; |
| 31552 | 31559 | if( pItem->fg.isTabFunc ) n++; |
| | @@ -38548,11 +38555,11 @@ |
| 38548 | 38555 | ** still short of its goal. The following chart shows the allowed |
| 38549 | 38556 | ** transitions and the inserted intermediate states: |
| 38550 | 38557 | ** |
| 38551 | 38558 | ** UNLOCKED -> SHARED |
| 38552 | 38559 | ** SHARED -> RESERVED |
| 38553 | | -** SHARED -> (PENDING) -> EXCLUSIVE |
| 38560 | +** SHARED -> EXCLUSIVE |
| 38554 | 38561 | ** RESERVED -> (PENDING) -> EXCLUSIVE |
| 38555 | 38562 | ** PENDING -> EXCLUSIVE |
| 38556 | 38563 | ** |
| 38557 | 38564 | ** This routine will only increase a lock. Use the sqlite3OsUnlock() |
| 38558 | 38565 | ** routine to lower a locking level. |
| | @@ -38581,23 +38588,24 @@ |
| 38581 | 38588 | ** |
| 38582 | 38589 | ** A process may only obtain a RESERVED lock after it has a SHARED lock. |
| 38583 | 38590 | ** A RESERVED lock is implemented by grabbing a write-lock on the |
| 38584 | 38591 | ** 'reserved byte'. |
| 38585 | 38592 | ** |
| 38586 | | - ** A process may only obtain a PENDING lock after it has obtained a |
| 38587 | | - ** SHARED lock. A PENDING lock is implemented by obtaining a write-lock |
| 38588 | | - ** on the 'pending byte'. This ensures that no new SHARED locks can be |
| 38589 | | - ** obtained, but existing SHARED locks are allowed to persist. A process |
| 38590 | | - ** does not have to obtain a RESERVED lock on the way to a PENDING lock. |
| 38591 | | - ** This property is used by the algorithm for rolling back a journal file |
| 38592 | | - ** after a crash. |
| 38593 | + ** An EXCLUSIVE lock may only be requested after either a SHARED or |
| 38594 | + ** RESERVED lock is held. An EXCLUSIVE lock is implemented by obtaining |
| 38595 | + ** a write-lock on the entire 'shared byte range'. Since all other locks |
| 38596 | + ** require a read-lock on one of the bytes within this range, this ensures |
| 38597 | + ** that no other locks are held on the database. |
| 38593 | 38598 | ** |
| 38594 | | - ** An EXCLUSIVE lock, obtained after a PENDING lock is held, is |
| 38595 | | - ** implemented by obtaining a write-lock on the entire 'shared byte |
| 38596 | | - ** range'. Since all other locks require a read-lock on one of the bytes |
| 38597 | | - ** within this range, this ensures that no other locks are held on the |
| 38598 | | - ** database. |
| 38599 | + ** If a process that holds a RESERVED lock requests an EXCLUSIVE, then |
| 38600 | + ** a PENDING lock is obtained first. A PENDING lock is implemented by |
| 38601 | + ** obtaining a write-lock on the 'pending byte'. This ensures that no new |
| 38602 | + ** SHARED locks can be obtained, but existing SHARED locks are allowed to |
| 38603 | + ** persist. If the call to this function fails to obtain the EXCLUSIVE |
| 38604 | + ** lock in this case, it holds the PENDING lock intead. The client may |
| 38605 | + ** then re-attempt the EXCLUSIVE lock later on, after existing SHARED |
| 38606 | + ** locks have cleared. |
| 38599 | 38607 | */ |
| 38600 | 38608 | int rc = SQLITE_OK; |
| 38601 | 38609 | unixFile *pFile = (unixFile*)id; |
| 38602 | 38610 | unixInodeInfo *pInode; |
| 38603 | 38611 | struct flock lock; |
| | @@ -38664,11 +38672,11 @@ |
| 38664 | 38672 | ** be released. |
| 38665 | 38673 | */ |
| 38666 | 38674 | lock.l_len = 1L; |
| 38667 | 38675 | lock.l_whence = SEEK_SET; |
| 38668 | 38676 | if( eFileLock==SHARED_LOCK |
| 38669 | | - || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock<PENDING_LOCK) |
| 38677 | + || (eFileLock==EXCLUSIVE_LOCK && pFile->eFileLock==RESERVED_LOCK) |
| 38670 | 38678 | ){ |
| 38671 | 38679 | lock.l_type = (eFileLock==SHARED_LOCK?F_RDLCK:F_WRLCK); |
| 38672 | 38680 | lock.l_start = PENDING_BYTE; |
| 38673 | 38681 | if( unixFileLock(pFile, &lock) ){ |
| 38674 | 38682 | tErrno = errno; |
| | @@ -38675,10 +38683,13 @@ |
| 38675 | 38683 | rc = sqliteErrorFromPosixError(tErrno, SQLITE_IOERR_LOCK); |
| 38676 | 38684 | if( rc!=SQLITE_BUSY ){ |
| 38677 | 38685 | storeLastErrno(pFile, tErrno); |
| 38678 | 38686 | } |
| 38679 | 38687 | goto end_lock; |
| 38688 | + }else if( eFileLock==EXCLUSIVE_LOCK ){ |
| 38689 | + pFile->eFileLock = PENDING_LOCK; |
| 38690 | + pInode->eFileLock = PENDING_LOCK; |
| 38680 | 38691 | } |
| 38681 | 38692 | } |
| 38682 | 38693 | |
| 38683 | 38694 | |
| 38684 | 38695 | /* If control gets to this point, then actually go ahead and make |
| | @@ -38762,17 +38773,13 @@ |
| 38762 | 38773 | pFile->dbUpdate = 0; |
| 38763 | 38774 | pFile->inNormalWrite = 1; |
| 38764 | 38775 | } |
| 38765 | 38776 | #endif |
| 38766 | 38777 | |
| 38767 | | - |
| 38768 | 38778 | if( rc==SQLITE_OK ){ |
| 38769 | 38779 | pFile->eFileLock = eFileLock; |
| 38770 | 38780 | pInode->eFileLock = eFileLock; |
| 38771 | | - }else if( eFileLock==EXCLUSIVE_LOCK ){ |
| 38772 | | - pFile->eFileLock = PENDING_LOCK; |
| 38773 | | - pInode->eFileLock = PENDING_LOCK; |
| 38774 | 38781 | } |
| 38775 | 38782 | |
| 38776 | 38783 | end_lock: |
| 38777 | 38784 | sqlite3_mutex_leave(pInode->pLockMutex); |
| 38778 | 38785 | OSTRACE(("LOCK %d %s %s (unix)\n", pFile->h, azFileLock(eFileLock), |
| | @@ -60118,11 +60125,10 @@ |
| 60118 | 60125 | int useJournal = (flags & PAGER_OMIT_JOURNAL)==0; /* False to omit journal */ |
| 60119 | 60126 | int pcacheSize = sqlite3PcacheSize(); /* Bytes to allocate for PCache */ |
| 60120 | 60127 | u32 szPageDflt = SQLITE_DEFAULT_PAGE_SIZE; /* Default page size */ |
| 60121 | 60128 | const char *zUri = 0; /* URI args to copy */ |
| 60122 | 60129 | int nUriByte = 1; /* Number of bytes of URI args at *zUri */ |
| 60123 | | - int nUri = 0; /* Number of URI parameters */ |
| 60124 | 60130 | |
| 60125 | 60131 | /* Figure out how much space is required for each journal file-handle |
| 60126 | 60132 | ** (there are two of them, the main journal and the sub-journal). */ |
| 60127 | 60133 | journalFileSize = ROUND8(sqlite3JournalSize(pVfs)); |
| 60128 | 60134 | |
| | @@ -60166,11 +60172,10 @@ |
| 60166 | 60172 | nPathname = sqlite3Strlen30(zPathname); |
| 60167 | 60173 | z = zUri = &zFilename[sqlite3Strlen30(zFilename)+1]; |
| 60168 | 60174 | while( *z ){ |
| 60169 | 60175 | z += strlen(z)+1; |
| 60170 | 60176 | z += strlen(z)+1; |
| 60171 | | - nUri++; |
| 60172 | 60177 | } |
| 60173 | 60178 | nUriByte = (int)(&z[1] - zUri); |
| 60174 | 60179 | assert( nUriByte>=1 ); |
| 60175 | 60180 | if( rc==SQLITE_OK && nPathname+8>pVfs->mxPathname ){ |
| 60176 | 60181 | /* This branch is taken when the journal path required by |
| | @@ -78786,11 +78791,13 @@ |
| 78786 | 78791 | ** entry represents the span of a cell or freeblock on a btree page. |
| 78787 | 78792 | ** The upper 16 bits are the index of the first byte of a range and the |
| 78788 | 78793 | ** lower 16 bits are the index of the last byte of that range. |
| 78789 | 78794 | */ |
| 78790 | 78795 | static void btreeHeapInsert(u32 *aHeap, u32 x){ |
| 78791 | | - u32 j, i = ++aHeap[0]; |
| 78796 | + u32 j, i; |
| 78797 | + assert( aHeap!=0 ); |
| 78798 | + i = ++aHeap[0]; |
| 78792 | 78799 | aHeap[i] = x; |
| 78793 | 78800 | while( (j = i/2)>0 && aHeap[j]>aHeap[i] ){ |
| 78794 | 78801 | x = aHeap[j]; |
| 78795 | 78802 | aHeap[j] = aHeap[i]; |
| 78796 | 78803 | aHeap[i] = x; |
| | @@ -81830,12 +81837,10 @@ |
| 81830 | 81837 | if( pVal==0 ){ |
| 81831 | 81838 | rc = SQLITE_NOMEM_BKPT; |
| 81832 | 81839 | goto value_from_function_out; |
| 81833 | 81840 | } |
| 81834 | 81841 | |
| 81835 | | - testcase( pCtx->pParse->rc==SQLITE_ERROR ); |
| 81836 | | - testcase( pCtx->pParse->rc==SQLITE_OK ); |
| 81837 | 81842 | memset(&ctx, 0, sizeof(ctx)); |
| 81838 | 81843 | ctx.pOut = pVal; |
| 81839 | 81844 | ctx.pFunc = pFunc; |
| 81840 | 81845 | ctx.enc = ENC(db); |
| 81841 | 81846 | pFunc->xSFunc(&ctx, nVal, apVal); |
| | @@ -81843,15 +81848,18 @@ |
| 81843 | 81848 | rc = ctx.isError; |
| 81844 | 81849 | sqlite3ErrorMsg(pCtx->pParse, "%s", sqlite3_value_text(pVal)); |
| 81845 | 81850 | }else{ |
| 81846 | 81851 | sqlite3ValueApplyAffinity(pVal, aff, SQLITE_UTF8); |
| 81847 | 81852 | assert( rc==SQLITE_OK ); |
| 81853 | + assert( enc==pVal->enc || db->mallocFailed ); |
| 81854 | +#if 0 /* Not reachable except after a prior failure */ |
| 81848 | 81855 | rc = sqlite3VdbeChangeEncoding(pVal, enc); |
| 81849 | 81856 | if( rc==SQLITE_OK && sqlite3VdbeMemTooBig(pVal) ){ |
| 81850 | 81857 | rc = SQLITE_TOOBIG; |
| 81851 | 81858 | pCtx->pParse->nErr++; |
| 81852 | 81859 | } |
| 81860 | +#endif |
| 81853 | 81861 | } |
| 81854 | 81862 | pCtx->pParse->rc = rc; |
| 81855 | 81863 | |
| 81856 | 81864 | value_from_function_out: |
| 81857 | 81865 | if( rc!=SQLITE_OK ){ |
| | @@ -103700,10 +103708,36 @@ |
| 103700 | 103708 | assert( (pMatch->fg.jointype & (JT_LEFT|JT_LTORJ))!=0 ); |
| 103701 | 103709 | ExprSetProperty(pNew, EP_CanBeNull); |
| 103702 | 103710 | *ppList = sqlite3ExprListAppend(pParse, *ppList, pNew); |
| 103703 | 103711 | } |
| 103704 | 103712 | } |
| 103713 | + |
| 103714 | +/* |
| 103715 | +** Return TRUE (non-zero) if zTab is a valid name for the schema table pTab. |
| 103716 | +*/ |
| 103717 | +static SQLITE_NOINLINE int isValidSchemaTableName( |
| 103718 | + const char *zTab, /* Name as it appears in the SQL */ |
| 103719 | + Table *pTab, /* The schema table we are trying to match */ |
| 103720 | + Schema *pSchema /* non-NULL if a database qualifier is present */ |
| 103721 | +){ |
| 103722 | + const char *zLegacy; |
| 103723 | + assert( pTab!=0 ); |
| 103724 | + assert( pTab->tnum==1 ); |
| 103725 | + if( sqlite3StrNICmp(zTab, "sqlite_", 7)!=0 ) return 0; |
| 103726 | + zLegacy = pTab->zName; |
| 103727 | + if( strcmp(zLegacy+7, &LEGACY_TEMP_SCHEMA_TABLE[7])==0 ){ |
| 103728 | + if( sqlite3StrICmp(zTab+7, &PREFERRED_TEMP_SCHEMA_TABLE[7])==0 ){ |
| 103729 | + return 1; |
| 103730 | + } |
| 103731 | + if( pSchema==0 ) return 0; |
| 103732 | + if( sqlite3StrICmp(zTab+7, &LEGACY_SCHEMA_TABLE[7])==0 ) return 1; |
| 103733 | + if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1; |
| 103734 | + }else{ |
| 103735 | + if( sqlite3StrICmp(zTab+7, &PREFERRED_SCHEMA_TABLE[7])==0 ) return 1; |
| 103736 | + } |
| 103737 | + return 0; |
| 103738 | +} |
| 103705 | 103739 | |
| 103706 | 103740 | /* |
| 103707 | 103741 | ** Given the name of a column of the form X.Y.Z or Y.Z or just Z, look up |
| 103708 | 103742 | ** that name in the set of source tables in pSrcList and make the pExpr |
| 103709 | 103743 | ** expression node refer back to that source column. The following changes |
| | @@ -103854,19 +103888,21 @@ |
| 103854 | 103888 | } |
| 103855 | 103889 | if( hit || zTab==0 ) continue; |
| 103856 | 103890 | } |
| 103857 | 103891 | assert( zDb==0 || zTab!=0 ); |
| 103858 | 103892 | if( zTab ){ |
| 103859 | | - const char *zTabName; |
| 103860 | 103893 | if( zDb ){ |
| 103861 | 103894 | if( pTab->pSchema!=pSchema ) continue; |
| 103862 | 103895 | if( pSchema==0 && strcmp(zDb,"*")!=0 ) continue; |
| 103863 | 103896 | } |
| 103864 | | - zTabName = pItem->zAlias ? pItem->zAlias : pTab->zName; |
| 103865 | | - assert( zTabName!=0 ); |
| 103866 | | - if( sqlite3StrICmp(zTabName, zTab)!=0 ){ |
| 103867 | | - continue; |
| 103897 | + if( pItem->zAlias!=0 ){ |
| 103898 | + if( sqlite3StrICmp(zTab, pItem->zAlias)!=0 ){ |
| 103899 | + continue; |
| 103900 | + } |
| 103901 | + }else if( sqlite3StrICmp(zTab, pTab->zName)!=0 ){ |
| 103902 | + if( pTab->tnum!=1 ) continue; |
| 103903 | + if( !isValidSchemaTableName(zTab, pTab, pSchema) ) continue; |
| 103868 | 103904 | } |
| 103869 | 103905 | assert( ExprUseYTab(pExpr) ); |
| 103870 | 103906 | if( IN_RENAME_OBJECT && pItem->zAlias ){ |
| 103871 | 103907 | sqlite3RenameTokenRemap(pParse, 0, (void*)&pExpr->y.pTab); |
| 103872 | 103908 | } |
| | @@ -116150,20 +116186,22 @@ |
| 116150 | 116186 | /* |
| 116151 | 116187 | ** If the Index.aSample variable is not NULL, delete the aSample[] array |
| 116152 | 116188 | ** and its contents. |
| 116153 | 116189 | */ |
| 116154 | 116190 | SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){ |
| 116191 | + assert( db!=0 ); |
| 116192 | + assert( pIdx!=0 ); |
| 116155 | 116193 | #ifdef SQLITE_ENABLE_STAT4 |
| 116156 | 116194 | if( pIdx->aSample ){ |
| 116157 | 116195 | int j; |
| 116158 | 116196 | for(j=0; j<pIdx->nSample; j++){ |
| 116159 | 116197 | IndexSample *p = &pIdx->aSample[j]; |
| 116160 | 116198 | sqlite3DbFree(db, p->p); |
| 116161 | 116199 | } |
| 116162 | 116200 | sqlite3DbFree(db, pIdx->aSample); |
| 116163 | 116201 | } |
| 116164 | | - if( db && db->pnBytesFreed==0 ){ |
| 116202 | + if( db->pnBytesFreed==0 ){ |
| 116165 | 116203 | pIdx->nSample = 0; |
| 116166 | 116204 | pIdx->aSample = 0; |
| 116167 | 116205 | } |
| 116168 | 116206 | #else |
| 116169 | 116207 | UNUSED_PARAMETER(db); |
| | @@ -135976,16 +136014,25 @@ |
| 135976 | 136014 | /* Fetch the right-most column from the table. This will cause |
| 135977 | 136015 | ** the entire record header to be parsed and sanity checked. It |
| 135978 | 136016 | ** will also prepopulate the cursor column cache that is used |
| 135979 | 136017 | ** by the OP_IsType code, so it is a required step. |
| 135980 | 136018 | */ |
| 135981 | | - mxCol = pTab->nCol-1; |
| 135982 | | - while( mxCol>=0 |
| 135983 | | - && ((pTab->aCol[mxCol].colFlags & COLFLAG_VIRTUAL)!=0 |
| 135984 | | - || pTab->iPKey==mxCol) ) mxCol--; |
| 136019 | + assert( !IsVirtual(pTab) ); |
| 136020 | + if( HasRowid(pTab) ){ |
| 136021 | + mxCol = -1; |
| 136022 | + for(j=0; j<pTab->nCol; j++){ |
| 136023 | + if( (pTab->aCol[j].colFlags & COLFLAG_VIRTUAL)==0 ) mxCol++; |
| 136024 | + } |
| 136025 | + if( mxCol==pTab->iPKey ) mxCol--; |
| 136026 | + }else{ |
| 136027 | + /* COLFLAG_VIRTUAL columns are not included in the WITHOUT ROWID |
| 136028 | + ** PK index column-count, so there is no need to account for them |
| 136029 | + ** in this case. */ |
| 136030 | + mxCol = sqlite3PrimaryKeyIndex(pTab)->nColumn-1; |
| 136031 | + } |
| 135985 | 136032 | if( mxCol>=0 ){ |
| 135986 | | - sqlite3ExprCodeGetColumnOfTable(v, pTab, iDataCur, mxCol, 3); |
| 136033 | + sqlite3VdbeAddOp3(v, OP_Column, iDataCur, mxCol, 3); |
| 135987 | 136034 | sqlite3VdbeTypeofColumn(v, 3); |
| 135988 | 136035 | } |
| 135989 | 136036 | |
| 135990 | 136037 | if( !isQuick ){ |
| 135991 | 136038 | if( pPk ){ |
| | @@ -143758,13 +143805,10 @@ |
| 143758 | 143805 | return 2; |
| 143759 | 143806 | } |
| 143760 | 143807 | pFrom->fg.isCte = 1; |
| 143761 | 143808 | pFrom->u2.pCteUse = pCteUse; |
| 143762 | 143809 | pCteUse->nUse++; |
| 143763 | | - if( pCteUse->nUse>=2 && pCteUse->eM10d==M10d_Any ){ |
| 143764 | | - pCteUse->eM10d = M10d_Yes; |
| 143765 | | - } |
| 143766 | 143810 | |
| 143767 | 143811 | /* Check if this is a recursive CTE. */ |
| 143768 | 143812 | pRecTerm = pSel = pFrom->pSelect; |
| 143769 | 143813 | bMayRecursive = ( pSel->op==TK_ALL || pSel->op==TK_UNION ); |
| 143770 | 143814 | while( bMayRecursive && pRecTerm->op==pSel->op ){ |
| | @@ -145043,12 +145087,14 @@ |
| 145043 | 145087 | ** (i) The subquery is the left-most subquery in the FROM clause |
| 145044 | 145088 | ** (ii) There is nothing that would prevent the subquery from |
| 145045 | 145089 | ** being used as the outer loop if the sqlite3WhereBegin() |
| 145046 | 145090 | ** routine nominates it to that position. |
| 145047 | 145091 | ** (iii) The query is not a UPDATE ... FROM |
| 145048 | | -** (2) The subquery is not a CTE that should be materialized because of |
| 145049 | | -** the AS MATERIALIZED keywords |
| 145092 | +** (2) The subquery is not a CTE that should be materialized because |
| 145093 | +** (a) the AS MATERIALIZED keyword is used, or |
| 145094 | +** (b) the CTE is used multiple times and does not have the |
| 145095 | +** NOT MATERIALIZED keyword |
| 145050 | 145096 | ** (3) The subquery is not part of a left operand for a RIGHT JOIN |
| 145051 | 145097 | ** (4) The SQLITE_Coroutine optimization disable flag is not set |
| 145052 | 145098 | ** (5) The subquery is not self-joined |
| 145053 | 145099 | */ |
| 145054 | 145100 | static int fromClauseTermCanBeCoroutine( |
| | @@ -145056,13 +145102,17 @@ |
| 145056 | 145102 | SrcList *pTabList, /* FROM clause */ |
| 145057 | 145103 | int i, /* Which term of the FROM clause holds the subquery */ |
| 145058 | 145104 | int selFlags /* Flags on the SELECT statement */ |
| 145059 | 145105 | ){ |
| 145060 | 145106 | SrcItem *pItem = &pTabList->a[i]; |
| 145061 | | - if( pItem->fg.isCte && pItem->u2.pCteUse->eM10d==M10d_Yes ) return 0;/* (2) */ |
| 145062 | | - if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */ |
| 145063 | | - if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */ |
| 145107 | + if( pItem->fg.isCte ){ |
| 145108 | + const CteUse *pCteUse = pItem->u2.pCteUse; |
| 145109 | + if( pCteUse->eM10d==M10d_Yes ) return 0; /* (2a) */ |
| 145110 | + if( pCteUse->nUse>=2 && pCteUse->eM10d!=M10d_No ) return 0; /* (2b) */ |
| 145111 | + } |
| 145112 | + if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */ |
| 145113 | + if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */ |
| 145064 | 145114 | if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){ |
| 145065 | 145115 | return 0; /* (5) */ |
| 145066 | 145116 | } |
| 145067 | 145117 | if( i==0 ){ |
| 145068 | 145118 | if( pTabList->nSrc==1 ) return 1; /* (1a) */ |
| | @@ -160345,11 +160395,12 @@ |
| 160345 | 160395 | ** indexes on subqueries and views. */ |
| 160346 | 160396 | pNew->rSetup = rLogSize + rSize; |
| 160347 | 160397 | if( !IsView(pTab) && (pTab->tabFlags & TF_Ephemeral)==0 ){ |
| 160348 | 160398 | pNew->rSetup += 28; |
| 160349 | 160399 | }else{ |
| 160350 | | - pNew->rSetup -= 10; |
| 160400 | + pNew->rSetup -= 25; /* Greatly reduced setup cost for auto indexes |
| 160401 | + ** on ephemeral materializations of views */ |
| 160351 | 160402 | } |
| 160352 | 160403 | ApplyCostMultiplier(pNew->rSetup, pTab->costMult); |
| 160353 | 160404 | if( pNew->rSetup<0 ) pNew->rSetup = 0; |
| 160354 | 160405 | /* TUNING: Each index lookup yields 20 rows in the table. This |
| 160355 | 160406 | ** is more than the usual guess of 10 rows, since we have no way |
| | @@ -164586,10 +164637,11 @@ |
| 164586 | 164637 | ** of sqlite3DbMallocRawNN() called from |
| 164587 | 164638 | ** sqlite3SrcListAppend() */ |
| 164588 | 164639 | if( p->pSrc ){ |
| 164589 | 164640 | Table *pTab2; |
| 164590 | 164641 | p->pSrc->a[0].pSelect = pSub; |
| 164642 | + p->pSrc->a[0].fg.isCorrelated = 1; |
| 164591 | 164643 | sqlite3SrcListAssignCursors(pParse, p->pSrc); |
| 164592 | 164644 | pSub->selFlags |= SF_Expanded|SF_OrderByReqd; |
| 164593 | 164645 | pTab2 = sqlite3ResultSetOfSelect(pParse, pSub, SQLITE_AFF_NONE); |
| 164594 | 164646 | pSub->selFlags |= (selFlags & SF_Aggregate); |
| 164595 | 164647 | if( pTab2==0 ){ |
| | @@ -240036,11 +240088,11 @@ |
| 240036 | 240088 | int nArg, /* Number of args */ |
| 240037 | 240089 | sqlite3_value **apUnused /* Function arguments */ |
| 240038 | 240090 | ){ |
| 240039 | 240091 | assert( nArg==0 ); |
| 240040 | 240092 | UNUSED_PARAM2(nArg, apUnused); |
| 240041 | | - sqlite3_result_text(pCtx, "fts5: 2023-01-19 18:16:09 fa10e561f5dcdb23af862c2e486e877d379f12eae077ae5fd3da6028f1c20b49", -1, SQLITE_TRANSIENT); |
| 240093 | + sqlite3_result_text(pCtx, "fts5: 2023-02-03 12:03:56 75cdaafc77b8a1efc84e71e90470994227f376e7d7de34c813e75dcadbb9f268", -1, SQLITE_TRANSIENT); |
| 240042 | 240094 | } |
| 240043 | 240095 | |
| 240044 | 240096 | /* |
| 240045 | 240097 | ** Return true if zName is the extension on one of the shadow tables used |
| 240046 | 240098 | ** by this module. |
| 240047 | 240099 | |