Skip to content

[PR] fix(storage): match KV key prefixes literally - #6247

Closed
Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-11_literal-kv-prefixes
Closed

Afloat16 wants to merge 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-11_literal-kv-prefixes

Conversation

@Afloat16

Copy link
Copy Markdown
Contributor

Fixes #6243

Problem

listKv({ keyPrefix: "Prefix:" }) also returns prefix: keys because both backends use LIKE alone for prefix filtering. SQLite folds ASCII case, while MySQL's default collation can also fold accents. Prefix queries therefore return keys that do not start with the supplied literal string.

Change

Keep the escaped LIKE predicate as a coarse filter and add an exact prefix check: instr(key, ?) = 1 in SQLite, and LOCATE on binary operands in MySQL. This keeps wildcard escaping and empty-prefix behavior, without changing the schema or stored keys.

A shared backend contract covers uppercase/lowercase prefixes, accented keys, literal %, _ and backslash characters, missing prefixes and the empty-prefix case.

Validation

  • On unchanged master dc041dd1ab1a014efa352ba47a6f31fc47f55284, the new prefix contract fails on both real SQLite and MySQL 8.0 with assertion failures; the validation job verifies that exact negative-control result.
  • The corrected storage suite passes on both engines in fork CI. That validation branch combines the three independently based storage fixes ([PR] fix(storage): treat malformed integrity caches as misses #6239, [PR] perf(storage): avoid quadratic media-array copies #6242 and this patch); it is not an extra contribution PR.
  • Independently against this patch locally: 22 tests passed, 1 MySQL-only test skipped because no local MySQL DSN was configured.
  • npm run typecheck, npm run build, and git diff --check: passed locally; typecheck and build also pass in the MySQL validation job.

Checked the prior PR history and open/closed issues for matching listKv prefix/collation fixes. This change does not alter key identity or uniqueness rules.

@ranxianglei

Copy link
Copy Markdown
Owner

Landed via batch PR #6439 (merged) — closing as superseded.

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.

[Bug][storage] listKv prefix filtering returns keys with a different letter case

2 participants