Skip to content

sqlite: reject plans with unusable virtual table parameters - #66215

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
trivikr:sqlite-virtual-table-param-unavailable
Sep 29, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
trivikr:sqlite-virtual-table-param-unavailable

Conversation

@trivikr

@trivikr trivikr commented Sep 22, 2026

Copy link
Copy Markdown
Member

Fixes: #66214

Return SQLITE_CONSTRAINT from xBestIndex() when a hidden column has an equality constraint that is not usable at the current point in the query plan. Accepting such a plan makes xFilter() call rows() with null, silently dropping rows and returning an empty result, e.g. for "SELECT DISTINCT * FROM m(t.a) JOIN t ON t.a = m.a".

Cost estimates alone cannot enforce parameter dependencies; rejecting the plan lets SQLite pick an ordering where the parameter value is available.


Assisted-by: opencode

@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++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Sep 22, 2026
Return SQLITE_CONSTRAINT from xBestIndex() when a hidden column has
an equality constraint that is not usable at the current point in the
query plan. Accepting such a plan makes xFilter() call rows() with
null, silently dropping rows and returning an empty result, e.g. for
"SELECT DISTINCT * FROM m(t.a) JOIN t ON t.a = m.a". Cost estimates
alone cannot enforce parameter dependencies; rejecting the plan lets
SQLite pick an ordering where the parameter value is available.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: opencode
@trivikr
trivikr force-pushed the sqlite-virtual-table-param-unavailable branch from 8b0e7cc to cd29ffe Compare September 23, 2026 00:26
@trivikr
trivikr requested a review from araujogui September 23, 2026 01:22
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 23, 2026
@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.27%. Comparing base (c0ed28f) to head (cd29ffe).
⚠️ Report is 146 commits behind head on main.

Files with missing lines Patch % Lines
src/node_sqlite.cc 75.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66215      +/-   ##
==========================================
- Coverage   90.29%   90.27%   -0.02%     
==========================================
  Files         790      790              
  Lines      272883   272891       +8     
  Branches    52118    52108      -10     
==========================================
- Hits       246387   246348      -39     
- Misses      16943    16996      +53     
+ Partials     9553     9547       -6     
Files with missing lines Coverage Δ
src/node_sqlite.cc 82.04% <75.00%> (-0.02%) ⬇️

... and 32 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.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 25, 2026
@trivikr
trivikr requested a review from Qard September 25, 2026 03:46

@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.

LGTM

@trivikr trivikr added author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue PRs queued for automated landing through the Commit Queue. labels Sep 28, 2026
@nodejs-github-bot nodejs-github-bot added the lacks-second-approval Commit Queue PRs awaiting a second collaborator approval or completion of the required wait. label Sep 28, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 9bf40b2 into nodejs:main Sep 29, 2026
80 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 9bf40b2

@nodejs-github-bot nodejs-github-bot removed commit-queue PRs queued for automated landing through the Commit Queue. lacks-second-approval Commit Queue PRs awaiting a second collaborator approval or completion of the required wait. labels Sep 29, 2026
aduh95 pushed a commit that referenced this pull request Oct 3, 2026
Return SQLITE_CONSTRAINT from xBestIndex() when a hidden column has
an equality constraint that is not usable at the current point in the
query plan. Accepting such a plan makes xFilter() call rows() with
null, silently dropping rows and returning an empty result, e.g. for
"SELECT DISTINCT * FROM m(t.a) JOIN t ON t.a = m.a". Cost estimates
alone cannot enforce parameter dependencies; rejecting the plan lets
SQLite pick an ordering where the parameter value is available.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: opencode
PR-URL: #66215
Fixes: #66214
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
aduh95 pushed a commit that referenced this pull request Oct 3, 2026
Return SQLITE_CONSTRAINT from xBestIndex() when a hidden column has
an equality constraint that is not usable at the current point in the
query plan. Accepting such a plan makes xFilter() call rows() with
null, silently dropping rows and returning an empty result, e.g. for
"SELECT DISTINCT * FROM m(t.a) JOIN t ON t.a = m.a". Cost estimates
alone cannot enforce parameter dependencies; rejecting the plan lets
SQLite pick an ordering where the parameter value is available.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: opencode
PR-URL: #66215
Fixes: #66214
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
mceachen added a commit to photostructure/node-sqlite that referenced this pull request Oct 3, 2026
When a hidden column's equality constraint was not yet usable, xBestIndex()
accepted the plan and xFilter() called rows(null), so a query such as
SELECT DISTINCT ... FROM vt, t WHERE vt.param = t.a returned no rows.

Refs: nodejs/node#66215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. c++ Issues and PRs that require attention from people who are familiar with C++. 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 virtual table silently returns empty rows for unavailable join parameters

3 participants