From fd5654c15df700d915cc8dedf8de98532432bad1 Mon Sep 17 00:00:00 2001 From: geeksilva97 Date: Thu, 16 Jul 2026 11:24:40 -0700 Subject: [PATCH] sqlite: expose prepared statement statistics Signed-off-by: geeksilva97 --- doc/api/sqlite.md | 34 ++++++++ src/node_sqlite.cc | 39 +++++++++ src/node_sqlite.h | 19 +++++ test/parallel/test-sqlite-statement-sync.js | 92 +++++++++++++++++++++ 4 files changed, 184 insertions(+) diff --git a/doc/api/sqlite.md b/doc/api/sqlite.md index 850358ff43aa86..7f142602f199b7 100644 --- a/doc/api/sqlite.md +++ b/doc/api/sqlite.md @@ -1202,6 +1202,39 @@ added: v22.5.0 The source SQL text of the prepared statement. This property is a wrapper around [`sqlite3_sql()`][]. +### `statement.stat(counter)` + + + +* `counter` {string} The name of the counter to read. One of: + + * `'fullscanStep'` The number of times SQLite has stepped forward in a table + as part of a full table scan. + * `'sort'` The number of sort operations that have occurred. + * `'autoindex'` The number of rows inserted into transient indices that were + created automatically to help joins run faster. + * `'vmStep'` The number of virtual machine operations executed by the + prepared statement. + * `'reprepare'` The number of times the statement has been automatically + reprepared due to schema changes or changes to bound parameters. + * `'run'` The number of times the statement has run to completion. + * `'filterMiss'` The number of times the Bloom filter returned a result that + required the join step to be processed as normal. + * `'filterHit'` The number of times a join step was bypassed because a Bloom + filter returned not-found. + * `'memused'` The approximate number of bytes of heap memory used to store + the prepared statement. + +* Returns: {number} The current value of the requested counter. + +Returns one of the runtime counters that SQLite tracks for this prepared +statement. This method is a wrapper around [`sqlite3_stmt_status()`][] and does +not reset the counter. Asserting that a statement does not perform a full table +scan (`statement.stat('fullscanStep') === 0`) is a useful check to guard +against degenerate performance. + ## Class: `SQLTagStore`