Skip to content

vtgate: route inserts on pinned sharded tables to their pinned shard#19746

Open
officialasishkumar wants to merge 2 commits intovitessio:mainfrom
officialasishkumar:vtgate-pinned-table-insert
Open

vtgate: route inserts on pinned sharded tables to their pinned shard#19746
officialasishkumar wants to merge 2 commits intovitessio:mainfrom
officialasishkumar:vtgate-pinned-table-insert

Conversation

@officialasishkumar
Copy link
Copy Markdown

Description

This PR fixes inserts for pinned tables in sharded keyspaces.

Pinned tables already carry a fixed keyspace id in the vschema, and generic sharded routing already treats them as single-shard EqualUnique routes. The insert pipeline was bypassing that routing path and unconditionally requiring primary vindex values, which caused INSERT into pinned tables to fail with VT09001.

This change carries the pinned destination through insert planning and execution, then routes inserts directly to the pinned shard when there are no insert vindex columns to evaluate. Regression coverage was added in both the engine and vtgate executor tests.

Related Issue(s)

Fixes #19529

Checklist

  • "Backport to:" labels not necessary, not applied
  • Not backported, so no backport justification provided
  • Tests were added
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation is not required

Deployment Notes

None.

AI Disclosure

This PR was written with assistance from OpenAI Codex. I reviewed the final diff and local test results.

Copilot AI review requested due to automatic review settings March 28, 2026 15:54
@github-actions github-actions Bot added this to the v24.0.0 milestone Mar 28, 2026
@vitess-bot vitess-bot Bot added NeedsWebsiteDocsUpdate What it says NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work 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 Mar 28, 2026
@vitess-bot
Copy link
Copy Markdown
Contributor

vitess-bot Bot commented Mar 28, 2026

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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes INSERT routing for pinned tables in sharded keyspaces by propagating the pinned keyspace-id destination into insert planning/execution so inserts can be sent directly to the pinned shard when no vindex evaluation is needed.

Changes:

  • Carry a pinned-table TargetDestination through insert planning to avoid requiring a primary vindex for pinned tables with no vindexes.
  • Add execution support for single-destination inserts (resolve destination → execute on exactly one shard).
  • Add regression tests in both vtgate executor and engine layers.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
go/vt/vtgate/planbuilder/operator_transformers.go Sets InsertCommon.TargetDestination for pinned tables with no column vindexes during insert plan construction.
go/vt/vtgate/engine/insert_common.go Adds TargetDestination to InsertCommon and a helper to execute inserts by an explicit shard destination.
go/vt/vtgate/engine/insert.go Routes sharded inserts directly by TargetDestination when present.
go/vt/vtgate/engine/insert_select.go Adds a TargetDestination fast-path for sharded INSERT ... SELECT and includes destination in primitive description.
go/vt/vtgate/engine/insert_test.go Adds an engine-level regression test for sharded pinned inserts.
go/vt/vtgate/executor_dml_test.go Adds an executor-level regression test ensuring pinned-table inserts only hit the pinned shard.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbed6ea41e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +684 to +686
if len(ins.ColVindexes) == 0 && ins.VTable.Pinned != nil {
ic.TargetDestination = key.DestinationKeyspaceID(ins.VTable.Pinned)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Propagate pinned destination to INSERT ... SELECT plans

This change wires TargetDestination only in buildInsertPrimitive, which fixes INSERT ... VALUES but leaves the INSERT ... SELECT transformer path (transformInsertionSelection) constructing engine.InsertSelect without a pinned destination. For pinned sharded tables that have no insert vindexes, InsertSelect will still fall through to sharded vindex routing and call processVindexes with an empty ColVindexes slice, so INSERT ... SELECT on pinned tables remains broken instead of being routed to the pinned shard.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Wired TargetDestination for pinned tables in the INSERT...SELECT path too, matching the existing logic in buildInsertPrimitive (commit f322ddb).

promptless Bot added a commit that referenced this pull request Mar 28, 2026
The pinned table feature has been implemented for some time. This
removes the outdated statement in the V3 Vindex design doc that
said pinned tables were yet to be implemented.

Related: PR #19746 which fixes INSERT support for pinned tables.
The TargetDestination for pinned sharded tables was only set in
buildInsertPrimitive (INSERT...VALUES). Apply the same check in
transformInsertionSelection so INSERT...SELECT also routes to the
pinned shard when ColVindexes is empty.
@mattlord mattlord modified the milestones: v24.0.0, v25.0.0 Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: VTGate 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Cannot insert into pinned table, got no primary vindex.

3 participants