Skip to content

pg: fix list_key_versions interpreting keys as patterns - #114

Merged
tankyleo merged 1 commit into
lightningdevkit:mainfrom
phlip9:phlip9/fix-list-key-versions
Sep 24, 2026
Merged

tankyleo merged 1 commit into
lightningdevkit:mainfrom
phlip9:phlip9/fix-list-key-versions

Conversation

@phlip9

@phlip9 phlip9 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Using key LIKE $3 unescaped tells Postgres to interpret the requested key prefix as a pattern, which means %, _, and \ are interpreted as wildcards and character escapes in the original prefix rather the actual intended literal prefix.

This means a list_key_versions(key="foo_bar", ..) actually includes foo1bar, which definitely does not seem intentional.

A better approach is to just use starts_with(key, $3), which the query planner understands better and doesn't require any escaping.

@ldk-reviews-bot

ldk-reviews-bot commented Sep 2, 2026 •

Copy link
Copy Markdown

I've assigned @tankyleo as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

@phlip9

phlip9 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

cc @tnull (can't add reviewers in the sidebar 😢)

@tankyleo tankyleo left a comment

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.

thanks sorry for the delay this needs a rebase

Comment thread impls/src/postgres_store.rs
Comment thread impls/src/postgres_store.rs Outdated
Using `key LIKE $3` unescaped tells Postgres to interpret the requested
key prefix as a pattern, which means %, _, and \ are interpreted as
wildcards and character escapes in the original prefix rather the actual
intended literal prefix.

This means a `list_key_versions(key="foo_bar", ..)` actually includes
`foo1bar`, which definitely does not seem intentional.

A better approach is to just use `starts_with(key, $3)`, which the query
planner understands better and doesn't require us to do any escaping.
@phlip9
phlip9 force-pushed the phlip9/fix-list-key-versions branch from e833d09 to 3ae3390 Compare September 24, 2026 01:59
@tankyleo
tankyleo merged commit 0a638f7 into lightningdevkit:main Sep 24, 2026
8 checks passed
@phlip9
phlip9 deleted the phlip9/fix-list-key-versions branch September 25, 2026 02:09
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.

3 participants