Skip to content

Commit

Permalink
Update SQLite with more logs, v3
Browse files Browse the repository at this point in the history
  • Loading branch information
flodnv committed Oct 21, 2024
1 parent 02829cc commit 3a71cef
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ INCLUDE = -I$(PROJECT) -I$(PROJECT)/mbedtls/include
CXXFLAGS = -g -std=c++20 -fPIC -DSQLITE_ENABLE_NORMALIZE $(BEDROCK_OPTIM_COMPILE_FLAG) -Wall -Werror -Wformat-security -Wno-unqualified-std-cast-call -Wno-error=deprecated-declarations $(INCLUDE)

# Amalgamation flags
AMALGAMATION_FLAGS = -Wno-unused-but-set-variable -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_ENABLE_NOOP_UPDATE -DSQLITE_MUTEX_ALERT_MILLISECONDS=20 -DHAVE_USLEEP=1 -DSQLITE_MAX_MMAP_SIZE=17592186044416ull -DSQLITE_SHARED_MAPPING -DSQLITE_ENABLE_NORMALIZE -DSQLITE_MAX_PAGE_COUNT=4294967294 -DSQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS
AMALGAMATION_FLAGS = -Wno-unused-but-set-variable -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_STAT4 -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_SESSION -DSQLITE_ENABLE_PREUPDATE_HOOK -DSQLITE_ENABLE_UPDATE_DELETE_LIMIT -DSQLITE_ENABLE_NOOP_UPDATE -DSQLITE_MUTEX_ALERT_MILLISECONDS=20 -DHAVE_USLEEP=1 -DSQLITE_MAX_MMAP_SIZE=17592186044416ull -DSQLITE_SHARED_MAPPING -DSQLITE_ENABLE_NORMALIZE -DSQLITE_MAX_PAGE_COUNT=4294967294 -DSQLITE_DISABLE_PAGECACHE_OVERFLOW_STATS -DSQLITE_ENABLE_STMT_SCANSTATUS=1

# All our intermediate, dependency, object, etc files get hidden in here.
INTERMEDIATEDIR = .build
Expand Down
38 changes: 33 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
** 6deb4794f8e24dbb946069de1e5c34fbcd47.
** 08e1dea9c070c9a2d668d39ceb153bc8b6d1.
*/
#define SQLITE_CORE 1
#define SQLITE_AMALGAMATION 1
Expand Down Expand Up @@ -465,7 +465,7 @@ extern "C" {
*/
#define SQLITE_VERSION "3.47.0"
#define SQLITE_VERSION_NUMBER 3047000
#define SQLITE_SOURCE_ID "2024-10-10 15:28:18 6deb4794f8e24dbb946069de1e5c34fbcd4734162002f3bc7deb1a3f69adec05"
#define SQLITE_SOURCE_ID "2024-10-21 11:49:04 08e1dea9c070c9a2d668d39ceb153bc8b6d172e7273f6564a374c43055e84461"

/*
** CAPI3REF: Run-Time Library Version Numbers
Expand Down Expand Up @@ -18185,6 +18185,7 @@ struct sqlite3 {

#define sqlite3PrepareTimeSet(x,y) sqlite3CommitTimeSet(x,y)
SQLITE_PRIVATE void sqlite3PrepareTimeLog(const char *zSql, int nSql, u64 *aPrepareTime);
SQLITE_PRIVATE void sqlite3SchemaTimeLog(Vdbe *pVdbe);

#define PREPARE_TIME_TIMEOUT (2 * 1000 * 1000) /* 2 second timeout */

Expand Down Expand Up @@ -93187,7 +93188,7 @@ SQLITE_PRIVATE void sqlite3CommitTimeLog(u64 *aCommit){
(aCommit[ii]==0 ? 0 : (int)(aCommit[ii] - i1))
);
}
sqlite3_log(SQLITE_WARNING, "slow commit (v=2): (%s)", zStr);
sqlite3_log(SQLITE_WARNING, "slow commit (v=3): (%s)", zStr);
sqlite3_free(zStr);
}
}
Expand Down Expand Up @@ -93215,11 +93216,25 @@ SQLITE_PRIVATE void sqlite3PrepareTimeLog(const char *zSql, int nSql, u64 *aPrep
}
if( nByte<0 ){ nByte = sqlite3Strlen30(zSql); }
sqlite3_log(SQLITE_WARNING,
"slow prepare (v=2): (%s) [%.*s]", zStr, nByte, zSql
"slow prepare (v=3): (%s) [%.*s]", zStr, nByte, zSql
);
sqlite3_free(zStr);
}
}
SQLITE_PRIVATE void sqlite3SchemaTimeLog(Vdbe *pVdbe){
int ii;
char *zStr = 0;
for(ii=0; ii<pVdbe->nOp; ii++){
VdbeOp *pOp = &pVdbe->aOp[ii];
zStr = sqlite3_mprintf("%z%s(%s %lld %lld)", zStr, (zStr?" ":""),
(char*)sqlite3OpcodeName(pOp->opcode), pOp->nExec, pOp->nCycle
);
}
sqlite3_log(SQLITE_WARNING,
"slow schema query (v=3): (%s) [%s]", zStr, pVdbe->zSql
);
sqlite3_free(zStr);
}


