Skip to content

Conversation

@nickvanw
Copy link
Collaborator

@nickvanw nickvanw commented Oct 25, 2025

Description

This PR adds the ability for a user to target a specific tablet by alias when doing USE, instead of only being able to pick a type for a shard. This means that a user can get "stable" routing, which is extremely useful when they don't have access to the underlying MySQL instance and need to do things like debug.

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

AI Disclosure

This PR was written hand-in-hand with Claude Code, which absolutely got the initial few approaches extremely incorrect and required a lot of human help. Robot isn't going to take my job any time soon.

@vitess-bot
Copy link
Contributor

vitess-bot bot commented Oct 25, 2025

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Oct 25, 2025
@github-actions github-actions bot added this to the v24.0.0 milestone Oct 25, 2025
@codecov
Copy link

codecov bot commented Oct 25, 2025

Codecov Report

❌ Patch coverage is 94.02985% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.90%. Comparing base (cd546ab) to head (c8edb0b).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/vtgate/executorcontext/vcursor_impl.go 83.33% 2 Missing ⚠️
go/vt/topo/topoproto/destination.go 96.00% 1 Missing ⚠️
go/vtbench/client.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18809      +/-   ##
==========================================
- Coverage   69.91%   69.90%   -0.01%     
==========================================
  Files        1613     1613              
  Lines      216071   216124      +53     
==========================================
+ Hits       151073   151089      +16     
- Misses      64998    65035      +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@nickvanw nickvanw force-pushed the nickvanw/direct-access branch 5 times, most recently from f77286f to 1eb17dd Compare October 27, 2025 07:41
@nickvanw nickvanw removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Oct 27, 2025
@nickvanw nickvanw force-pushed the nickvanw/direct-access branch 8 times, most recently from 84f29f0 to 6c49907 Compare October 27, 2025 14:03
@nickvanw nickvanw marked this pull request as ready for review October 27, 2025 14:28
Signed-off-by: Nick Van Wiggeren <[email protected]>
…re it is not valid to set

Signed-off-by: Nick Van Wiggeren <[email protected]>
Signed-off-by: Nick Van Wiggeren <[email protected]>
@nickvanw nickvanw removed the release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) label Dec 8, 2025
@nickvanw
Copy link
Collaborator Author

I believe this is ready for another review @harshit-gangal! Let me know if you have any questions.


For examples and more details, see the [documentation](https://vitess.io/docs/24.0/reference/compatibility/mysql-compatibility/#window-functions).

#### <a id="tablet-targeting"/>Tablet targeting via USE statement</a>
Copy link
Contributor

@timvaillancourt timvaillancourt Dec 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nickvanw let's say I use this feature to write rows to a PRIMARY that doesn't align with the VSchema, am I creating any data correctness/etc risks we should detail here?

I'm wondering if that would cause query failures or potentially-surprising results. But at the same time, I guess you can only use this feature with intention 🤔

And on a similar track, could vReplication get upset about rows in the wrong shard? One dreamed-up scenario I can think of is merging shards, and the same primary key exists in both, etc

None of what I'm thinking means changing the code here I think (it looks good so far), maybe just documentation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's say I use this feature to write rows to a PRIMARY that doesn't align with the VSchema, am I creating any data correctness/etc risks we should detail here?

I don't think the introduction of this feature changes this - you can already target specific shards and side-step any validation that Vitess would normally do against the queries you are executing (like ensuring inserts only are routed to the "correct" shard).

@github-actions
Copy link
Contributor

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions bot added Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. and removed Stale Marks PRs as stale after a period of inactivity, which are then closed after a grace period. labels Jan 11, 2026
@nickvanw
Copy link
Collaborator Author

I'm still working on this! If you have time for review @harshit-gangal, I would appreciate it 😁

Copy link
Member

@mattlord mattlord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just some minor comments/questions/suggestions.


logging *ExecuteLogger

// targetTabletAlias is set when using tablet-specific routing via USE keyspace@tablet-alias.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It must contain the shard too, no? keyspace:shard@tablet-alias

I'm also not sure when/why you would specify the tablet type in this context from the changelog info. When I read that, I thought that the shard AND tablet type would be required and we would confirm that it still matches when doing the routing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This was an older comment, the shard and the tablet type are required (in part, to avoid accidentally trying to write to a replica, etc)

}

// TestTargetTabletAlias tests the SetTargetTabletAlias and GetTargetTabletAlias methods.
func TestTargetTabletAlias(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like overkill to me -- a test for a setter/getter -- but obviously fine too.

Copy link
Member

@arthurschreiber arthurschreiber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ❤️

- Fix comment in safe_session.go to use correct syntax
- Add bounds check for empty string after @ in ParseDestination
- Use require.EqualError instead of manual error checking in tests
- Change %v to %s for string formatting in error message
- Use require.ErrorContains instead of require.Error + require.Contains

Signed-off-by: Nick Van Wiggeren <[email protected]>
@nickvanw nickvanw merged commit 21e1aee into main Jan 16, 2026
103 of 110 checks passed
@nickvanw nickvanw deleted the nickvanw/direct-access branch January 16, 2026 23:24
@promptless
Copy link
Contributor

promptless bot commented Jan 17, 2026

📝 Documentation updates detected!

New suggestion: Document tablet-specific targeting via USE statement

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RFC: Tablet Targeting

6 participants