Skip to content

Commit 27deab7

Browse files
markhannumclaude
andcommitted
lua: clear page-in fingerprint TLS at each inner statement's true end
Lua stored-procedure inner statements (db:exec/db:prepare, temp table handling) already set the page-in fingerprint thread-local correctly via the shared get_prepared_stmt_int() chokepoint, but had no per-inner-statement clear -- only the whole-procedure sqlite_done() call cleared it. This let page-ins between one inner statement finishing and the next one's own prepare bleed onto the previous statement's fingerprint instead of falling into NO-FINGERPRINT. Adds bdb_fingerprint_rtstats_clear() at every point an inner statement's execution conclusively ends: donate_stmt() (the shared terminal disposal point for exec/prepare/cursor handles -- covers dbstmt_free, dbstmt_exec's error path, dbstmt_fetch exhaustion, dbstmt_close, and reset_stmt's terminal branch) plus the six direct sqlite3_finalize() sites that bypass it (create_temp_table, dbtable_insert, dbtable_copyfrom, db_csvcopy, drop_temp_tables, clone_temp_tables). Deliberately does not hook lua_end_step(), since it fires multiple times against the same open statement in some paths (db_csvcopy, once per CSV row) and would clear prematurely. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Signed-off-by: Mark Hannum <mhannum@bloomberg.net>
1 parent d076bd4 commit 27deab7

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

lua/sp.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,8 @@ static void donate_stmt(SP sp, dbstmt_t *dbstmt)
11461146
sqlite3_stmt *stmt = dbstmt->stmt;
11471147
if (stmt == NULL) return;
11481148

1149+
bdb_fingerprint_rtstats_clear();
1150+
11491151
if (!gbl_enable_sql_stmt_caching || !dbstmt->rec) {
11501152
sqlite3_finalize(stmt);
11511153
} else {
@@ -1249,6 +1251,7 @@ static struct sp_tmptbl *create_temp_table(Lua lua, const char **name)
12491251
}
12501252
lua_end_step(sp->clnt, sp, stmt);
12511253
set_tmptbl(NULL);
1254+
bdb_fingerprint_rtstats_clear();
12521255
sqlite3_finalize(stmt);
12531256

12541257
if (rc == SQLITE_DONE) {
@@ -2240,6 +2243,7 @@ out:if (rc) {
22402243
sql_check_errors(sp->clnt, sqldb, stmt, &errstr);
22412244
luabb_error(lua, sp, errstr);
22422245
}
2246+
bdb_fingerprint_rtstats_clear();
22432247
sqlite3_finalize(stmt);
22442248
lua_pushinteger(lua, rc);
22452249
return 1;
@@ -2295,6 +2299,7 @@ static int dbtable_copyfrom(Lua lua)
22952299
}
22962300
lua_end_step(sp->clnt, sp, stmt);
22972301

2302+
bdb_fingerprint_rtstats_clear();
22982303
sqlite3_finalize(stmt);
22992304

23002305
lua_pushinteger(lua, 0); /* Success return code. */
@@ -2878,6 +2883,7 @@ static void drop_temp_tables(SP sp)
28782883
do {
28792884
rc = sqlite3_step(stmt);
28802885
} while (rc == SQLITE_ROW);
2886+
bdb_fingerprint_rtstats_clear();
28812887
sqlite3_finalize(stmt);
28822888
if (rc != SQLITE_DONE) {
28832889
expire = 1;
@@ -3510,8 +3516,10 @@ int db_csvcopy(Lua lua)
35103516
done:
35113517
if (csv.z)
35123518
free(csv.z);
3513-
if (stmt)
3519+
if (stmt) {
3520+
bdb_fingerprint_rtstats_clear();
35143521
sqlite3_finalize(stmt);
3522+
}
35153523
if (fp)
35163524
fclose(fp);
35173525
if (rc == 0)
@@ -6481,6 +6489,7 @@ static void clone_temp_tables(SP sp)
64816489
sqlite3_stmt *stmt;
64826490
lua_prepare_sql_with_temp_ddl(sp, strbuf_buf(sql), &stmt);
64836491
clone_temp_table(stmt, &tmp->tbl);
6492+
bdb_fingerprint_rtstats_clear();
64846493
sqlite3_finalize(stmt);
64856494
sp->clnt->skip_peer_chk = 0;
64866495
strbuf_free(sql);

0 commit comments

Comments
 (0)