Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHuaiyu committed Nov 1, 2018
1 parent 1f58b41 commit 5e2d6db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ explain_test
cmd/explaintest/explain-test.out
_tools/
*.fail.go
parser/
26 changes: 6 additions & 20 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,19 +701,14 @@ func (b *PlanBuilder) buildProjection4Union(u *LogicalUnionAll) {
// Process each child and add a projection above original child.
// So the schema of `UnionAll` can be the same with its children's.
for childID, child := range u.children {
uniqueIDToOutputIdxes := make(map[int][]int)
if p, ok := child.(*LogicalProjection); ok {
for i, expr := range p.Exprs {
col, ok1 := expr.(*expression.Column)
if !ok1 {
continue
}
uniqueID := int(col.UniqueID)
uniqueIDToOutputIdxes[uniqueID] = append(uniqueIDToOutputIdxes[uniqueID], i)
}
}
childProj, isChildProj := child.(*LogicalProjection)
exprs := make([]expression.Expression, len(child.Schema().Columns))
for i, srcCol := range child.Schema().Columns {
if isChildProj {
if exprCol, isCol := childProj.Exprs[i].(*expression.Column); isCol{
srcCol.UniqueID = exprCol.UniqueID
}
}
dstType := unionCols[i].RetType
srcType := srcCol.RetType
if !srcType.Equal(dstType) {
Expand All @@ -722,15 +717,6 @@ func (b *PlanBuilder) buildProjection4Union(u *LogicalUnionAll) {
exprs[i] = srcCol
}
}
for _, outputIdxes := range uniqueIDToOutputIdxes {
if len(outputIdxes) <= 1 {
continue
}
for i := 1; i < len(outputIdxes); i++ {
exprs[outputIdxes[i]] = exprs[outputIdxes[0]]
}
}

b.optFlag |= flagEliminateProjection
proj := LogicalProjection{Exprs: exprs}.Init(b.ctx)
proj.SetSchema(u.schema.Clone())
Expand Down

0 comments on commit 5e2d6db

Please sign in to comment.