#ifndef SQLITE_OMIT_VIRTUALTABLE
Expand Down Expand Up @@ -139681,6 +139696,11 @@ SQLITE_API int sqlite3_exec(
while( rc==SQLITE_OK && zSql[0] ){
int nCol = 0;
char **azVals = 0;
i64 tmStart = sqlite3STimeNow();
u64 svFlags = db->flags;
if( db->init.busy ){
db->flags |= SQLITE_StmtScanStatus;
}

pStmt = 0;
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
Expand Down Expand Up @@ -139741,6 +139761,9 @@ SQLITE_API int sqlite3_exec(
}

if( rc!=SQLITE_ROW ){
if( db->init.busy && (sqlite3STimeNow()-tmStart)>PREPARE_TIME_TIMEOUT ){
sqlite3SchemaTimeLog((Vdbe*)pStmt);
}
rc = sqlite3VdbeFinalize((Vdbe *)pStmt);
pStmt = 0;
zSql = zLeftover;
Expand All @@ -139749,6 +139772,11 @@ SQLITE_API int sqlite3_exec(
}
}

if( db->init.busy ){
/* Clear the SQLITE_StmtScanStatus flag if it was clear at the top
** of this loop. */
db->flags &= (~SQLITE_StmtScanStatus | svFlags);
}
sqlite3DbFree(db, azCols);
azCols = 0;
}
Expand Down Expand Up @@ -257570,7 +257598,7 @@ static void fts5SourceIdFunc(
){
assert( nArg==0 );
UNUSED_PARAM2(nArg, apUnused);
sqlite3_result_text(pCtx, "fts5: 2024-10-10 15:28:18 6deb4794f8e24dbb946069de1e5c34fbcd4734162002f3bc7deb1a3f69adec05", -1, SQLITE_TRANSIENT);
sqlite3_result_text(pCtx, "fts5: 2024-10-21 11:49:04 08e1dea9c070c9a2d668d39ceb153bc8b6d172e7273f6564a374c43055e84461", -1, SQLITE_TRANSIENT);
}

/*
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.47.0"
#define SQLITE_VERSION_NUMBER 3047000
#define SQLITE_SOURCE_ID "2024-10-10 15:28:18 6deb4794f8e24dbb946069de1e5c34fbcd4734162002f3bc7deb1a3f69adec05"
#define SQLITE_SOURCE_ID "2024-10-21 11:49:04 08e1dea9c070c9a2d668d39ceb153bc8b6d172e7273f6564a374c43055e84461"

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

0 comments on commit 3a71cef

Please sign in to comment.