fix(plan): evaluate REPLACE ... SET RHS column references as DEFAULT(col)#25084
Open
ck89119 wants to merge 5 commits into
Open
fix(plan): evaluate REPLACE ... SET RHS column references as DEFAULT(col)#25084ck89119 wants to merge 5 commits into
ck89119 wants to merge 5 commits into
Conversation
…col) For `REPLACE ... SET col = col + 1`, MySQL treats the RHS reference to a target-table column as DEFAULT(col), not the current conflicting row value. MatrixOne instead reported `ambiguous column reference 'v'` and left the old row unchanged. The parser lowers `REPLACE ... SET` to the same Columns + ValuesClause shape as the VALUES form, so the value expressions are bound by buildValueScan with a DefaultBinder whose bind context is nil; any column reference therefore hits the `ctx == nil` branch in baseBindColRef and fails. Add an IsSetFormat marker to tree.Replace (set only in the SET grammar branch) so the SET-only semantics can be distinguished from the VALUES form, and route SET-form value binding through a new ReplaceValueBinder that resolves every column reference to that column's DEFAULT expression. Missing columns continue to fall back to their defaults like a normal REPLACE insert. The VALUES form is unchanged and still rejects column references, matching MySQL. Adds planner/binder unit tests and BVT coverage for provided and omitted columns and for references to other columns' defaults. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
- fix "agregate" -> "aggregate" typo in the unsupported aggregate error - add `var _ Binder = (*ReplaceValueBinder)(nil)` compile-time interface check - strengthen binder tests: assert DEFAULT(v) resolves to literal 5 for both the case-insensitive lookup and the `v + 1` binding (structure check, since constant folding happens later in the optimizer) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
heni02
approved these changes
Jun 23, 2026
# Conflicts: # pkg/sql/parsers/dialect/mysql/mysql_sql.go
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.
What type of PR is this?
Which issue(s) this PR fixes:
issue #24945
What this PR does / why we need it:
Subtask of #24918 (section 1). For
REPLACE ... SET col = col + 1, MySQL treats the RHS reference to a target-table column asDEFAULT(col), not the current conflicting row value. Missing columns also fall back to their defaults, matching normalREPLACEinsert semantics.Before this PR, MatrixOne reported
invalid input: ambiguous column reference 'v'and left the old row unchanged:Root cause
The parser lowers
REPLACE ... SET a = x, b = ytotree.Replace{Columns, Rows: ValuesClause}, i.e. the same AST shape as the VALUES form. WhenbuildValueScanbinds the value expressions it uses aDefaultBinderwhose bind context isnil, so any column reference hits theb.ctx == nilbranch inbaseBindColRefand fails with "ambiguous column reference".Fix
IsSetFormatmarker totree.Replace, set only in theSETgrammar branch, so the SET-only semantics can be distinguished from the VALUES form (which still rejects column references, matching MySQL).ReplaceValueBinderthat resolves every RHS column reference to that column'sDEFAULT(col)expression. SET-form value binding is routed through it via a newcolRefAsDefaultflag threaded frombindReplace→initInsertReplaceStmt→buildValueScan.INSERTand the VALUES form are unchanged.Tests
ReplaceValueBinder(default value resolution, case-insensitive lookup, unknown column error, unsupported bindings) — 100% coverage of the new file; planner testTestReplaceSetColRefAsDefault.dml/replace/replace.testcovering provided/omitted columns and references to other columns' defaults (set id=1,v=v+1→1|6|d,set id=2,v=v*2→2|10|d,set id=1,a=b+1→1|8|7); verified with mo-tester (198/198),replace_statement50/50 with no regression.🤖 Generated with Claude Code