| | @@ -1171,11 +1171,11 @@ |
| 1171 | 1171 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 1172 | 1172 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 1173 | 1173 | */ |
| 1174 | 1174 | #define SQLITE_VERSION "3.34.0" |
| 1175 | 1175 | #define SQLITE_VERSION_NUMBER 3034000 |
| 1176 | | -#define SQLITE_SOURCE_ID "2020-10-19 20:49:54 75a0288871ccb2a69a636cbb328fe19045a0d0ef96a193ecd118b9a196784d2d" |
| 1176 | +#define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692392d" |
| 1177 | 1177 | |
| 1178 | 1178 | /* |
| 1179 | 1179 | ** CAPI3REF: Run-Time Library Version Numbers |
| 1180 | 1180 | ** KEYWORDS: sqlite3_version sqlite3_sourceid |
| 1181 | 1181 | ** |
| | @@ -17621,10 +17621,11 @@ |
| 17621 | 17621 | ** Index.aiRowLogEst[] values */ |
| 17622 | 17622 | #define TF_NoVisibleRowid 0x0200 /* No user-visible "rowid" column */ |
| 17623 | 17623 | #define TF_OOOHidden 0x0400 /* Out-of-Order hidden columns */ |
| 17624 | 17624 | #define TF_HasNotNull 0x0800 /* Contains NOT NULL constraints */ |
| 17625 | 17625 | #define TF_Shadow 0x1000 /* True for a shadow table */ |
| 17626 | +#define TF_HasStat4 0x2000 /* STAT4 info available for this table */ |
| 17626 | 17627 | |
| 17627 | 17628 | /* |
| 17628 | 17629 | ** Test to see whether or not a table is a virtual table. This is |
| 17629 | 17630 | ** done as a macro so that it will be optimized out when virtual |
| 17630 | 17631 | ** table support is omitted from the build. |
| | @@ -27864,16 +27865,21 @@ |
| 27864 | 27865 | ** xRoundup. */ |
| 27865 | 27866 | nNew = sqlite3GlobalConfig.m.xRoundup((int)nBytes); |
| 27866 | 27867 | if( nOld==nNew ){ |
| 27867 | 27868 | pNew = pOld; |
| 27868 | 27869 | }else if( sqlite3GlobalConfig.bMemstat ){ |
| 27870 | + sqlite3_int64 nUsed; |
| 27869 | 27871 | sqlite3_mutex_enter(mem0.mutex); |
| 27870 | 27872 | sqlite3StatusHighwater(SQLITE_STATUS_MALLOC_SIZE, (int)nBytes); |
| 27871 | 27873 | nDiff = nNew - nOld; |
| 27872 | | - if( nDiff>0 && sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED) >= |
| 27874 | + if( nDiff>0 && (nUsed = sqlite3StatusValue(SQLITE_STATUS_MEMORY_USED)) >= |
| 27873 | 27875 | mem0.alarmThreshold-nDiff ){ |
| 27874 | 27876 | sqlite3MallocAlarm(nDiff); |
| 27877 | + if( mem0.hardLimit>0 && nUsed >= mem0.hardLimit - nDiff ){ |
| 27878 | + sqlite3_mutex_leave(mem0.mutex); |
| 27879 | + return 0; |
| 27880 | + } |
| 27875 | 27881 | } |
| 27876 | 27882 | pNew = sqlite3GlobalConfig.m.xRealloc(pOld, nNew); |
| 27877 | 27883 | #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT |
| 27878 | 27884 | if( pNew==0 && mem0.alarmThreshold>0 ){ |
| 27879 | 27885 | sqlite3MallocAlarm((int)nBytes); |
| | @@ -48529,12 +48535,16 @@ |
| 48529 | 48535 | if( iDb<0 ){ |
| 48530 | 48536 | rc = SQLITE_ERROR; |
| 48531 | 48537 | goto end_deserialize; |
| 48532 | 48538 | } |
| 48533 | 48539 | zSql = sqlite3_mprintf("ATTACH x AS %Q", zSchema); |
| 48534 | | - rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); |
| 48535 | | - sqlite3_free(zSql); |
| 48540 | + if( zSql==0 ){ |
| 48541 | + rc = SQLITE_NOMEM; |
| 48542 | + }else{ |
| 48543 | + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); |
| 48544 | + sqlite3_free(zSql); |
| 48545 | + } |
| 48536 | 48546 | if( rc ) goto end_deserialize; |
| 48537 | 48547 | db->init.iDb = (u8)iDb; |
| 48538 | 48548 | db->init.reopenMemdb = 1; |
| 48539 | 48549 | rc = sqlite3_step(pStmt); |
| 48540 | 48550 | db->init.reopenMemdb = 0; |
| | @@ -78362,10 +78372,11 @@ |
| 78362 | 78372 | */ |
| 78363 | 78373 | SQLITE_PRIVATE void sqlite3VdbeAddParseSchemaOp(Vdbe *p, int iDb, char *zWhere){ |
| 78364 | 78374 | int j; |
| 78365 | 78375 | sqlite3VdbeAddOp4(p, OP_ParseSchema, iDb, 0, 0, zWhere, P4_DYNAMIC); |
| 78366 | 78376 | for(j=0; j<p->db->nDb; j++) sqlite3VdbeUsesBtree(p, j); |
| 78377 | + sqlite3MayAbort(p->pParse); |
| 78367 | 78378 | } |
| 78368 | 78379 | |
| 78369 | 78380 | /* |
| 78370 | 78381 | ** Add an opcode that includes the p4 value as an integer. |
| 78371 | 78382 | */ |
| | @@ -78590,11 +78601,11 @@ |
| 78590 | 78601 | while( (pOp = opIterNext(&sIter))!=0 ){ |
| 78591 | 78602 | int opcode = pOp->opcode; |
| 78592 | 78603 | if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename |
| 78593 | 78604 | || opcode==OP_VDestroy |
| 78594 | 78605 | || opcode==OP_VCreate |
| 78595 | | - || (opcode==OP_ParseSchema && pOp->p4.z==0) |
| 78606 | + || opcode==OP_ParseSchema |
| 78596 | 78607 | || ((opcode==OP_Halt || opcode==OP_HaltIfNull) |
| 78597 | 78608 | && ((pOp->p1)!=SQLITE_OK && pOp->p2==OE_Abort)) |
| 78598 | 78609 | ){ |
| 78599 | 78610 | hasAbort = 1; |
| 78600 | 78611 | break; |
| | @@ -79408,11 +79419,11 @@ |
| 79408 | 79419 | sqlite3_context *pCtx = pOp->p4.pCtx; |
| 79409 | 79420 | if( pOp->p4type!=P4_FUNCCTX || pCtx->argc==1 ){ |
| 79410 | 79421 | sqlite3_str_appendf(&x, "%d", v1); |
| 79411 | 79422 | }else if( pCtx->argc>1 ){ |
| 79412 | 79423 | sqlite3_str_appendf(&x, "%d..%d", v1, v1+pCtx->argc-1); |
| 79413 | | - }else{ |
| 79424 | + }else if( x.accError==0 ){ |
| 79414 | 79425 | assert( x.nChar>2 ); |
| 79415 | 79426 | x.nChar -= 2; |
| 79416 | 79427 | ii++; |
| 79417 | 79428 | } |
| 79418 | 79429 | ii += 3; |
| | @@ -107329,17 +107340,25 @@ |
| 107329 | 107340 | SrcList *pSrc = sqlite3TriggerStepSrc(pParse, pStep); |
| 107330 | 107341 | if( pSrc ){ |
| 107331 | 107342 | int i; |
| 107332 | 107343 | for(i=0; i<pSrc->nSrc && rc==SQLITE_OK; i++){ |
| 107333 | 107344 | struct SrcList_item *p = &pSrc->a[i]; |
| 107334 | | - p->pTab = sqlite3LocateTableItem(pParse, 0, p); |
| 107335 | 107345 | p->iCursor = pParse->nTab++; |
| 107336 | | - if( p->pTab==0 ){ |
| 107337 | | - rc = SQLITE_ERROR; |
| 107346 | + if( p->pSelect ){ |
| 107347 | + sqlite3SelectPrep(pParse, p->pSelect, 0); |
| 107348 | + sqlite3ExpandSubquery(pParse, p); |
| 107349 | + assert( i>0 ); |
| 107350 | + assert( pStep->pFrom->a[i-1].pSelect ); |
| 107351 | + sqlite3SelectPrep(pParse, pStep->pFrom->a[i-1].pSelect, 0); |
| 107338 | 107352 | }else{ |
| 107339 | | - p->pTab->nTabRef++; |
| 107340 | | - rc = sqlite3ViewGetColumnNames(pParse, p->pTab); |
| 107353 | + p->pTab = sqlite3LocateTableItem(pParse, 0, p); |
| 107354 | + if( p->pTab==0 ){ |
| 107355 | + rc = SQLITE_ERROR; |
| 107356 | + }else{ |
| 107357 | + p->pTab->nTabRef++; |
| 107358 | + rc = sqlite3ViewGetColumnNames(pParse, p->pTab); |
| 107359 | + } |
| 107341 | 107360 | } |
| 107342 | 107361 | } |
| 107343 | 107362 | sNC.pSrcList = pSrc; |
| 107344 | 107363 | if( rc==SQLITE_OK && pStep->pWhere ){ |
| 107345 | 107364 | rc = sqlite3ResolveExprNames(&sNC, pStep->pWhere); |
| | @@ -107396,10 +107415,16 @@ |
| 107396 | 107415 | Upsert *pUpsert = pStep->pUpsert; |
| 107397 | 107416 | sqlite3WalkExprList(pWalker, pUpsert->pUpsertTarget); |
| 107398 | 107417 | sqlite3WalkExprList(pWalker, pUpsert->pUpsertSet); |
| 107399 | 107418 | sqlite3WalkExpr(pWalker, pUpsert->pUpsertWhere); |
| 107400 | 107419 | sqlite3WalkExpr(pWalker, pUpsert->pUpsertTargetWhere); |
| 107420 | + } |
| 107421 | + if( pStep->pFrom ){ |
| 107422 | + int i; |
| 107423 | + for(i=0; i<pStep->pFrom->nSrc; i++){ |
| 107424 | + sqlite3WalkSelect(pWalker, pStep->pFrom->a[i].pSelect); |
| 107425 | + } |
| 107401 | 107426 | } |
| 107402 | 107427 | } |
| 107403 | 107428 | } |
| 107404 | 107429 | |
| 107405 | 107430 | /* |
| | @@ -109655,10 +109680,11 @@ |
| 109655 | 109680 | sqlite3_finalize(pStmt); |
| 109656 | 109681 | return SQLITE_NOMEM_BKPT; |
| 109657 | 109682 | } |
| 109658 | 109683 | pSpace = (tRowcnt*)&pIdx->aSample[nSample]; |
| 109659 | 109684 | pIdx->aAvgEq = pSpace; pSpace += nIdxCol; |
| 109685 | + pIdx->pTable->tabFlags |= TF_HasStat4; |
| 109660 | 109686 | for(i=0; i<nSample; i++){ |
| 109661 | 109687 | pIdx->aSample[i].anEq = pSpace; pSpace += nIdxCol; |
| 109662 | 109688 | pIdx->aSample[i].anLt = pSpace; pSpace += nIdxCol; |
| 109663 | 109689 | pIdx->aSample[i].anDLt = pSpace; pSpace += nIdxCol; |
| 109664 | 109690 | } |
| | @@ -149074,12 +149100,27 @@ |
| 149074 | 149100 | /* Integer primary key index */ |
| 149075 | 149101 | pNew->wsFlags = WHERE_IPK; |
| 149076 | 149102 | |
| 149077 | 149103 | /* Full table scan */ |
| 149078 | 149104 | pNew->iSortIdx = b ? iSortIdx : 0; |
| 149079 | | - /* TUNING: Cost of full table scan is (N*3.0). */ |
| 149105 | + /* TUNING: Cost of full table scan is 3.0*N. The 3.0 factor is an |
| 149106 | + ** extra cost designed to discourage the use of full table scans, |
| 149107 | + ** since index lookups have better worst-case performance if our |
| 149108 | + ** stat guesses are wrong. Reduce the 3.0 penalty slightly |
| 149109 | + ** (to 2.75) if we have valid STAT4 information for the table. |
| 149110 | + ** At 2.75, a full table scan is preferred over using an index on |
| 149111 | + ** a column with just two distinct values where each value has about |
| 149112 | + ** an equal number of appearances. Without STAT4 data, we still want |
| 149113 | + ** to use an index in that case, since the constraint might be for |
| 149114 | + ** the scarcer of the two values, and in that case an index lookup is |
| 149115 | + ** better. |
| 149116 | + */ |
| 149117 | +#ifdef SQLITE_ENABLE_STAT4 |
| 149118 | + pNew->rRun = rSize + 16 - 2*((pTab->tabFlags & TF_HasStat4)!=0); |
| 149119 | +#else |
| 149080 | 149120 | pNew->rRun = rSize + 16; |
| 149121 | +#endif |
| 149081 | 149122 | ApplyCostMultiplier(pNew->rRun, pTab->costMult); |
| 149082 | 149123 | whereLoopOutputAdjust(pWC, pNew, rSize); |
| 149083 | 149124 | rc = whereLoopInsert(pBuilder, pNew); |
| 149084 | 149125 | pNew->nOut = rSize; |
| 149085 | 149126 | if( rc ) break; |
| | @@ -226638,11 +226679,11 @@ |
| 226638 | 226679 | int nArg, /* Number of args */ |
| 226639 | 226680 | sqlite3_value **apUnused /* Function arguments */ |
| 226640 | 226681 | ){ |
| 226641 | 226682 | assert( nArg==0 ); |
| 226642 | 226683 | UNUSED_PARAM2(nArg, apUnused); |
| 226643 | | - sqlite3_result_text(pCtx, "fts5: 2020-10-12 18:09:16 7e17c2f4b7dc9b563d0b4da949bb134dc7c4fc9c86ce03891432a884ca6409d5", -1, SQLITE_TRANSIENT); |
| 226684 | + sqlite3_result_text(pCtx, "fts5: 2020-10-26 16:22:31 80eba105d6d1b49ba8ca2ad4e14ddec2de0bdc2f6686c2f8a1c1d24fc1fe846f", -1, SQLITE_TRANSIENT); |
| 226644 | 226685 | } |
| 226645 | 226686 | |
| 226646 | 226687 | /* |
| 226647 | 226688 | ** Return true if zName is the extension on one of the shadow tables used |
| 226648 | 226689 | ** by this module. |
| | @@ -230121,10 +230162,11 @@ |
| 230121 | 230162 | for(; i<128 && i<n; i++){ |
| 230122 | 230163 | aAscii[i] = (u8)bToken; |
| 230123 | 230164 | } |
| 230124 | 230165 | iTbl++; |
| 230125 | 230166 | } |
| 230167 | + aAscii[0] = 0; /* 0x00 is never a token character */ |
| 230126 | 230168 | } |
| 230127 | 230169 | |
| 230128 | 230170 | /* |
| 230129 | 230171 | ** 2015 May 30 |
| 230130 | 230172 | ** |
| | @@ -231560,12 +231602,12 @@ |
| 231560 | 231602 | } |
| 231561 | 231603 | #endif /* SQLITE_CORE */ |
| 231562 | 231604 | #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */ |
| 231563 | 231605 | |
| 231564 | 231606 | /************** End of stmt.c ************************************************/ |
| 231565 | | -#if __LINE__!=231565 |
| 231607 | +#if __LINE__!=231607 |
| 231566 | 231608 | #undef SQLITE_SOURCE_ID |
| 231567 | | -#define SQLITE_SOURCE_ID "2020-10-19 20:49:54 75a0288871ccb2a69a636cbb328fe19045a0d0ef96a193ecd118b9a19678alt2" |
| 231609 | +#define SQLITE_SOURCE_ID "2020-10-31 18:58:37 7d01e84dc49074e6364267eea9fd20d46a457d2498121a0f218fbf482692alt2" |
| 231568 | 231610 | #endif |
| 231569 | 231611 | /* Return the source-id for this library */ |
| 231570 | 231612 | SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; } |
| 231571 | 231613 | /************************** End of sqlite3.c ******************************/ |
| 231572 | 231614 | |