Skip to content

sql: rewrite scid string literals to use scid() for index support - #9430

Open
vincenzopalazzo wants to merge 3 commits into
ElementsProject:masterfrom
vincenzopalazzo:claude/eloquent-meitner
Open

vincenzopalazzo wants to merge 3 commits into
ElementsProject:masterfrom
vincenzopalazzo:claude/eloquent-meitner

Conversation

@vincenzopalazzo

Copy link
Copy Markdown
Collaborator

Recreated from #9407 (original head fork went private; identical commits, no content changes). Originally opened 2026-08-12.

♻️ Re-creation of #8984, which was auto-closed on 2026-08-11 when my fork was detached from the repository network (GitHub cannot reopen PRs closed by a detachment). Branch content is unchanged (head 84562dfed); the previous review discussion remains on #8984.

Confirmed still relevant on master (2026-08-12): plugins/sql.c has no scid() handling, scid string literals still cannot use indexes.

Summary

  • When querying with WHERE in_channel='735095x480x1', the string literal was compared directly against the integer SCID column, forcing SQLite into a full table scan even with an index present
  • Root cause: json_sql() passes user queries directly to sqlite3_prepare_v2() without translating scid string literals to integers
  • Automatically rewrite scid string literals matching NNNxNNNxNNN format to use the scid() function before query execution, so '735095x480x1' becomes scid('735095x480x1') transparently

Fixes #8941
Changelog-Fixed: sql plugin now automatically translates short_channel_id string literals to integers for efficient index usage.

Test plan

  • CI passes
  • Queries like SELECT * FROM forwards WHERE in_channel='735095x480x1' now use indexes
  • Queries already using scid('...') explicitly are left unchanged
  • Non-scid string literals are unaffected

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL plugin: translate short_channel_id strings to integers before querying SQLite

2 participants