Skip to content

vtgate: preserve evaluated IN tuples on lookup-miss fallback - #22150

Open
patnaikankit wants to merge 1 commit into
vitessio:mainfrom
patnaikankit:patnaikankit/lookup-miss-reuse-in-tuples
Open

patnaikankit wants to merge 1 commit into
vitessio:mainfrom
patnaikankit:patnaikankit/lookup-miss-reuse-in-tuples

Conversation

@patnaikankit

Copy link
Copy Markdown

Description

A marked IN route can find no lookup destinations but still need arbitrary-shard execution, for example for an aggregate result or an independent reference UNION arm. Its fallback must use the tuple that routing already evaluated. Re-evaluating a nondeterministic expression can change the list; sending only the original caller bindings can instead omit the generated list variable.

Resolve marked IN fallbacks inside the IN routing helpers while their evaluated values are still available, then build shard bindings through the existing helpers. Preserve single-column __vals and indexed multi-column lists, omit scalar-column list bindings, and reuse scalar evaluation results. Values remain local to each execution; caller bindings and cached route expressions are unchanged.

Regression coverage compares the routed values with the final fallback tuple using both uuid() and a deterministic changing expression. It exercises buffered, streaming and VEXPLAIN execution, repeated use of one Route, and composite list/scalar combinations.

This PR is based directly on main and contains only the tuple-preservation fix and tests. It does not include #21962 or #21354. The reference-UNION issue was reported during #21962's review, but the engine fix also applies to existing marked IN fallbacks. When #21962 lands, its overlapping fallback code should be reconciled with this shared routing path.

Related Issue(s)

Fixes #22149

Related to #21962 and its nonblocking follow-up review.

Validation

  • Full engine, planbuilder and operator unit suites pass.
  • The tuple-reuse regressions pass 20 repeated runs under the race detector.
  • The regressions fail on main (823174c29a) without the fix, and also detect the tuple mismatch and duplicate evaluation on vtgate: preserve reference rows in UNION ALL on lookup miss #21962's unchanged implementation.
  • scripts/fmt, engine lint and git diff --check pass.
go test ./go/vt/vtgate/engine ./go/vt/vtgate/planbuilder ./go/vt/vtgate/planbuilder/operators -count=1 -timeout 5m
go test -race ./go/vt/vtgate/engine -run '^Test(INLookupMissReusesEvaluatedTuple|MultiColumnINFallbackReusesEvaluatedValues)$' -count=20 -timeout 5m

No end-to-end cluster run was performed for this follow-up. Fresh CI results are pending.

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, a justification is included in the PR description
  • Tests were added
  • Did the new or modified tests pass consistently locally and on CI? (Local checks passed; CI is pending.)
  • Documentation was added or is not required

Deployment Notes

No configuration, schema or deployment changes are required. Marked IN fallback queries retain the values already checked during routing. Ordinary lookup-only misses remain empty results. No backport is requested.

Arbitrary-shard selection is unchanged. In transaction_mode=SINGLE, a fallback can still select another shard and trigger multi-db transaction attempted; transaction affinity is outside this fix.

AI Disclosure

Codex assisted with implementation, regression tests and validation.

Resolve marked IN fallbacks while the evaluated routing values are still available, preserving single-column and indexed multi-column bindings without re-evaluation. Add deterministic changing-expression and UUID regressions for buffered, streaming, and VEXPLAIN execution.

Signed-off-by: Ankit Patnaik <ankit.123patnaik123@gmail.com>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 07:17
@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 Nov 24, 2026
@github-actions github-actions Bot added this to the v25.0.0 milestone Nov 24, 2026
@vitess-bot

vitess-bot Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

Copilot AI 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.

🟢 Approval recommended

The review identifies no active issues with the change preserving evaluated IN values during arbitrary-shard fallback.

No open issues 🎉

What changed in this PR

Fixes #22149 by preserving evaluated IN values when a marked VTGate route has no destinations and falls back to an arbitrary shard. This engine-only change is independent of the related UNION planner work.

Changes:

  • Resolve marked IN fallbacks within routing helpers, reusing evaluated tuples for shard bindings.
  • Preserve indexed composite lists and reuse scalar evaluation results without modifying caller bindings.
  • Add regression coverage for changing expressions, repeated Route execution, buffered and streaming execution, and VEXPLAIN.
File Description
go/​vt/​vtgate/​engine/​routing.go Retains evaluated IN values for fallback bindings and removes duplicate scalar evaluation.
go/​vt/​vtgate/​engine/​route.go Directs marked IN routes through fallback-aware routing helpers.
go/​vt/​vtgate/​engine/​route_in_fallback_test.go Tests tuple reuse, composite bindings, and execution-local values.

Review effort: Balanced

This branch has not been deployed

No deployments
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 Type: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: lookup-miss fallback can re-evaluate nondeterministic IN tuples

3 participants