Backport 19003#204
Merged
andyedison merged 6 commits intorelease-21.0-githubfrom Jan 8, 2026
Merged
Conversation
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
This fixes a bug where copying from an expression that had no type information would cause the target of the copy to have invalid information (as we'd be writing the null value which would prevent proper recalculation). Also added a bunch of unit test cases to cover `CopyExprInfo`. Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
There was a problem hiding this comment.
Pull request overview
This PR backports a fix from upstream PR vitessio#19003 that addresses issue vitessio#18987, which relates to proper handling of semantic information when copying expressions in the Vitess query planner, particularly affecting derived tables and subqueries.
- Fixed
CopySemanticInfoto validate map keys before copying and to differentiate behavior based on whether the target is a column name - Improved correlated subquery detection to only check for dependencies on outer tables
- Added comprehensive test coverage for semantic information copying behavior
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| go/vt/vtgate/semantics/semantic_table.go | Enhanced CopySemanticInfo method to add validation checks and conditional copying logic based on target expression type |
| go/vt/vtgate/semantics/semantic_table_test.go | Added two comprehensive test functions to verify correct behavior when copying semantic information to both ColName and non-ColName expressions |
| go/vt/vtgate/planbuilder/operators/subquery_builder.go | Fixed correlated subquery detection logic to properly filter dependencies by outerID; added unused createSubqueryFromPath function |
| go/vt/vtgate/planbuilder/testdata/select_cases.json | Updated test expectations with new window function test cases and minor changes to existing test output |
Comments suppressed due to low confidence (1)
go/vt/vtgate/planbuilder/operators/subquery_builder.go:231
- The function
createSubqueryFromPathappears to be a duplicate ofcreateSubquerywith nearly identical implementation. The only difference is howoriginalSqis obtained (line 206 usessqlparser.GetNodeFromPath(original, path)vs line 166 usescloneASTAndSemState(ctx, subq)). However, this function doesn't appear to be called anywhere in the codebase, suggesting it may be dead code that was accidentally included in this backport.
func createSubqueryFromPath(
ctx *plancontext.PlanningContext,
original sqlparser.Expr,
subq *sqlparser.Subquery,
path sqlparser.ASTPath,
outerID semantics.TableSet,
parent sqlparser.Expr,
argName string,
filterType opcode.PulloutOpcode,
isArg bool,
) *SubQuery {
topLevel := ctx.SemTable.EqualsExpr(original, parent)
original = cloneASTAndSemState(ctx, original)
originalSq := sqlparser.GetNodeFromPath(original, path).(*sqlparser.Subquery)
subqID := findTablesContained(ctx, originalSq.Select)
totalID := subqID.Merge(outerID)
sqc := &SubQueryBuilder{totalID: totalID, subqID: subqID, outerID: outerID}
predicates, joinCols := sqc.inspectStatement(ctx, subq.Select)
subqDependencies := ctx.SemTable.RecursiveDeps(subq)
correlated := subqDependencies.KeepOnly(outerID).NotEmpty()
opInner := translateQueryToOp(ctx, subq.Select)
opInner = sqc.getRootOperator(opInner, nil)
return &SubQuery{
FilterType: filterType,
Subquery: opInner,
Predicates: predicates,
Original: original,
ArgName: argName,
originalSubquery: originalSq,
IsArgument: isArg,
TopLevel: topLevel,
JoinColumns: joinCols,
correlated: correlated,
}
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Arthur Schreiber <arthur@planetscale.com>
susanzhang27
approved these changes
Jan 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR backports fix for vitessio#18987
upstream PR vitessio#19003
Description
Related Issue(s)
Checklist
Deployment Notes