Skip to content

sqlite: expose prepared statement statistics - #64541

Open
geeksilva97 wants to merge 1 commit into
nodejs:mainfrom
geeksilva97:sqlite-statement-statistics
Open

sqlite: expose prepared statement statistics#64541
geeksilva97 wants to merge 1 commit into
nodejs:mainfrom
geeksilva97:sqlite-statement-statistics

Conversation

@geeksilva97

@geeksilva97 geeksilva97 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Closes #64540

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 16, 2026
@geeksilva97
geeksilva97 force-pushed the sqlite-statement-statistics branch 2 times, most recently from f5e8fcb to 2195e97 Compare July 16, 2026 18:42
@geeksilva97
geeksilva97 marked this pull request as ready for review July 16, 2026 18:43
@bakkot

bakkot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

I'm a little uncomfortable with getters that create an object every time they're read.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.23%. Comparing base (46de80d) to head (fd5654c).
⚠️ Report is 191 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 92.30% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #64541   +/-   ##
=======================================
  Coverage   90.23%   90.23%           
=======================================
  Files         739      739           
  Lines      241744   241770   +26     
  Branches    45552    45572   +20     
=======================================
+ Hits       218136   218161   +25     
- Misses      15148    15154    +6     
+ Partials     8460     8455    -5     
Files with missing lines Coverage Δ
src/node_sqlite.h 80.64% <ø> (ø)
src/node_sqlite.cc 80.82% <92.30%> (+0.11%) ⬆️

... and 30 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@geeksilva97 geeksilva97 added the wip Issues and PRs that are still a work in progress. label Jul 16, 2026
@geeksilva97
geeksilva97 force-pushed the sqlite-statement-statistics branch 2 times, most recently from bbbbeec to bef2511 Compare July 16, 2026 21:12
Comment thread src/node_sqlite.h
{"run", SQLITE_STMTSTATUS_RUN},
{"filterMiss", SQLITE_STMTSTATUS_FILTER_MISS},
{"filterHit", SQLITE_STMTSTATUS_FILTER_HIT},
{"memused", SQLITE_STMTSTATUS_MEMUSED},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{"memused", SQLITE_STMTSTATUS_MEMUSED},
{"memUsed", SQLITE_STMTSTATUS_MEMUSED},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since SQLite does not use an underscore here, I think memused is a more faithful name to the SQLite API.

https://sqlite.org/c3ref/c_stmtstatus_counter.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that was the pattern followed

Signed-off-by: geeksilva97 <edigleyssonsilva@gmail.com>
@geeksilva97
geeksilva97 force-pushed the sqlite-statement-statistics branch from bef2511 to fd5654c Compare July 17, 2026 16:25
@geeksilva97 geeksilva97 removed the wip Issues and PRs that are still a work in progress. label Jul 17, 2026
@geeksilva97

Copy link
Copy Markdown
Contributor Author

Please @nodejs/sqlite , share your thoughts

@araujogui araujogui left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another method to reset stats would be nice to have

Comment thread src/node_sqlite.h
{"reprepare", SQLITE_STMTSTATUS_REPREPARE},
{"run", SQLITE_STMTSTATUS_RUN},
{"filterMiss", SQLITE_STMTSTATUS_FILTER_MISS},
{"filterHit", SQLITE_STMTSTATUS_FILTER_HIT},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SQLITE_STMTSTATUS_FILTER_MISS and SQLITE_STMTSTATUS_FILTER_HIT was introduced in SQLite 3.38.0.

3.37.2: https://github.com/sqlite/sqlite/blob/version-3.37.2/src/sqlite.h.in
3.38.0: https://github.com/sqlite/sqlite/blob/version-3.38.0/src/sqlite.h.in

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe we need to enforce a minimum SQLite version on --shared-sqlite

Comment thread src/node_sqlite.cc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another method to reset stats would be nice to have

];

test('returns a number for every valid counter', (t) => {
using db = new DatabaseSync(nextDb());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using db = new DatabaseSync(nextDb());
using db = new DatabaseSync(':memory:');

Comment thread src/node_sqlite.cc
return nullptr;
}

static constexpr const StatusInfo* GetStatusInfoFromName(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This is structurally identical to GetLimitInfoFromName just above, we can replace both with a single function template.

template <typename T, size_t N>
static constexpr const T* FindByJsName(const std::array<T, N>& mapping,
                                       std::string_view name) {
  for (const auto& info : mapping) {
    if (name == info.js_name) {
      return &info;
    }
  }
  return nullptr;
}

@trivikr trivikr added the sqlite Issues and PRs related to the SQLite subsystem. label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: expose prepared statement stats

6 participants