-
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 a problem caused by union's schema #7680
Conversation
We often treat the |
I don't understand this. Could you please explain a few more?
|
plan/logical_plan_builder.go
Outdated
@@ -660,15 +660,10 @@ func (b *planBuilder) buildProjection4Union(u *LogicalUnionAll) { | |||
if _, isProj := child.(*LogicalProjection); needProjection || !isProj { | |||
b.optFlag |= flagEliminateProjection | |||
proj := LogicalProjection{Exprs: exprs}.init(b.ctx) | |||
if childID == 0 { |
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.
Why remove this?
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 generated new columns above here. So don't need add this check.
childTp := u.children[j].Schema().Columns[i].RetType | ||
resultTp = unionJoinFieldType(resultTp, childTp) | ||
} | ||
unionCols = append(unionCols, &expression.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.
Since we are using ColName
of children[0]
's Column here, should we keep other fields except UniqueID
same with children[0]
's Column as well? such as OrigTblName
, OrigColName
@@ -132,6 +132,7 @@ func (p *LogicalUnionAll) PruneColumns(parentUsedCols []*expression.Column) { | |||
for _, child := range p.Children() { | |||
child.PruneColumns(parentUsedCols) | |||
} | |||
p.schema.Columns = p.children[0].Schema().Columns |
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 this right? parent columns may have different UniqueID
and RetType
now?
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.
Oh yes we need some changing. We need to make sure it's the same with its children[0]
's.
Yes, union's col's id is the same with child's
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.
Here https://github.com/pingcap/tidb/pull/7680/files#diff-638d8be162d442ef3a5c423ff0c735d4R642 the UniqueID
of columns in UnionAll
is different from child[0]
union's col's id is the same with child's
What does id
in the above sentence mean?
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's done by here
plan/logical_plan_builder.go
Outdated
@@ -660,15 +660,10 @@ func (b *planBuilder) buildProjection4Union(u *LogicalUnionAll) { | |||
if _, isProj := child.(*LogicalProjection); needProjection || !isProj { | |||
b.optFlag |= flagEliminateProjection | |||
proj := LogicalProjection{Exprs: exprs}.init(b.ctx) | |||
if childID == 0 { | |||
for _, col := range unionSchema.Columns { | |||
col.UniqueID = b.ctx.GetSessionVars().AllocPlanColumnID() |
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 if all children of LogicalUnionAll
have same RetType for each Column? We would still generate new UniqueID
for each Column? Can we just use previous UniqueID
in this case?
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 could do this.
@shenli
It would be better if we have
|
@winoros Got it. It is much clear now. Thanks! |
@eurekaka I've updated the comment. You can see whether is clear enough. |
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
/run-all-tests |
Always at a projection when building a union. |
/run-all-tests |
Oh plan id changed after the last commit. |
/run-all-tests |
@eurekaka @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
What problem does this PR solve?
Before this commit. Union use the schema of its
Children[0]
.The
Columns
information is correct.But the
unique key information
is not, obviously.What is changed and how it works?
Give it a schema held by itself.
Check List
Tests
Code changes
This is found by #7676