| | @@ -670,11 +670,11 @@ |
| 670 | 670 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 671 | 671 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 672 | 672 | */ |
| 673 | 673 | #define SQLITE_VERSION "3.8.0" |
| 674 | 674 | #define SQLITE_VERSION_NUMBER 3008000 |
| 675 | | -#define SQLITE_SOURCE_ID "2013-06-26 22:46:00 93f632152e464a89322a0130adaf9f342411bf7d" |
| 675 | +#define SQLITE_SOURCE_ID "2013-06-28 23:55:45 338826ef3f8a209b14f8d42370855cab9ac9ed45" |
| 676 | 676 | |
| 677 | 677 | /* |
| 678 | 678 | ** CAPI3REF: Run-Time Library Version Numbers |
| 679 | 679 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 680 | 680 | ** |
| | @@ -1041,10 +1041,11 @@ |
| 1041 | 1041 | #define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8)) |
| 1042 | 1042 | #define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8)) |
| 1043 | 1043 | #define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8)) |
| 1044 | 1044 | #define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8)) |
| 1045 | 1045 | #define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8)) |
| 1046 | +#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8)) |
| 1046 | 1047 | #define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8)) |
| 1047 | 1048 | #define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8)) |
| 1048 | 1049 | #define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8)) |
| 1049 | 1050 | #define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8)) |
| 1050 | 1051 | #define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8)) |
| | @@ -1060,10 +1061,11 @@ |
| 1060 | 1061 | #define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8)) |
| 1061 | 1062 | #define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8)) |
| 1062 | 1063 | #define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8)) |
| 1063 | 1064 | #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8)) |
| 1064 | 1065 | #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8)) |
| 1066 | +#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8)) |
| 1065 | 1067 | |
| 1066 | 1068 | /* |
| 1067 | 1069 | ** CAPI3REF: Flags For File Open Operations |
| 1068 | 1070 | ** |
| 1069 | 1071 | ** These bit values are intended for use in the |
| | @@ -10076,13 +10078,14 @@ |
| 10076 | 10078 | int newTnum; /* Rootpage of table being initialized */ |
| 10077 | 10079 | u8 iDb; /* Which db file is being initialized */ |
| 10078 | 10080 | u8 busy; /* TRUE if currently initializing */ |
| 10079 | 10081 | u8 orphanTrigger; /* Last statement is orphaned TEMP trigger */ |
| 10080 | 10082 | } init; |
| 10081 | | - int activeVdbeCnt; /* Number of VDBEs currently executing */ |
| 10082 | | - int writeVdbeCnt; /* Number of active VDBEs that are writing */ |
| 10083 | | - int vdbeExecCnt; /* Number of nested calls to VdbeExec() */ |
| 10083 | + int nVdbeActive; /* Number of VDBEs currently running */ |
| 10084 | + int nVdbeRead; /* Number of active VDBEs that read or write */ |
| 10085 | + int nVdbeWrite; /* Number of active VDBEs that read and write */ |
| 10086 | + int nVdbeExec; /* Number of nested calls to VdbeExec() */ |
| 10084 | 10087 | int nExtension; /* Number of loaded extensions */ |
| 10085 | 10088 | void **aExtension; /* Array of shared library handles */ |
| 10086 | 10089 | void (*xTrace)(void*,const char*); /* Trace function */ |
| 10087 | 10090 | void *pTraceArg; /* Argument to the trace function */ |
| 10088 | 10091 | void (*xProfile)(void*,const char*,u64); /* Profiling function */ |
| | @@ -10204,10 +10207,11 @@ |
| 10204 | 10207 | #define SQLITE_CoverIdxScan 0x0040 /* Covering index scans */ |
| 10205 | 10208 | #define SQLITE_OrderByIdxJoin 0x0080 /* ORDER BY of joins via index */ |
| 10206 | 10209 | #define SQLITE_SubqCoroutine 0x0100 /* Evaluate subqueries as coroutines */ |
| 10207 | 10210 | #define SQLITE_Transitive 0x0200 /* Transitive constraints */ |
| 10208 | 10211 | #define SQLITE_OmitNoopJoin 0x0400 /* Omit unused tables in joins */ |
| 10212 | +#define SQLITE_Stat3 0x0800 /* Use the SQLITE_STAT3 table */ |
| 10209 | 10213 | #define SQLITE_AllOpts 0xffff /* All optimizations */ |
| 10210 | 10214 | |
| 10211 | 10215 | /* |
| 10212 | 10216 | ** Macros for testing whether or not optimizations are enabled or disabled. |
| 10213 | 10217 | */ |
| | @@ -13512,11 +13516,12 @@ |
| 13512 | 13516 | bft inVtabMethod:2; /* See comments above */ |
| 13513 | 13517 | bft changeCntOn:1; /* True to update the change-counter */ |
| 13514 | 13518 | bft expired:1; /* True if the VM needs to be recompiled */ |
| 13515 | 13519 | bft runOnlyOnce:1; /* Automatically expire on reset */ |
| 13516 | 13520 | bft usesStmtJournal:1; /* True if uses a statement journal */ |
| 13517 | | - bft readOnly:1; /* True for read-only statements */ |
| 13521 | + bft readOnly:1; /* True for statements that do not write */ |
| 13522 | + bft bIsReader:1; /* True for statements that read */ |
| 13518 | 13523 | bft isPrepareV2:1; /* True if prepared with prepare_v2() */ |
| 13519 | 13524 | bft doingRerun:1; /* True if rerunning after an auto-reprepare */ |
| 13520 | 13525 | int nChange; /* Number of db changes made since last reset */ |
| 13521 | 13526 | yDbMask btreeMask; /* Bitmask of db->aDb[] entries referenced */ |
| 13522 | 13527 | yDbMask lockMask; /* Subset of btreeMask that requires a lock */ |
| | @@ -47891,11 +47896,11 @@ |
| 47891 | 47896 | ** the write is disallowed. |
| 47892 | 47897 | */ |
| 47893 | 47898 | if( memcmp(&pWal->hdr, (void *)walIndexHdr(pWal), sizeof(WalIndexHdr))!=0 ){ |
| 47894 | 47899 | walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1); |
| 47895 | 47900 | pWal->writeLock = 0; |
| 47896 | | - rc = SQLITE_BUSY; |
| 47901 | + rc = SQLITE_BUSY_SNAPSHOT; |
| 47897 | 47902 | } |
| 47898 | 47903 | |
| 47899 | 47904 | return rc; |
| 47900 | 47905 | } |
| 47901 | 47906 | |
| | @@ -52751,16 +52756,17 @@ |
| 52751 | 52756 | ** This function is called from both BtreeCommitPhaseTwo() and BtreeRollback() |
| 52752 | 52757 | ** at the conclusion of a transaction. |
| 52753 | 52758 | */ |
| 52754 | 52759 | static void btreeEndTransaction(Btree *p){ |
| 52755 | 52760 | BtShared *pBt = p->pBt; |
| 52761 | + sqlite3 *db = p->db; |
| 52756 | 52762 | assert( sqlite3BtreeHoldsMutex(p) ); |
| 52757 | 52763 | |
| 52758 | 52764 | #ifndef SQLITE_OMIT_AUTOVACUUM |
| 52759 | 52765 | pBt->bDoTruncate = 0; |
| 52760 | 52766 | #endif |
| 52761 | | - if( p->inTrans>TRANS_NONE && p->db->activeVdbeCnt>1 ){ |
| 52767 | + if( p->inTrans>TRANS_NONE && db->nVdbeRead>1 ){ |
| 52762 | 52768 | /* If there are other active statements that belong to this database |
| 52763 | 52769 | ** handle, downgrade to a read-only transaction. The other statements |
| 52764 | 52770 | ** may still be reading from the database. */ |
| 52765 | 52771 | downgradeAllSharedCacheTableLocks(p); |
| 52766 | 52772 | p->inTrans = TRANS_READ; |
| | @@ -60277,18 +60283,30 @@ |
| 60277 | 60283 | int i; |
| 60278 | 60284 | int nMaxArgs = *pMaxFuncArgs; |
| 60279 | 60285 | Op *pOp; |
| 60280 | 60286 | int *aLabel = p->aLabel; |
| 60281 | 60287 | p->readOnly = 1; |
| 60288 | + p->bIsReader = 0; |
| 60282 | 60289 | for(pOp=p->aOp, i=p->nOp-1; i>=0; i--, pOp++){ |
| 60283 | 60290 | u8 opcode = pOp->opcode; |
| 60284 | 60291 | |
| 60285 | 60292 | pOp->opflags = sqlite3OpcodeProperty[opcode]; |
| 60286 | 60293 | if( opcode==OP_Function || opcode==OP_AggStep ){ |
| 60287 | 60294 | if( pOp->p5>nMaxArgs ) nMaxArgs = pOp->p5; |
| 60288 | | - }else if( (opcode==OP_Transaction && pOp->p2!=0) || opcode==OP_Vacuum ){ |
| 60295 | + }else if( opcode==OP_Transaction ){ |
| 60296 | + if( pOp->p2!=0 ) p->readOnly = 0; |
| 60297 | + p->bIsReader = 1; |
| 60298 | + }else if( opcode==OP_AutoCommit || opcode==OP_Savepoint ){ |
| 60299 | + p->bIsReader = 1; |
| 60300 | + }else if( opcode==OP_Vacuum |
| 60301 | + || opcode==OP_JournalMode |
| 60302 | +#ifndef SQLITE_OMIT_VIRTUALTABLE |
| 60303 | + || opcode==OP_Checkpoint |
| 60304 | +#endif |
| 60305 | + ){ |
| 60289 | 60306 | p->readOnly = 0; |
| 60307 | + p->bIsReader = 1; |
| 60290 | 60308 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 60291 | 60309 | }else if( opcode==OP_VUpdate ){ |
| 60292 | 60310 | if( pOp->p2>nMaxArgs ) nMaxArgs = pOp->p2; |
| 60293 | 60311 | }else if( opcode==OP_VFilter ){ |
| 60294 | 60312 | int n; |
| | @@ -60310,12 +60328,12 @@ |
| 60310 | 60328 | pOp->p2 = aLabel[-1-pOp->p2]; |
| 60311 | 60329 | } |
| 60312 | 60330 | } |
| 60313 | 60331 | sqlite3DbFree(p->db, p->aLabel); |
| 60314 | 60332 | p->aLabel = 0; |
| 60315 | | - |
| 60316 | 60333 | *pMaxFuncArgs = nMaxArgs; |
| 60334 | + assert( p->bIsReader!=0 || p->btreeMask==0 ); |
| 60317 | 60335 | } |
| 60318 | 60336 | |
| 60319 | 60337 | /* |
| 60320 | 60338 | ** Return the address of the next instruction to be inserted. |
| 60321 | 60339 | */ |
| | @@ -61837,11 +61855,11 @@ |
| 61837 | 61855 | |
| 61838 | 61856 | return rc; |
| 61839 | 61857 | } |
| 61840 | 61858 | |
| 61841 | 61859 | /* |
| 61842 | | -** This routine checks that the sqlite3.activeVdbeCnt count variable |
| 61860 | +** This routine checks that the sqlite3.nVdbeActive count variable |
| 61843 | 61861 | ** matches the number of vdbe's in the list sqlite3.pVdbe that are |
| 61844 | 61862 | ** currently active. An assertion fails if the two counts do not match. |
| 61845 | 61863 | ** This is an internal self-check only - it is not an essential processing |
| 61846 | 61864 | ** step. |
| 61847 | 61865 | ** |
| | @@ -61850,20 +61868,23 @@ |
| 61850 | 61868 | #ifndef NDEBUG |
| 61851 | 61869 | static void checkActiveVdbeCnt(sqlite3 *db){ |
| 61852 | 61870 | Vdbe *p; |
| 61853 | 61871 | int cnt = 0; |
| 61854 | 61872 | int nWrite = 0; |
| 61873 | + int nRead = 0; |
| 61855 | 61874 | p = db->pVdbe; |
| 61856 | 61875 | while( p ){ |
| 61857 | 61876 | if( p->magic==VDBE_MAGIC_RUN && p->pc>=0 ){ |
| 61858 | 61877 | cnt++; |
| 61859 | 61878 | if( p->readOnly==0 ) nWrite++; |
| 61879 | + if( p->bIsReader ) nRead++; |
| 61860 | 61880 | } |
| 61861 | 61881 | p = p->pNext; |
| 61862 | 61882 | } |
| 61863 | | - assert( cnt==db->activeVdbeCnt ); |
| 61864 | | - assert( nWrite==db->writeVdbeCnt ); |
| 61883 | + assert( cnt==db->nVdbeActive ); |
| 61884 | + assert( nWrite==db->nVdbeWrite ); |
| 61885 | + assert( nRead==db->nVdbeRead ); |
| 61865 | 61886 | } |
| 61866 | 61887 | #else |
| 61867 | 61888 | #define checkActiveVdbeCnt(x) |
| 61868 | 61889 | #endif |
| 61869 | 61890 | |
| | @@ -61995,12 +62016,13 @@ |
| 61995 | 62016 | if( p->magic!=VDBE_MAGIC_RUN ){ |
| 61996 | 62017 | return SQLITE_OK; |
| 61997 | 62018 | } |
| 61998 | 62019 | checkActiveVdbeCnt(db); |
| 61999 | 62020 | |
| 62000 | | - /* No commit or rollback needed if the program never started */ |
| 62001 | | - if( p->pc>=0 ){ |
| 62021 | + /* No commit or rollback needed if the program never started or if the |
| 62022 | + ** SQL statement does not read or write a database file. */ |
| 62023 | + if( p->pc>=0 && p->bIsReader ){ |
| 62002 | 62024 | int mrc; /* Primary error code from p->rc */ |
| 62003 | 62025 | int eStatementOp = 0; |
| 62004 | 62026 | int isSpecialError; /* Set to true if a 'special' error */ |
| 62005 | 62027 | |
| 62006 | 62028 | /* Lock all btrees used by the statement */ |
| | @@ -62049,11 +62071,11 @@ |
| 62049 | 62071 | ** Note: This block also runs if one of the special errors handled |
| 62050 | 62072 | ** above has occurred. |
| 62051 | 62073 | */ |
| 62052 | 62074 | if( !sqlite3VtabInSync(db) |
| 62053 | 62075 | && db->autoCommit |
| 62054 | | - && db->writeVdbeCnt==(p->readOnly==0) |
| 62076 | + && db->nVdbeWrite==(p->readOnly==0) |
| 62055 | 62077 | ){ |
| 62056 | 62078 | if( p->rc==SQLITE_OK || (p->errorAction==OE_Fail && !isSpecialError) ){ |
| 62057 | 62079 | rc = sqlite3VdbeCheckFk(p, 1); |
| 62058 | 62080 | if( rc!=SQLITE_OK ){ |
| 62059 | 62081 | if( NEVER(p->readOnly) ){ |
| | @@ -62130,15 +62152,16 @@ |
| 62130 | 62152 | sqlite3VdbeLeave(p); |
| 62131 | 62153 | } |
| 62132 | 62154 | |
| 62133 | 62155 | /* We have successfully halted and closed the VM. Record this fact. */ |
| 62134 | 62156 | if( p->pc>=0 ){ |
| 62135 | | - db->activeVdbeCnt--; |
| 62136 | | - if( !p->readOnly ){ |
| 62137 | | - db->writeVdbeCnt--; |
| 62138 | | - } |
| 62139 | | - assert( db->activeVdbeCnt>=db->writeVdbeCnt ); |
| 62157 | + db->nVdbeActive--; |
| 62158 | + if( !p->readOnly ) db->nVdbeWrite--; |
| 62159 | + if( p->bIsReader ) db->nVdbeRead--; |
| 62160 | + assert( db->nVdbeActive>=db->nVdbeRead ); |
| 62161 | + assert( db->nVdbeRead>=db->nVdbeWrite ); |
| 62162 | + assert( db->nVdbeWrite>=0 ); |
| 62140 | 62163 | } |
| 62141 | 62164 | p->magic = VDBE_MAGIC_HALT; |
| 62142 | 62165 | checkActiveVdbeCnt(db); |
| 62143 | 62166 | if( p->db->mallocFailed ){ |
| 62144 | 62167 | p->rc = SQLITE_NOMEM; |
| | @@ -62150,11 +62173,11 @@ |
| 62150 | 62173 | */ |
| 62151 | 62174 | if( db->autoCommit ){ |
| 62152 | 62175 | sqlite3ConnectionUnlocked(db); |
| 62153 | 62176 | } |
| 62154 | 62177 | |
| 62155 | | - assert( db->activeVdbeCnt>0 || db->autoCommit==0 || db->nStatement==0 ); |
| 62178 | + assert( db->nVdbeActive>0 || db->autoCommit==0 || db->nStatement==0 ); |
| 62156 | 62179 | return (p->rc==SQLITE_BUSY ? SQLITE_BUSY : SQLITE_OK); |
| 62157 | 62180 | } |
| 62158 | 62181 | |
| 62159 | 62182 | |
| 62160 | 62183 | /* |
| | @@ -63508,35 +63531,36 @@ |
| 63508 | 63531 | if( p->pc<0 ){ |
| 63509 | 63532 | /* If there are no other statements currently running, then |
| 63510 | 63533 | ** reset the interrupt flag. This prevents a call to sqlite3_interrupt |
| 63511 | 63534 | ** from interrupting a statement that has not yet started. |
| 63512 | 63535 | */ |
| 63513 | | - if( db->activeVdbeCnt==0 ){ |
| 63536 | + if( db->nVdbeActive==0 ){ |
| 63514 | 63537 | db->u1.isInterrupted = 0; |
| 63515 | 63538 | } |
| 63516 | 63539 | |
| 63517 | | - assert( db->writeVdbeCnt>0 || db->autoCommit==0 || db->nDeferredCons==0 ); |
| 63540 | + assert( db->nVdbeWrite>0 || db->autoCommit==0 || db->nDeferredCons==0 ); |
| 63518 | 63541 | |
| 63519 | 63542 | #ifndef SQLITE_OMIT_TRACE |
| 63520 | 63543 | if( db->xProfile && !db->init.busy ){ |
| 63521 | 63544 | sqlite3OsCurrentTimeInt64(db->pVfs, &p->startTime); |
| 63522 | 63545 | } |
| 63523 | 63546 | #endif |
| 63524 | 63547 | |
| 63525 | | - db->activeVdbeCnt++; |
| 63526 | | - if( p->readOnly==0 ) db->writeVdbeCnt++; |
| 63548 | + db->nVdbeActive++; |
| 63549 | + if( p->readOnly==0 ) db->nVdbeWrite++; |
| 63550 | + if( p->bIsReader ) db->nVdbeRead++; |
| 63527 | 63551 | p->pc = 0; |
| 63528 | 63552 | } |
| 63529 | 63553 | #ifndef SQLITE_OMIT_EXPLAIN |
| 63530 | 63554 | if( p->explain ){ |
| 63531 | 63555 | rc = sqlite3VdbeList(p); |
| 63532 | 63556 | }else |
| 63533 | 63557 | #endif /* SQLITE_OMIT_EXPLAIN */ |
| 63534 | 63558 | { |
| 63535 | | - db->vdbeExecCnt++; |
| 63559 | + db->nVdbeExec++; |
| 63536 | 63560 | rc = sqlite3VdbeExec(p); |
| 63537 | | - db->vdbeExecCnt--; |
| 63561 | + db->nVdbeExec--; |
| 63538 | 63562 | } |
| 63539 | 63563 | |
| 63540 | 63564 | #ifndef SQLITE_OMIT_TRACE |
| 63541 | 63565 | /* Invoke the profile callback if there is one |
| 63542 | 63566 | */ |
| | @@ -64469,13 +64493,13 @@ |
| 64469 | 64493 | return nTotal; |
| 64470 | 64494 | } |
| 64471 | 64495 | |
| 64472 | 64496 | /* |
| 64473 | 64497 | ** This function returns a pointer to a nul-terminated string in memory |
| 64474 | | -** obtained from sqlite3DbMalloc(). If sqlite3.vdbeExecCnt is 1, then the |
| 64498 | +** obtained from sqlite3DbMalloc(). If sqlite3.nVdbeExec is 1, then the |
| 64475 | 64499 | ** string contains a copy of zRawSql but with host parameters expanded to |
| 64476 | | -** their current bindings. Or, if sqlite3.vdbeExecCnt is greater than 1, |
| 64500 | +** their current bindings. Or, if sqlite3.nVdbeExec is greater than 1, |
| 64477 | 64501 | ** then the returned string holds a copy of zRawSql with "-- " prepended |
| 64478 | 64502 | ** to each line of text. |
| 64479 | 64503 | ** |
| 64480 | 64504 | ** If the SQLITE_TRACE_SIZE_LIMIT macro is defined to an integer, then |
| 64481 | 64505 | ** then long strings and blobs are truncated to that many bytes. This |
| | @@ -64509,11 +64533,11 @@ |
| 64509 | 64533 | |
| 64510 | 64534 | db = p->db; |
| 64511 | 64535 | sqlite3StrAccumInit(&out, zBase, sizeof(zBase), |
| 64512 | 64536 | db->aLimit[SQLITE_LIMIT_LENGTH]); |
| 64513 | 64537 | out.db = db; |
| 64514 | | - if( db->vdbeExecCnt>1 ){ |
| 64538 | + if( db->nVdbeExec>1 ){ |
| 64515 | 64539 | while( *zRawSql ){ |
| 64516 | 64540 | const char *zStart = zRawSql; |
| 64517 | 64541 | while( *(zRawSql++)!='\n' && *zRawSql ); |
| 64518 | 64542 | sqlite3StrAccumAppend(&out, "-- ", 3); |
| 64519 | 64543 | sqlite3StrAccumAppend(&out, zStart, (int)(zRawSql-zStart)); |
| | @@ -65815,10 +65839,11 @@ |
| 65815 | 65839 | /* This happens if a malloc() inside a call to sqlite3_column_text() or |
| 65816 | 65840 | ** sqlite3_column_text16() failed. */ |
| 65817 | 65841 | goto no_mem; |
| 65818 | 65842 | } |
| 65819 | 65843 | assert( p->rc==SQLITE_OK || p->rc==SQLITE_BUSY ); |
| 65844 | + assert( p->bIsReader || p->readOnly!=0 ); |
| 65820 | 65845 | p->rc = SQLITE_OK; |
| 65821 | 65846 | assert( p->explain==0 ); |
| 65822 | 65847 | p->pResultSet = 0; |
| 65823 | 65848 | db->busyHandler.nBusy = 0; |
| 65824 | 65849 | CHECK_FOR_INTERRUPT; |
| | @@ -67959,13 +67984,14 @@ |
| 67959 | 67984 | */ |
| 67960 | 67985 | assert( db->pSavepoint==0 || db->autoCommit==0 ); |
| 67961 | 67986 | assert( u.as.p1==SAVEPOINT_BEGIN||u.as.p1==SAVEPOINT_RELEASE||u.as.p1==SAVEPOINT_ROLLBACK ); |
| 67962 | 67987 | assert( db->pSavepoint || db->isTransactionSavepoint==0 ); |
| 67963 | 67988 | assert( checkSavepointCount(db) ); |
| 67989 | + assert( p->bIsReader ); |
| 67964 | 67990 | |
| 67965 | 67991 | if( u.as.p1==SAVEPOINT_BEGIN ){ |
| 67966 | | - if( db->writeVdbeCnt>0 ){ |
| 67992 | + if( db->nVdbeWrite>0 ){ |
| 67967 | 67993 | /* A new savepoint cannot be created if there are active write |
| 67968 | 67994 | ** statements (i.e. open read/write incremental blob handles). |
| 67969 | 67995 | */ |
| 67970 | 67996 | sqlite3SetString(&p->zErrMsg, db, "cannot open savepoint - " |
| 67971 | 67997 | "SQL statements in progress"); |
| | @@ -68018,11 +68044,11 @@ |
| 68018 | 68044 | u.as.iSavepoint++; |
| 68019 | 68045 | } |
| 68020 | 68046 | if( !u.as.pSavepoint ){ |
| 68021 | 68047 | sqlite3SetString(&p->zErrMsg, db, "no such savepoint: %s", u.as.zName); |
| 68022 | 68048 | rc = SQLITE_ERROR; |
| 68023 | | - }else if( db->writeVdbeCnt>0 && u.as.p1==SAVEPOINT_RELEASE ){ |
| 68049 | + }else if( db->nVdbeWrite>0 && u.as.p1==SAVEPOINT_RELEASE ){ |
| 68024 | 68050 | /* It is not possible to release (commit) a savepoint if there are |
| 68025 | 68051 | ** active write statements. |
| 68026 | 68052 | */ |
| 68027 | 68053 | sqlite3SetString(&p->zErrMsg, db, |
| 68028 | 68054 | "cannot release savepoint - SQL statements in progress" |
| | @@ -68121,24 +68147,25 @@ |
| 68121 | 68147 | u.at.desiredAutoCommit = pOp->p1; |
| 68122 | 68148 | u.at.iRollback = pOp->p2; |
| 68123 | 68149 | u.at.turnOnAC = u.at.desiredAutoCommit && !db->autoCommit; |
| 68124 | 68150 | assert( u.at.desiredAutoCommit==1 || u.at.desiredAutoCommit==0 ); |
| 68125 | 68151 | assert( u.at.desiredAutoCommit==1 || u.at.iRollback==0 ); |
| 68126 | | - assert( db->activeVdbeCnt>0 ); /* At least this one VM is active */ |
| 68152 | + assert( db->nVdbeActive>0 ); /* At least this one VM is active */ |
| 68153 | + assert( p->bIsReader ); |
| 68127 | 68154 | |
| 68128 | 68155 | #if 0 |
| 68129 | | - if( u.at.turnOnAC && u.at.iRollback && db->activeVdbeCnt>1 ){ |
| 68156 | + if( u.at.turnOnAC && u.at.iRollback && db->nVdbeActive>1 ){ |
| 68130 | 68157 | /* If this instruction implements a ROLLBACK and other VMs are |
| 68131 | 68158 | ** still running, and a transaction is active, return an error indicating |
| 68132 | 68159 | ** that the other VMs must complete first. |
| 68133 | 68160 | */ |
| 68134 | 68161 | sqlite3SetString(&p->zErrMsg, db, "cannot rollback transaction - " |
| 68135 | 68162 | "SQL statements in progress"); |
| 68136 | 68163 | rc = SQLITE_BUSY; |
| 68137 | 68164 | }else |
| 68138 | 68165 | #endif |
| 68139 | | - if( u.at.turnOnAC && !u.at.iRollback && db->writeVdbeCnt>0 ){ |
| 68166 | + if( u.at.turnOnAC && !u.at.iRollback && db->nVdbeWrite>0 ){ |
| 68140 | 68167 | /* If this instruction implements a COMMIT and other VMs are writing |
| 68141 | 68168 | ** return an error indicating that the other VMs must complete first. |
| 68142 | 68169 | */ |
| 68143 | 68170 | sqlite3SetString(&p->zErrMsg, db, "cannot commit transaction - " |
| 68144 | 68171 | "SQL statements in progress"); |
| | @@ -68212,10 +68239,12 @@ |
| 68212 | 68239 | case OP_Transaction: { |
| 68213 | 68240 | #if 0 /* local variables moved into u.au */ |
| 68214 | 68241 | Btree *pBt; |
| 68215 | 68242 | #endif /* local variables moved into u.au */ |
| 68216 | 68243 | |
| 68244 | + assert( p->bIsReader ); |
| 68245 | + assert( p->readOnly==0 || pOp->p2==0 ); |
| 68217 | 68246 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 68218 | 68247 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 68219 | 68248 | u.au.pBt = db->aDb[pOp->p1].pBt; |
| 68220 | 68249 | |
| 68221 | 68250 | if( u.au.pBt ){ |
| | @@ -68228,11 +68257,11 @@ |
| 68228 | 68257 | if( rc!=SQLITE_OK ){ |
| 68229 | 68258 | goto abort_due_to_error; |
| 68230 | 68259 | } |
| 68231 | 68260 | |
| 68232 | 68261 | if( pOp->p2 && p->usesStmtJournal |
| 68233 | | - && (db->autoCommit==0 || db->activeVdbeCnt>1) |
| 68262 | + && (db->autoCommit==0 || db->nVdbeRead>1) |
| 68234 | 68263 | ){ |
| 68235 | 68264 | assert( sqlite3BtreeIsInTrans(u.au.pBt) ); |
| 68236 | 68265 | if( p->iStatement==0 ){ |
| 68237 | 68266 | assert( db->nStatement>=0 && db->nSavepoint>=0 ); |
| 68238 | 68267 | db->nStatement++; |
| | @@ -68270,10 +68299,11 @@ |
| 68270 | 68299 | int iMeta; |
| 68271 | 68300 | int iDb; |
| 68272 | 68301 | int iCookie; |
| 68273 | 68302 | #endif /* local variables moved into u.av */ |
| 68274 | 68303 | |
| 68304 | + assert( p->bIsReader ); |
| 68275 | 68305 | u.av.iDb = pOp->p1; |
| 68276 | 68306 | u.av.iCookie = pOp->p3; |
| 68277 | 68307 | assert( pOp->p3<SQLITE_N_BTREE_META ); |
| 68278 | 68308 | assert( u.av.iDb>=0 && u.av.iDb<db->nDb ); |
| 68279 | 68309 | assert( db->aDb[u.av.iDb].pBt!=0 ); |
| | @@ -68299,10 +68329,11 @@ |
| 68299 | 68329 | Db *pDb; |
| 68300 | 68330 | #endif /* local variables moved into u.aw */ |
| 68301 | 68331 | assert( pOp->p2<SQLITE_N_BTREE_META ); |
| 68302 | 68332 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 68303 | 68333 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 68334 | + assert( p->readOnly==0 ); |
| 68304 | 68335 | u.aw.pDb = &db->aDb[pOp->p1]; |
| 68305 | 68336 | assert( u.aw.pDb->pBt!=0 ); |
| 68306 | 68337 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 68307 | 68338 | pIn3 = &aMem[pOp->p3]; |
| 68308 | 68339 | sqlite3VdbeMemIntegerify(pIn3); |
| | @@ -68351,10 +68382,11 @@ |
| 68351 | 68382 | #endif /* local variables moved into u.ax */ |
| 68352 | 68383 | |
| 68353 | 68384 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 68354 | 68385 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 68355 | 68386 | assert( sqlite3SchemaMutexHeld(db, pOp->p1, 0) ); |
| 68387 | + assert( p->bIsReader ); |
| 68356 | 68388 | u.ax.pBt = db->aDb[pOp->p1].pBt; |
| 68357 | 68389 | if( u.ax.pBt ){ |
| 68358 | 68390 | sqlite3BtreeGetMeta(u.ax.pBt, BTREE_SCHEMA_VERSION, (u32 *)&u.ax.iMeta); |
| 68359 | 68391 | u.ax.iGen = db->aDb[pOp->p1].pSchema->iGeneration; |
| 68360 | 68392 | }else{ |
| | @@ -68448,10 +68480,12 @@ |
| 68448 | 68480 | Db *pDb; |
| 68449 | 68481 | #endif /* local variables moved into u.ay */ |
| 68450 | 68482 | |
| 68451 | 68483 | assert( (pOp->p5&(OPFLAG_P2ISREG|OPFLAG_BULKCSR))==pOp->p5 ); |
| 68452 | 68484 | assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 ); |
| 68485 | + assert( p->bIsReader ); |
| 68486 | + assert( pOp->opcode==OP_OpenRead || p->readOnly==0 ); |
| 68453 | 68487 | |
| 68454 | 68488 | if( p->expired ){ |
| 68455 | 68489 | rc = SQLITE_ABORT; |
| 68456 | 68490 | break; |
| 68457 | 68491 | } |
| | @@ -70066,19 +70100,22 @@ |
| 70066 | 70100 | int iCnt; |
| 70067 | 70101 | Vdbe *pVdbe; |
| 70068 | 70102 | int iDb; |
| 70069 | 70103 | #endif /* local variables moved into u.bw */ |
| 70070 | 70104 | |
| 70105 | + assert( p->readOnly==0 ); |
| 70071 | 70106 | #ifndef SQLITE_OMIT_VIRTUALTABLE |
| 70072 | 70107 | u.bw.iCnt = 0; |
| 70073 | 70108 | for(u.bw.pVdbe=db->pVdbe; u.bw.pVdbe; u.bw.pVdbe = u.bw.pVdbe->pNext){ |
| 70074 | | - if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0 ){ |
| 70109 | + if( u.bw.pVdbe->magic==VDBE_MAGIC_RUN && u.bw.pVdbe->bIsReader |
| 70110 | + && u.bw.pVdbe->inVtabMethod<2 && u.bw.pVdbe->pc>=0 |
| 70111 | + ){ |
| 70075 | 70112 | u.bw.iCnt++; |
| 70076 | 70113 | } |
| 70077 | 70114 | } |
| 70078 | 70115 | #else |
| 70079 | | - u.bw.iCnt = db->activeVdbeCnt; |
| 70116 | + u.bw.iCnt = db->nVdbeRead; |
| 70080 | 70117 | #endif |
| 70081 | 70118 | pOut->flags = MEM_Null; |
| 70082 | 70119 | if( u.bw.iCnt>1 ){ |
| 70083 | 70120 | rc = SQLITE_LOCKED; |
| 70084 | 70121 | p->errorAction = OE_Abort; |
| | @@ -70123,10 +70160,11 @@ |
| 70123 | 70160 | #if 0 /* local variables moved into u.bx */ |
| 70124 | 70161 | int nChange; |
| 70125 | 70162 | #endif /* local variables moved into u.bx */ |
| 70126 | 70163 | |
| 70127 | 70164 | u.bx.nChange = 0; |
| 70165 | + assert( p->readOnly==0 ); |
| 70128 | 70166 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p2))!=0 ); |
| 70129 | 70167 | rc = sqlite3BtreeClearTable( |
| 70130 | 70168 | db->aDb[pOp->p2].pBt, pOp->p1, (pOp->p3 ? &u.bx.nChange : 0) |
| 70131 | 70169 | ); |
| 70132 | 70170 | if( pOp->p3 ){ |
| | @@ -70171,10 +70209,11 @@ |
| 70171 | 70209 | #endif /* local variables moved into u.by */ |
| 70172 | 70210 | |
| 70173 | 70211 | u.by.pgno = 0; |
| 70174 | 70212 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 70175 | 70213 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 70214 | + assert( p->readOnly==0 ); |
| 70176 | 70215 | u.by.pDb = &db->aDb[pOp->p1]; |
| 70177 | 70216 | assert( u.by.pDb->pBt!=0 ); |
| 70178 | 70217 | if( pOp->opcode==OP_CreateTable ){ |
| 70179 | 70218 | /* u.by.flags = BTREE_INTKEY; */ |
| 70180 | 70219 | u.by.flags = BTREE_INTKEY; |
| | @@ -70323,10 +70362,11 @@ |
| 70323 | 70362 | int nErr; /* Number of errors reported */ |
| 70324 | 70363 | char *z; /* Text of the error report */ |
| 70325 | 70364 | Mem *pnErr; /* Register keeping track of errors remaining */ |
| 70326 | 70365 | #endif /* local variables moved into u.ca */ |
| 70327 | 70366 | |
| 70367 | + assert( p->bIsReader ); |
| 70328 | 70368 | u.ca.nRoot = pOp->p2; |
| 70329 | 70369 | assert( u.ca.nRoot>0 ); |
| 70330 | 70370 | u.ca.aRoot = sqlite3DbMallocRaw(db, sizeof(int)*(u.ca.nRoot+1) ); |
| 70331 | 70371 | if( u.ca.aRoot==0 ) goto no_mem; |
| 70332 | 70372 | assert( pOp->p3>0 && pOp->p3<=p->nMem ); |
| | @@ -70844,10 +70884,11 @@ |
| 70844 | 70884 | int i; /* Loop counter */ |
| 70845 | 70885 | int aRes[3]; /* Results */ |
| 70846 | 70886 | Mem *pMem; /* Write results here */ |
| 70847 | 70887 | #endif /* local variables moved into u.ci */ |
| 70848 | 70888 | |
| 70889 | + assert( p->readOnly==0 ); |
| 70849 | 70890 | u.ci.aRes[0] = 0; |
| 70850 | 70891 | u.ci.aRes[1] = u.ci.aRes[2] = -1; |
| 70851 | 70892 | assert( pOp->p2==SQLITE_CHECKPOINT_PASSIVE |
| 70852 | 70893 | || pOp->p2==SQLITE_CHECKPOINT_FULL |
| 70853 | 70894 | || pOp->p2==SQLITE_CHECKPOINT_RESTART |
| | @@ -70895,10 +70936,11 @@ |
| 70895 | 70936 | || u.cj.eNew==PAGER_JOURNALMODE_MEMORY |
| 70896 | 70937 | || u.cj.eNew==PAGER_JOURNALMODE_WAL |
| 70897 | 70938 | || u.cj.eNew==PAGER_JOURNALMODE_QUERY |
| 70898 | 70939 | ); |
| 70899 | 70940 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 70941 | + assert( p->readOnly==0 ); |
| 70900 | 70942 | |
| 70901 | 70943 | u.cj.pBt = db->aDb[pOp->p1].pBt; |
| 70902 | 70944 | u.cj.pPager = sqlite3BtreePager(u.cj.pBt); |
| 70903 | 70945 | u.cj.eOld = sqlite3PagerGetJournalMode(u.cj.pPager); |
| 70904 | 70946 | if( u.cj.eNew==PAGER_JOURNALMODE_QUERY ) u.cj.eNew = u.cj.eOld; |
| | @@ -70918,11 +70960,11 @@ |
| 70918 | 70960 | } |
| 70919 | 70961 | |
| 70920 | 70962 | if( (u.cj.eNew!=u.cj.eOld) |
| 70921 | 70963 | && (u.cj.eOld==PAGER_JOURNALMODE_WAL || u.cj.eNew==PAGER_JOURNALMODE_WAL) |
| 70922 | 70964 | ){ |
| 70923 | | - if( !db->autoCommit || db->activeVdbeCnt>1 ){ |
| 70965 | + if( !db->autoCommit || db->nVdbeRead>1 ){ |
| 70924 | 70966 | rc = SQLITE_ERROR; |
| 70925 | 70967 | sqlite3SetString(&p->zErrMsg, db, |
| 70926 | 70968 | "cannot change %s wal mode from within a transaction", |
| 70927 | 70969 | (u.cj.eNew==PAGER_JOURNALMODE_WAL ? "into" : "out of") |
| 70928 | 70970 | ); |
| | @@ -70977,10 +71019,11 @@ |
| 70977 | 71019 | ** Vacuum the entire database. This opcode will cause other virtual |
| 70978 | 71020 | ** machines to be created and run. It may not be called from within |
| 70979 | 71021 | ** a transaction. |
| 70980 | 71022 | */ |
| 70981 | 71023 | case OP_Vacuum: { |
| 71024 | + assert( p->readOnly==0 ); |
| 70982 | 71025 | rc = sqlite3RunVacuum(&p->zErrMsg, db); |
| 70983 | 71026 | break; |
| 70984 | 71027 | } |
| 70985 | 71028 | #endif |
| 70986 | 71029 | |
| | @@ -70996,10 +71039,11 @@ |
| 70996 | 71039 | Btree *pBt; |
| 70997 | 71040 | #endif /* local variables moved into u.ck */ |
| 70998 | 71041 | |
| 70999 | 71042 | assert( pOp->p1>=0 && pOp->p1<db->nDb ); |
| 71000 | 71043 | assert( (p->btreeMask & (((yDbMask)1)<<pOp->p1))!=0 ); |
| 71044 | + assert( p->readOnly==0 ); |
| 71001 | 71045 | u.ck.pBt = db->aDb[pOp->p1].pBt; |
| 71002 | 71046 | rc = sqlite3BtreeIncrVacuum(u.ck.pBt); |
| 71003 | 71047 | if( rc==SQLITE_DONE ){ |
| 71004 | 71048 | pc = pOp->p2 - 1; |
| 71005 | 71049 | rc = SQLITE_OK; |
| | @@ -71118,10 +71162,11 @@ |
| 71118 | 71162 | sqlite3_vtab_cursor *pVtabCursor; |
| 71119 | 71163 | sqlite3_vtab *pVtab; |
| 71120 | 71164 | sqlite3_module *pModule; |
| 71121 | 71165 | #endif /* local variables moved into u.cm */ |
| 71122 | 71166 | |
| 71167 | + assert( p->bIsReader ); |
| 71123 | 71168 | u.cm.pCur = 0; |
| 71124 | 71169 | u.cm.pVtabCursor = 0; |
| 71125 | 71170 | u.cm.pVtab = pOp->p4.pVtab->pVtab; |
| 71126 | 71171 | u.cm.pModule = (sqlite3_module *)u.cm.pVtab->pModule; |
| 71127 | 71172 | assert(u.cm.pVtab && u.cm.pModule); |
| | @@ -71342,10 +71387,11 @@ |
| 71342 | 71387 | |
| 71343 | 71388 | u.cq.pVtab = pOp->p4.pVtab->pVtab; |
| 71344 | 71389 | u.cq.pName = &aMem[pOp->p1]; |
| 71345 | 71390 | assert( u.cq.pVtab->pModule->xRename ); |
| 71346 | 71391 | assert( memIsValid(u.cq.pName) ); |
| 71392 | + assert( p->readOnly==0 ); |
| 71347 | 71393 | REGISTER_TRACE(pOp->p1, u.cq.pName); |
| 71348 | 71394 | assert( u.cq.pName->flags & MEM_Str ); |
| 71349 | 71395 | testcase( u.cq.pName->enc==SQLITE_UTF8 ); |
| 71350 | 71396 | testcase( u.cq.pName->enc==SQLITE_UTF16BE ); |
| 71351 | 71397 | testcase( u.cq.pName->enc==SQLITE_UTF16LE ); |
| | @@ -71395,10 +71441,11 @@ |
| 71395 | 71441 | #endif /* local variables moved into u.cr */ |
| 71396 | 71442 | |
| 71397 | 71443 | assert( pOp->p2==1 || pOp->p5==OE_Fail || pOp->p5==OE_Rollback |
| 71398 | 71444 | || pOp->p5==OE_Abort || pOp->p5==OE_Ignore || pOp->p5==OE_Replace |
| 71399 | 71445 | ); |
| 71446 | + assert( p->readOnly==0 ); |
| 71400 | 71447 | u.cr.pVtab = pOp->p4.pVtab->pVtab; |
| 71401 | 71448 | u.cr.pModule = (sqlite3_module *)u.cr.pVtab->pModule; |
| 71402 | 71449 | u.cr.nArg = pOp->p2; |
| 71403 | 71450 | assert( pOp->p4type==P4_VTAB ); |
| 71404 | 71451 | if( ALWAYS(u.cr.pModule->xUpdate) ){ |
| | @@ -102957,11 +103004,11 @@ |
| 102957 | 103004 | |
| 102958 | 103005 | if( !db->autoCommit ){ |
| 102959 | 103006 | sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction"); |
| 102960 | 103007 | return SQLITE_ERROR; |
| 102961 | 103008 | } |
| 102962 | | - if( db->activeVdbeCnt>1 ){ |
| 103009 | + if( db->nVdbeActive>1 ){ |
| 102963 | 103010 | sqlite3SetString(pzErrMsg, db,"cannot VACUUM - SQL statements in progress"); |
| 102964 | 103011 | return SQLITE_ERROR; |
| 102965 | 103012 | } |
| 102966 | 103013 | |
| 102967 | 103014 | /* Save the current value of the database flags so that it can be |
| | @@ -104742,11 +104789,11 @@ |
| 104742 | 104789 | #define WHERE_INDEXED 0x00000200 /* WhereLoop.u.btree.pIndex is valid */ |
| 104743 | 104790 | #define WHERE_VIRTUALTABLE 0x00000400 /* WhereLoop.u.vtab is valid */ |
| 104744 | 104791 | #define WHERE_IN_ABLE 0x00000800 /* Able to support an IN operator */ |
| 104745 | 104792 | #define WHERE_ONEROW 0x00001000 /* Selects no more than one row */ |
| 104746 | 104793 | #define WHERE_MULTI_OR 0x00002000 /* OR using multiple indices */ |
| 104747 | | -#define WHERE_TEMP_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 104794 | +#define WHERE_AUTO_INDEX 0x00004000 /* Uses an ephemeral index */ |
| 104748 | 104795 | |
| 104749 | 104796 | |
| 104750 | 104797 | /* Convert a WhereCost value (10 times log2(X)) into its integer value X. |
| 104751 | 104798 | ** A rough approximation is used. The value returned is not exact. |
| 104752 | 104799 | */ |
| | @@ -106036,10 +106083,11 @@ |
| 106036 | 106083 | ** the start of the loop will prevent any results from being returned. |
| 106037 | 106084 | */ |
| 106038 | 106085 | if( pExpr->op==TK_NOTNULL |
| 106039 | 106086 | && pExpr->pLeft->op==TK_COLUMN |
| 106040 | 106087 | && pExpr->pLeft->iColumn>=0 |
| 106088 | + && OptimizationEnabled(db, SQLITE_Stat3) |
| 106041 | 106089 | ){ |
| 106042 | 106090 | Expr *pNewExpr; |
| 106043 | 106091 | Expr *pLeft = pExpr->pLeft; |
| 106044 | 106092 | int idxNew; |
| 106045 | 106093 | WhereTerm *pNewTerm; |
| | @@ -106339,10 +106387,11 @@ |
| 106339 | 106387 | int mxBitCol; /* Maximum column in pSrc->colUsed */ |
| 106340 | 106388 | CollSeq *pColl; /* Collating sequence to on a column */ |
| 106341 | 106389 | WhereLoop *pLoop; /* The Loop object */ |
| 106342 | 106390 | Bitmask idxCols; /* Bitmap of columns used for indexing */ |
| 106343 | 106391 | Bitmask extraCols; /* Bitmap of additional columns */ |
| 106392 | + u8 sentWarning = 0; /* True if a warnning has been issued */ |
| 106344 | 106393 | |
| 106345 | 106394 | /* Generate code to skip over the creation and initialization of the |
| 106346 | 106395 | ** transient index on 2nd and subsequent iterations of the loop. */ |
| 106347 | 106396 | v = pParse->pVdbe; |
| 106348 | 106397 | assert( v!=0 ); |
| | @@ -106359,10 +106408,16 @@ |
| 106359 | 106408 | if( termCanDriveIndex(pTerm, pSrc, notReady) ){ |
| 106360 | 106409 | int iCol = pTerm->u.leftColumn; |
| 106361 | 106410 | Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol); |
| 106362 | 106411 | testcase( iCol==BMS ); |
| 106363 | 106412 | testcase( iCol==BMS-1 ); |
| 106413 | + if( !sentWarning ){ |
| 106414 | + sqlite3_log(SQLITE_WARNING_AUTOINDEX, |
| 106415 | + "automatic index on %s(%s)", pTable->zName, |
| 106416 | + pTable->aCol[iCol].zName); |
| 106417 | + sentWarning = 1; |
| 106418 | + } |
| 106364 | 106419 | if( (idxCols & cMask)==0 ){ |
| 106365 | 106420 | if( whereLoopResize(pParse->db, pLoop, nColumn+1) ) return; |
| 106366 | 106421 | pLoop->aLTerm[nColumn++] = pTerm; |
| 106367 | 106422 | idxCols |= cMask; |
| 106368 | 106423 | } |
| | @@ -106369,11 +106424,11 @@ |
| 106369 | 106424 | } |
| 106370 | 106425 | } |
| 106371 | 106426 | assert( nColumn>0 ); |
| 106372 | 106427 | pLoop->u.btree.nEq = pLoop->nLTerm = nColumn; |
| 106373 | 106428 | pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED |
| 106374 | | - | WHERE_TEMP_INDEX; |
| 106429 | + | WHERE_AUTO_INDEX; |
| 106375 | 106430 | |
| 106376 | 106431 | /* Count the number of additional columns needed to create a |
| 106377 | 106432 | ** covering index. A "covering index" is an index that contains all |
| 106378 | 106433 | ** columns that are needed by the query. With a covering index, the |
| 106379 | 106434 | ** original table never needs to be accessed. Automatic indices must |
| | @@ -106869,11 +106924,11 @@ |
| 106869 | 106924 | ){ |
| 106870 | 106925 | int rc = SQLITE_OK; |
| 106871 | 106926 | |
| 106872 | 106927 | #ifdef SQLITE_ENABLE_STAT3 |
| 106873 | 106928 | |
| 106874 | | - if( nEq==0 && p->nSample ){ |
| 106929 | + if( nEq==0 && p->nSample && OptimizationEnabled(pParse->db, SQLITE_Stat3) ){ |
| 106875 | 106930 | sqlite3_value *pRangeVal; |
| 106876 | 106931 | tRowcnt iLower = 0; |
| 106877 | 106932 | tRowcnt iUpper = p->aiRowEst[0]; |
| 106878 | 106933 | tRowcnt a[2]; |
| 106879 | 106934 | u8 aff = p->pTable->aCol[p->aiColumn[0]].affinity; |
| | @@ -107415,17 +107470,16 @@ |
| 107415 | 107470 | } |
| 107416 | 107471 | if( (flags & (WHERE_IPK|WHERE_VIRTUALTABLE))==0 |
| 107417 | 107472 | && ALWAYS(pLoop->u.btree.pIndex!=0) |
| 107418 | 107473 | ){ |
| 107419 | 107474 | char *zWhere = explainIndexRange(db, pLoop, pItem->pTab); |
| 107420 | | - zMsg = sqlite3MAppendf(db, zMsg, "%s USING %s%sINDEX%s%s%s", zMsg, |
| 107421 | | - ((flags & WHERE_TEMP_INDEX)?"AUTOMATIC ":""), |
| 107422 | | - ((flags & WHERE_IDX_ONLY)?"COVERING ":""), |
| 107423 | | - ((flags & WHERE_TEMP_INDEX)?"":" "), |
| 107424 | | - ((flags & WHERE_TEMP_INDEX)?"": pLoop->u.btree.pIndex->zName), |
| 107425 | | - zWhere |
| 107426 | | - ); |
| 107475 | + zMsg = sqlite3MAppendf(db, zMsg, |
| 107476 | + ((flags & WHERE_AUTO_INDEX) ? |
| 107477 | + "%s USING AUTOMATIC %sINDEX%.0s%s" : |
| 107478 | + "%s USING %sINDEX %s%s"), |
| 107479 | + zMsg, ((flags & WHERE_IDX_ONLY) ? "COVERING " : ""), |
| 107480 | + pLoop->u.btree.pIndex->zName, zWhere); |
| 107427 | 107481 | sqlite3DbFree(db, zWhere); |
| 107428 | 107482 | }else if( (flags & WHERE_IPK)!=0 && (flags & WHERE_CONSTRAINT)!=0 ){ |
| 107429 | 107483 | zMsg = sqlite3MAppendf(db, zMsg, "%s USING INTEGER PRIMARY KEY", zMsg); |
| 107430 | 107484 | |
| 107431 | 107485 | if( flags&(WHERE_COLUMN_EQ|WHERE_COLUMN_IN) ){ |
| | @@ -108092,11 +108146,11 @@ |
| 108092 | 108146 | ** terms, set pCov to the candidate covering index. Otherwise, set |
| 108093 | 108147 | ** pCov to NULL to indicate that no candidate covering index will |
| 108094 | 108148 | ** be available. |
| 108095 | 108149 | */ |
| 108096 | 108150 | pSubLoop = pSubWInfo->a[0].pWLoop; |
| 108097 | | - assert( (pSubLoop->wsFlags & WHERE_TEMP_INDEX)==0 ); |
| 108151 | + assert( (pSubLoop->wsFlags & WHERE_AUTO_INDEX)==0 ); |
| 108098 | 108152 | if( (pSubLoop->wsFlags & WHERE_INDEXED)!=0 |
| 108099 | 108153 | && (ii==0 || pSubLoop->u.btree.pIndex==pCov) |
| 108100 | 108154 | ){ |
| 108101 | 108155 | assert( pSubWInfo->a[0].iIdxCur==iCovCur ); |
| 108102 | 108156 | pCov = pSubLoop->u.btree.pIndex; |
| | @@ -108274,16 +108328,16 @@ |
| 108274 | 108328 | |
| 108275 | 108329 | /* |
| 108276 | 108330 | ** Clear the WhereLoop.u union. Leave WhereLoop.pLTerm intact. |
| 108277 | 108331 | */ |
| 108278 | 108332 | static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){ |
| 108279 | | - if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_TEMP_INDEX) ){ |
| 108333 | + if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_AUTO_INDEX) ){ |
| 108280 | 108334 | if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){ |
| 108281 | 108335 | sqlite3_free(p->u.vtab.idxStr); |
| 108282 | 108336 | p->u.vtab.needFree = 0; |
| 108283 | 108337 | p->u.vtab.idxStr = 0; |
| 108284 | | - }else if( (p->wsFlags & WHERE_TEMP_INDEX)!=0 && p->u.btree.pIndex!=0 ){ |
| 108338 | + }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){ |
| 108285 | 108339 | sqlite3DbFree(db, p->u.btree.pIndex->zColAff); |
| 108286 | 108340 | sqlite3DbFree(db, p->u.btree.pIndex); |
| 108287 | 108341 | p->u.btree.pIndex = 0; |
| 108288 | 108342 | } |
| 108289 | 108343 | } |
| | @@ -108322,11 +108376,11 @@ |
| 108322 | 108376 | whereLoopClearUnion(db, pTo); |
| 108323 | 108377 | memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ); |
| 108324 | 108378 | memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0])); |
| 108325 | 108379 | if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){ |
| 108326 | 108380 | pFrom->u.vtab.needFree = 0; |
| 108327 | | - }else if( (pFrom->wsFlags & WHERE_TEMP_INDEX)!=0 ){ |
| 108381 | + }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 108328 | 108382 | pFrom->u.btree.pIndex = 0; |
| 108329 | 108383 | } |
| 108330 | 108384 | return SQLITE_OK; |
| 108331 | 108385 | } |
| 108332 | 108386 | |
| | @@ -108634,11 +108688,12 @@ |
| 108634 | 108688 | whereRangeScanEst(pParse, pProbe, pNew->u.btree.nEq, |
| 108635 | 108689 | pBtm, pTop, &rDiv); |
| 108636 | 108690 | pNew->nOut = saved_nOut>rDiv+10 ? saved_nOut - rDiv : 10; |
| 108637 | 108691 | } |
| 108638 | 108692 | #ifdef SQLITE_ENABLE_STAT3 |
| 108639 | | - if( pNew->u.btree.nEq==1 && pProbe->nSample ){ |
| 108693 | + if( pNew->u.btree.nEq==1 && pProbe->nSample |
| 108694 | + && OptimizationEnabled(db, SQLITE_Stat3) ){ |
| 108640 | 108695 | tRowcnt nOut = 0; |
| 108641 | 108696 | if( (pTerm->eOperator & (WO_EQ|WO_ISNULL))!=0 ){ |
| 108642 | 108697 | testcase( pTerm->eOperator & WO_EQ ); |
| 108643 | 108698 | testcase( pTerm->eOperator & WO_ISNULL ); |
| 108644 | 108699 | rc = whereEqualScanEst(pParse, pProbe, pTerm->pExpr->pRight, &nOut); |
| | @@ -108794,17 +108849,20 @@ |
| 108794 | 108849 | pNew->u.btree.nEq = 1; |
| 108795 | 108850 | pNew->u.btree.pIndex = 0; |
| 108796 | 108851 | pNew->nLTerm = 1; |
| 108797 | 108852 | pNew->aLTerm[0] = pTerm; |
| 108798 | 108853 | /* TUNING: One-time cost for computing the automatic index is |
| 108799 | | - ** approximately 6*N*log2(N) where N is the number of rows in |
| 108854 | + ** approximately 7*N*log2(N) where N is the number of rows in |
| 108800 | 108855 | ** the table being indexed. */ |
| 108801 | | - pNew->rSetup = rLogSize + rSize + 26; assert( 26==whereCost(6) ); |
| 108802 | | - /* TUNING: Each index lookup yields 10 rows in the table */ |
| 108803 | | - pNew->nOut = 33; assert( 33==whereCost(10) ); |
| 108856 | + pNew->rSetup = rLogSize + rSize + 28; assert( 28==whereCost(7) ); |
| 108857 | + /* TUNING: Each index lookup yields 20 rows in the table. This |
| 108858 | + ** is more than the usual guess of 10 rows, since we have no way |
| 108859 | + ** of knowning how selective the index will ultimately be. It would |
| 108860 | + ** not be unreasonable to make this value much larger. */ |
| 108861 | + pNew->nOut = 43; assert( 43==whereCost(20) ); |
| 108804 | 108862 | pNew->rRun = whereCostAdd(rLogSize,pNew->nOut); |
| 108805 | | - pNew->wsFlags = WHERE_TEMP_INDEX; |
| 108863 | + pNew->wsFlags = WHERE_AUTO_INDEX; |
| 108806 | 108864 | pNew->prereq = mExtra | pTerm->prereqRight; |
| 108807 | 108865 | rc = whereLoopInsert(pBuilder, pNew); |
| 108808 | 108866 | } |
| 108809 | 108867 | } |
| 108810 | 108868 | } |
| | @@ -110094,18 +110152,28 @@ |
| 110094 | 110152 | && OptimizationEnabled(db, SQLITE_OmitNoopJoin) |
| 110095 | 110153 | ){ |
| 110096 | 110154 | Bitmask tabUsed = exprListTableUsage(pMaskSet, pResultSet); |
| 110097 | 110155 | if( pOrderBy ) tabUsed |= exprListTableUsage(pMaskSet, pOrderBy); |
| 110098 | 110156 | while( pWInfo->nLevel>=2 ){ |
| 110157 | + WhereTerm *pTerm, *pEnd; |
| 110099 | 110158 | pLoop = pWInfo->a[pWInfo->nLevel-1].pWLoop; |
| 110100 | 110159 | if( (pWInfo->pTabList->a[pLoop->iTab].jointype & JT_LEFT)==0 ) break; |
| 110101 | 110160 | if( (wctrlFlags & WHERE_WANT_DISTINCT)==0 |
| 110102 | 110161 | && (pLoop->wsFlags & WHERE_ONEROW)==0 |
| 110103 | 110162 | ){ |
| 110104 | 110163 | break; |
| 110105 | 110164 | } |
| 110106 | 110165 | if( (tabUsed & pLoop->maskSelf)!=0 ) break; |
| 110166 | + pEnd = sWLB.pWC->a + sWLB.pWC->nTerm; |
| 110167 | + for(pTerm=sWLB.pWC->a; pTerm<pEnd; pTerm++){ |
| 110168 | + if( (pTerm->prereqAll & pLoop->maskSelf)!=0 |
| 110169 | + && !ExprHasProperty(pTerm->pExpr, EP_FromJoin) |
| 110170 | + ){ |
| 110171 | + break; |
| 110172 | + } |
| 110173 | + } |
| 110174 | + if( pTerm<pEnd ) break; |
| 110107 | 110175 | WHERETRACE(0xffff, ("-> drop loop %c not used\n", pLoop->cId)); |
| 110108 | 110176 | pWInfo->nLevel--; |
| 110109 | 110177 | nTabList--; |
| 110110 | 110178 | } |
| 110111 | 110179 | } |
| | @@ -110167,11 +110235,11 @@ |
| 110167 | 110235 | } |
| 110168 | 110236 | }else{ |
| 110169 | 110237 | sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName); |
| 110170 | 110238 | } |
| 110171 | 110239 | #ifndef SQLITE_OMIT_AUTOMATIC_INDEX |
| 110172 | | - if( (pLoop->wsFlags & WHERE_TEMP_INDEX)!=0 ){ |
| 110240 | + if( (pLoop->wsFlags & WHERE_AUTO_INDEX)!=0 ){ |
| 110173 | 110241 | constructAutomaticIndex(pParse, &pWInfo->sWC, pTabItem, notReady, pLevel); |
| 110174 | 110242 | }else |
| 110175 | 110243 | #endif |
| 110176 | 110244 | if( pLoop->wsFlags & WHERE_INDEXED ){ |
| 110177 | 110245 | Index *pIx = pLoop->u.btree.pIndex; |
| | @@ -110290,11 +110358,11 @@ |
| 110290 | 110358 | ){ |
| 110291 | 110359 | int ws = pLoop->wsFlags; |
| 110292 | 110360 | if( !pWInfo->okOnePass && (ws & WHERE_IDX_ONLY)==0 ){ |
| 110293 | 110361 | sqlite3VdbeAddOp1(v, OP_Close, pTabItem->iCursor); |
| 110294 | 110362 | } |
| 110295 | | - if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_TEMP_INDEX))==0 ){ |
| 110363 | + if( (ws & WHERE_INDEXED)!=0 && (ws & (WHERE_IPK|WHERE_AUTO_INDEX))==0 ){ |
| 110296 | 110364 | sqlite3VdbeAddOp1(v, OP_Close, pLevel->iIdxCur); |
| 110297 | 110365 | } |
| 110298 | 110366 | } |
| 110299 | 110367 | |
| 110300 | 110368 | /* If this scan uses an index, make VDBE code substitutions to read data |
| | @@ -114501,11 +114569,11 @@ |
| 114501 | 114569 | sqlite3 *db = pParse->db; /* The database connection */ |
| 114502 | 114570 | int mxSqlLen; /* Max length of an SQL string */ |
| 114503 | 114571 | |
| 114504 | 114572 | |
| 114505 | 114573 | mxSqlLen = db->aLimit[SQLITE_LIMIT_SQL_LENGTH]; |
| 114506 | | - if( db->activeVdbeCnt==0 ){ |
| 114574 | + if( db->nVdbeActive==0 ){ |
| 114507 | 114575 | db->u1.isInterrupted = 0; |
| 114508 | 114576 | } |
| 114509 | 114577 | pParse->rc = SQLITE_OK; |
| 114510 | 114578 | pParse->zTail = zSql; |
| 114511 | 114579 | i = 0; |
| | @@ -116069,10 +116137,11 @@ |
| 116069 | 116137 | case SQLITE_PERM: zName = "SQLITE_PERM"; break; |
| 116070 | 116138 | case SQLITE_ABORT: zName = "SQLITE_ABORT"; break; |
| 116071 | 116139 | case SQLITE_ABORT_ROLLBACK: zName = "SQLITE_ABORT_ROLLBACK"; break; |
| 116072 | 116140 | case SQLITE_BUSY: zName = "SQLITE_BUSY"; break; |
| 116073 | 116141 | case SQLITE_BUSY_RECOVERY: zName = "SQLITE_BUSY_RECOVERY"; break; |
| 116142 | + case SQLITE_BUSY_SNAPSHOT: zName = "SQLITE_BUSY_SNAPSHOT"; break; |
| 116074 | 116143 | case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break; |
| 116075 | 116144 | case SQLITE_LOCKED_SHAREDCACHE: zName = "SQLITE_LOCKED_SHAREDCACHE";break; |
| 116076 | 116145 | case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break; |
| 116077 | 116146 | case SQLITE_READONLY: zName = "SQLITE_READONLY"; break; |
| 116078 | 116147 | case SQLITE_READONLY_RECOVERY: zName = "SQLITE_READONLY_RECOVERY"; break; |
| | @@ -116142,10 +116211,11 @@ |
| 116142 | 116211 | case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break; |
| 116143 | 116212 | case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break; |
| 116144 | 116213 | case SQLITE_NOTICE_RECOVER_ROLLBACK: |
| 116145 | 116214 | zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break; |
| 116146 | 116215 | case SQLITE_WARNING: zName = "SQLITE_WARNING"; break; |
| 116216 | + case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break; |
| 116147 | 116217 | case SQLITE_DONE: zName = "SQLITE_DONE"; break; |
| 116148 | 116218 | } |
| 116149 | 116219 | } |
| 116150 | 116220 | if( zName==0 ){ |
| 116151 | 116221 | static char zBuf[50]; |
| | @@ -116400,11 +116470,11 @@ |
| 116400 | 116470 | ** is being overridden/deleted but there are no active VMs, allow the |
| 116401 | 116471 | ** operation to continue but invalidate all precompiled statements. |
| 116402 | 116472 | */ |
| 116403 | 116473 | p = sqlite3FindFunction(db, zFunctionName, nName, nArg, (u8)enc, 0); |
| 116404 | 116474 | if( p && p->iPrefEnc==enc && p->nArg==nArg ){ |
| 116405 | | - if( db->activeVdbeCnt ){ |
| 116475 | + if( db->nVdbeActive ){ |
| 116406 | 116476 | sqlite3Error(db, SQLITE_BUSY, |
| 116407 | 116477 | "unable to delete/modify user-function due to active statements"); |
| 116408 | 116478 | assert( !db->mallocFailed ); |
| 116409 | 116479 | return SQLITE_BUSY; |
| 116410 | 116480 | }else{ |
| | @@ -116981,11 +117051,11 @@ |
| 116981 | 117051 | ** sequence. If so, and there are active VMs, return busy. If there |
| 116982 | 117052 | ** are no active VMs, invalidate any pre-compiled statements. |
| 116983 | 117053 | */ |
| 116984 | 117054 | pColl = sqlite3FindCollSeq(db, (u8)enc2, zName, 0); |
| 116985 | 117055 | if( pColl && pColl->xCmp ){ |
| 116986 | | - if( db->activeVdbeCnt ){ |
| 117056 | + if( db->nVdbeActive ){ |
| 116987 | 117057 | sqlite3Error(db, SQLITE_BUSY, |
| 116988 | 117058 | "unable to delete/modify collation sequence due to active statements"); |
| 116989 | 117059 | return SQLITE_BUSY; |
| 116990 | 117060 | } |
| 116991 | 117061 | sqlite3ExpirePreparedStatements(db); |
| | @@ -117456,11 +117526,14 @@ |
| 117456 | 117526 | memcpy(db->aLimit, aHardLimit, sizeof(db->aLimit)); |
| 117457 | 117527 | db->autoCommit = 1; |
| 117458 | 117528 | db->nextAutovac = -1; |
| 117459 | 117529 | db->szMmap = sqlite3GlobalConfig.szMmap; |
| 117460 | 117530 | db->nextPagesize = 0; |
| 117461 | | - db->flags |= SQLITE_ShortColNames | SQLITE_AutoIndex | SQLITE_EnableTrigger |
| 117531 | + db->flags |= SQLITE_ShortColNames | SQLITE_EnableTrigger |
| 117532 | +#if !defined(SQLITE_DEAULT_AUTOMATIC_INDEX) || SQLITE_DEFAULT_AUTOMATIC_INDEX |
| 117533 | + | SQLITE_AutoIndex |
| 117534 | +#endif |
| 117462 | 117535 | #if SQLITE_DEFAULT_FILE_FORMAT<4 |
| 117463 | 117536 | | SQLITE_LegacyFileFmt |
| 117464 | 117537 | #endif |
| 117465 | 117538 | #ifdef SQLITE_ENABLE_LOAD_EXTENSION |
| 117466 | 117539 | | SQLITE_LoadExtension |
| 117467 | 117540 | |