Skip to content

Commit

Permalink
Merge pull request #1794 from Expensify/bloom-version
Browse files Browse the repository at this point in the history
Update sqlite3
  • Loading branch information
rafecolton authored Jul 3, 2024
2 parents e2a2e57 + adf3d41 commit e455458
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
50 changes: 45 additions & 5 deletions libstuff/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
** separate file. This file contains only code for the core SQLite library.
**
** The content in this amalgamation comes from Fossil check-in
** 8362edb45b993f8467b464ca0491ef347c82.
** 0bb306eb70ef1df7734326d30359da7a1539.
*/
#define SQLITE_CORE 1
#define SQLITE_AMALGAMATION 1
Expand Down Expand Up @@ -462,7 +462,7 @@ extern "C" {
*/
#define SQLITE_VERSION "3.45.2"
#define SQLITE_VERSION_NUMBER 3045002
#define SQLITE_SOURCE_ID "2024-06-26 16:33:49 8362edb45b993f8467b464ca0491ef347c8215ea2e65504f7b3d1f7232eb3c63"
#define SQLITE_SOURCE_ID "2024-07-03 20:30:31 0bb306eb70ef1df7734326d30359da7a15397171d3e25ab644633ef3ee1428ec"

/*
** CAPI3REF: Run-Time Library Version Numbers
Expand Down Expand Up @@ -19711,7 +19711,11 @@ struct Select {
** SRT_Set The result must be a single column. Store each
** row of result as the key in table pDest->iSDParm.
** Apply the affinity pDest->affSdst before storing
** results. Used to implement "IN (SELECT ...)".
** results. if pDest->iSDParm2 is positive, then it is
** a regsiter holding a Bloom filter for the IN operator
** that should be populated in addition to the
** pDest->iSDParm table. This SRT is used to
** implement "IN (SELECT ...)".
**
** SRT_EphemTab Create an temporary table pDest->iSDParm and store
** the result there. The cursor is left open after
Expand Down Expand Up @@ -100521,6 +100525,7 @@ case OP_Found: { /* jump, in3, ncycle */
r.pKeyInfo = pC->pKeyInfo;
r.default_rc = 0;
#ifdef SQLITE_DEBUG
(void)sqlite3FaultSim(50); /* For use by --counter in TH3 */
for(ii=0; ii<r.nField; ii++){
assert( memIsValid(&r.aMem[ii]) );
assert( (r.aMem[ii].flags & MEM_Zero)==0 || r.aMem[ii].n==0 );
Expand Down Expand Up @@ -107959,10 +107964,10 @@ static int bytecodevtabColumn(

#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
case 9: /* nexec */
sqlite3_result_int(ctx, pOp->nExec);
sqlite3_result_int64(ctx, pOp->nExec);
break;
case 10: /* ncycle */
sqlite3_result_int(ctx, pOp->nCycle);
sqlite3_result_int64(ctx, pOp->nCycle);
break;
#else
case 9: /* nexec */
Expand Down Expand Up @@ -114461,15 +114466,30 @@ SQLITE_PRIVATE void sqlite3CodeRhsOfIN(
SelectDest dest;
int i;
int rc;
int addrBloom = 0;
sqlite3SelectDestInit(&dest, SRT_Set, iTab);
dest.zAffSdst = exprINAffinity(pParse, pExpr);
pSelect->iLimit = 0;
if( addrOnce && OptimizationEnabled(pParse->db, SQLITE_BloomFilter) ){
int regBloom = ++pParse->nMem;
addrBloom = sqlite3VdbeAddOp2(v, OP_Blob, 10000, regBloom);
VdbeComment((v, "Bloom filter"));
dest.iSDParm2 = regBloom;
}
testcase( pSelect->selFlags & SF_Distinct );
testcase( pKeyInfo==0 ); /* Caused by OOM in sqlite3KeyInfoAlloc() */
pCopy = sqlite3SelectDup(pParse->db, pSelect, 0);
rc = pParse->db->mallocFailed ? 1 :sqlite3Select(pParse, pCopy, &dest);
sqlite3SelectDelete(pParse->db, pCopy);
sqlite3DbFree(pParse->db, dest.zAffSdst);
if( addrBloom ){
sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
if( dest.iSDParm2==0 ){
sqlite3VdbeChangeToNoop(v, addrBloom);
}else{
sqlite3VdbeGetOp(v, addrOnce)->p3 = dest.iSDParm2;
}
}
if( rc ){
sqlite3KeyInfoUnref(pKeyInfo);
return;
Expand Down Expand Up @@ -114912,6 +114932,15 @@ static void sqlite3ExprCodeIN(
sqlite3VdbeAddOp4(v, OP_Affinity, rLhs, nVector, 0, zAff, nVector);
if( destIfFalse==destIfNull ){
/* Combine Step 3 and Step 5 into a single opcode */
if( ExprHasProperty(pExpr, EP_Subrtn) ){
const VdbeOp *pOp = sqlite3VdbeGetOp(v, pExpr->y.sub.iAddr);
assert( pOp->opcode==OP_Once || pParse->nErr );
if( pOp->opcode==OP_Once && pOp->p3>0 ){
assert( OptimizationEnabled(pParse->db, SQLITE_BloomFilter) );
sqlite3VdbeAddOp4Int(v, OP_Filter, pOp->p3, destIfFalse,
rLhs, nVector); VdbeCoverage(v);
}
}
sqlite3VdbeAddOp4Int(v, OP_NotFound, iTab, destIfFalse,
rLhs, nVector); VdbeCoverage(v);
goto sqlite3ExprCodeIN_finished;
Expand Down Expand Up @@ -145859,12 +145888,18 @@ static void selectInnerLoop(
** case the order does matter */
pushOntoSorter(
pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);
pDest->iSDParm2 = 0; /* Signal that any Bloom filter is unpopulated */
}else{
int r1 = sqlite3GetTempReg(pParse);
assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );
sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol,
r1, pDest->zAffSdst, nResultCol);
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);
if( pDest->iSDParm2 ){
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
regResult, nResultCol);
ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
}
sqlite3ReleaseTempReg(pParse, r1);
}
break;
Expand Down Expand Up @@ -147792,6 +147827,11 @@ static int generateOutputSubroutine(
r1, pDest->zAffSdst, pIn->nSdst);
sqlite3VdbeAddOp4Int(v, OP_IdxInsert, pDest->iSDParm, r1,
pIn->iSdst, pIn->nSdst);
if( pDest->iSDParm2>0 ){
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pDest->iSDParm2, 0,
pIn->iSdst, pIn->nSdst);
ExplainQueryPlan((pParse, 0, "CREATE BLOOM FILTER"));
}
sqlite3ReleaseTempReg(pParse, r1);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion libstuff/sqlite3.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extern "C" {
*/
#define SQLITE_VERSION "3.45.2"
#define SQLITE_VERSION_NUMBER 3045002
#define SQLITE_SOURCE_ID "2024-06-26 16:33:49 8362edb45b993f8467b464ca0491ef347c8215ea2e65504f7b3d1f7232eb3c63"
#define SQLITE_SOURCE_ID "2024-07-03 20:30:31 0bb306eb70ef1df7734326d30359da7a15397171d3e25ab644633ef3ee1428ec"

/*
** CAPI3REF: Run-Time Library Version Numbers
Expand Down

0 comments on commit e455458

Please sign in to comment.