-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plan: fix insert onduplicate key update #7406
Conversation
/run-all-tests |
/run-all-tests |
plan/planbuilder.go
Outdated
@@ -1187,7 +1187,40 @@ func (b *planBuilder) buildSelectPlanOfInsert(insert *ast.InsertStmt, insertPlan | |||
return errors.Trace(err) | |||
} | |||
|
|||
insertPlan.Schema4OnDuplicate = expression.MergeSchema(insertPlan.tableSchema, insertPlan.SelectPlan.Schema()) | |||
tableCols := insertPlan.Table.Cols() | |||
var insertCols []*table.Column |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it affectedValuesCols
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this name is better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we already have it at line 1158.
plan/planbuilder.go
Outdated
insertCols = tableCols | ||
} | ||
|
||
schema4NewRow := expression.NewSchema(make([]*expression.Column, len(tableCols))...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a comment for this variable.
@XuHuaiyu @lamxTyler PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
The schema we built for
Insert.Schema4OnDuplicate
was incorrect, thus the data record inserted by ofinsert ... select ... on duplicate key update ...
statement based on this schema was incorrect, too. Let's take the following queries as an example:After executing the above queries, the data record inside in table
t
is not as expected:This PR fixes this issue, and the correct result is:
What is changed and how it works?
construct the
Insert.Schema4OnDuplicate
based on the schema of table to be inserted.Check List
Tests
Related changes