-
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, executor: only set DefaultValues in agg push down. #5383
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ package plan | |
import ( | ||
"github.com/pingcap/tidb/context" | ||
"github.com/pingcap/tidb/expression" | ||
"github.com/pingcap/tidb/types" | ||
) | ||
|
||
// canProjectionBeEliminatedLoose checks whether a projection can be eliminated, returns true if | ||
|
@@ -158,9 +157,6 @@ func (pe *projectionEliminater) eliminate(p LogicalPlan, replace map[string]*exp | |
if !(isProj && canEliminate && canProjectionBeEliminatedLoose(proj)) { | ||
return p | ||
} | ||
if join, ok := p.Parents()[0].(*LogicalJoin); ok { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we could remove this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @shenli projection elimination is done before aggregation push down, we can remove it safely. |
||
pe.resetDefaultValues(join, p) | ||
} | ||
exprs := proj.Exprs | ||
for i, col := range proj.Schema().Columns { | ||
replace[string(col.HashCode())] = exprs[i].(*expression.Column) | ||
|
@@ -169,43 +165,6 @@ func (pe *projectionEliminater) eliminate(p LogicalPlan, replace map[string]*exp | |
return p.Children()[0].(LogicalPlan) | ||
} | ||
|
||
// If the inner child of a Join is a Projection which been eliminated, | ||
// and the schema of child plan of Projection is not consistent with | ||
// the schema of Projection, the default values of Join should be reset. | ||
func (pe *projectionEliminater) resetDefaultValues(join *LogicalJoin, prj Plan) { | ||
prjChild := prj.Children()[0] | ||
var joinInnerChild Plan | ||
switch join.JoinType { | ||
case LeftOuterJoin: | ||
joinInnerChild = join.Children()[1] | ||
case RightOuterJoin: | ||
joinInnerChild = join.Children()[0] | ||
default: | ||
return | ||
} | ||
if joinInnerChild != prj { | ||
return | ||
} | ||
var schemaIdxMap map[int]int | ||
prjSchema := prj.Schema().Columns | ||
childOfPrjSchema := prjChild.Schema().Columns | ||
for i := 0; i < len(prjSchema); i++ { | ||
for j := 0; j < len(childOfPrjSchema); j++ { | ||
if prjSchema[i].Equal(childOfPrjSchema[j], nil) { | ||
schemaIdxMap[i] = j | ||
} | ||
} | ||
} | ||
newDefaultValues := make([]types.Datum, len(childOfPrjSchema)) | ||
for i := range prjSchema { | ||
if j, ok := schemaIdxMap[i]; ok { | ||
newDefaultValues[j] = join.DefaultValues[i] | ||
} | ||
} | ||
join.DefaultValues = newDefaultValues | ||
return | ||
} | ||
|
||
func (p *LogicalJoin) replaceExprColumns(replace map[string]*expression.Column) { | ||
for _, equalExpr := range p.EqualConditions { | ||
resolveExprAndReplace(equalExpr, replace) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,8 +106,9 @@ type LogicalJoin struct { | |
leftProperties [][]*expression.Column | ||
rightProperties [][]*expression.Column | ||
|
||
// DefaultValues is only used for outer join, which stands for the default values when the outer table cannot find join partner | ||
// instead of null padding. | ||
// DefaultValues is only used for outer join, which is values the inner table's should be when the outer table | ||
// doesn't match any inner table'row. | ||
// That it's nil just means the default values is a slice of NULL. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about: // DefaultValues are only used for "LeftOuterJoin" and "RightOuterJoin" as the inner row when there is no inner row in the inner table can be joined with an outer row.
// NOTE: It is only set during the optimization of "aggregate push down", otherwise it will be nil, witch means a slice of NULLs. |
||
DefaultValues []types.Datum | ||
|
||
// redundantSchema contains columns which are eliminated in join. | ||
|
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.
Can we combine this code block with the code block in line 603~607?