Skip to content

Fixing substring keyspace match issue.#91

Merged
nickvanw merged 3 commits into
mainfrom
dtest_fix_shard_list
Jun 16, 2026
Merged

Fixing substring keyspace match issue.#91
nickvanw merged 3 commits into
mainfrom
dtest_fix_shard_list

Conversation

@dtest

@dtest dtest commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #90

@kelp

kelp commented Jun 16, 2026

Copy link
Copy Markdown

Nice fix — the two-layer approach (narrowed LIKE + exact-match filter in shardsForKeyspace) is the right shape. Worth noting the shardsForKeyspace exact-match is what actually makes it bulletproof: the LIKE "<db>/%" pattern alone still over-matches, since psc.Database is interpolated raw and _/% are LIKE wildcards (a keyspace named foo_bar would match fooXbar/...). The exact ks != keyspace check covers that, so the result is correct regardless. 👍

A couple of minor nits:

  1. The removed // TODO: is there a prepared statement equivalent? is still valid. The query still interpolates psc.Database into a string literal, so the parameterization concern (and the LIKE-wildcard / unescaped-quote edge) hasn't gone away. Consider keeping the TODO, or binding the parameter:

    p.db.QueryContext(ctx, `show vitess_shards like ?`, psc.Database+"/%")

    That also closes the case where a keyspace name contains a ".

  2. No integration coverage of the query change itself. The unit test exercises shardsForKeyspace but not the like "<db>/%" narrowing. Since test: add gated integration test suite #88 added the gated integration suite, a sibling-keyspace case there would lock in the half of the fix the unit test can't reach. Optional, given the defensive filter makes the result correct either way.

@nickvanw nickvanw merged commit af377f3 into main Jun 16, 2026
8 checks passed
@nickvanw nickvanw deleted the dtest_fix_shard_list branch June 16, 2026 19:17
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.

Building shard list gets invalid shards if the provided keyspace is a substring of other keyspaces

3 participants