-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner/core,binloginfo: add a projection to fix 'delete from join' schema #8805
Conversation
'delete from t where a in (select ...) or b in (select ...)' The correct schema should be the schema of t, rather than the schema of the join. Add a projection in this case.
proj.SetSchema(oldSchema.Clone()) | ||
p = proj | ||
} | ||
|
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.
Should we add projection for Update
as well?
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.
Yes, update have the same problem
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.
I simply add a projection but the CI failed.
I'll fix delete first, and leave update
to somebody else.
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
// Add a projection for the following case, otherwise the final schema will be the schema of the join. | ||
// delete from t where a in (select ...) or b in (select ...) | ||
if oldLen := oldSchema.Len(); oldLen != p.Schema().Len() { | ||
proj := LogicalProjection{Exprs: expression.Column2Exprs(p.Schema().Columns[:oldLen])}.Init(b.ctx) |
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.
it seems to delete target table isn't always the first table, MySQL support delete multiple tables syntax, although I never use that https://dev.mysql.com/doc/refman/5.7/en/delete.html 🤣
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.
Yes, we should consider the case of multi-table deletion.
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.
Delete from A where ... // delete single table
Delete A B ... from ... // delete multiple table
Delete from A B using ... // delete multiple table
Multiple tables case is more complex. This PR will only handle the single table cases.
Let's have a look what's the bug actually:
select from A where A join B ...
there is a projection on A join B
but for
delete from A where A join B ...
, the projection is missing.
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.
What output should it be if it's a multiple tables deleting
?
@tiancaiamao Please address the comments. |
/run-all-tests |
/run-all-tests |
/run-all-tests |
/run-unit-test |
1 similar comment
/run-unit-test |
/run-all-tests |
LGTM. and it's a little stranger, delete by subquery eliminate unused column by projection, but delete multiple tables eliminate unused column in |
/run-unit-test |
…chema (pingcap#8805) 'delete from t where a in (select ...) or b in (select ...)' The correct schema should be the schema of t, rather than the schema of the join. Add a projection in this case.
need a cherry pick to 2.1 version |
…chema (pingcap#8805) 'delete from t where a in (select ...) or b in (select ...)' The correct schema should be the schema of t, rather than the schema of the join. Add a projection in this case.
What problem does this PR solve?
With binlog on, the last SQL fail like this:
What is changed and how it works?
The final schema should be the schema of table b1, rather than the schema of join.
Add a projection to the plan to get the correct schema.
Check List
Tests
This change is