Skip to content

Commit

Permalink
planner: avoid chained calls to improve debug (#54402)
Browse files Browse the repository at this point in the history
ref #54401
  • Loading branch information
hawkingrei authored Jul 3, 2024
1 parent 5909899 commit 95edc2d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -852,8 +852,8 @@ func (er *expressionRewriter) buildQuantifierPlan(planCtx *exprRewriterPlanCtx,
intest.AssertNotNil(planCtx)
innerIsNull := expression.NewFunctionInternal(er.sctx, ast.IsNull, types.NewFieldType(mysql.TypeTiny), rexpr)
outerIsNull := expression.NewFunctionInternal(er.sctx, ast.IsNull, types.NewFieldType(mysql.TypeTiny), lexpr)

funcSum, err := aggregation.NewAggFuncDesc(planCtx.builder.ctx.GetExprCtx(), ast.AggFuncSum, []expression.Expression{innerIsNull}, false)
exprCtx := planCtx.builder.ctx.GetExprCtx()
funcSum, err := aggregation.NewAggFuncDesc(exprCtx, ast.AggFuncSum, []expression.Expression{innerIsNull}, false)
if err != nil {
er.err = err
return
Expand All @@ -868,7 +868,7 @@ func (er *expressionRewriter) buildQuantifierPlan(planCtx *exprRewriterPlanCtx,
innerHasNull := expression.NewFunctionInternal(er.sctx, ast.NE, types.NewFieldType(mysql.TypeTiny), colSum, expression.NewZero())

// Build `count(1)` aggregation to check if subquery is empty.
funcCount, err := aggregation.NewAggFuncDesc(planCtx.builder.ctx.GetExprCtx(), ast.AggFuncCount, []expression.Expression{expression.NewOne()}, false)
funcCount, err := aggregation.NewAggFuncDesc(exprCtx, ast.AggFuncCount, []expression.Expression{expression.NewOne()}, false)
if err != nil {
er.err = err
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/rule_generate_column_substitute.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (gc *gcSubstituter) substitute(ctx context.Context, lp base.LogicalPlan, ex
for i := 0; i < len(aggFunc.Args); i++ {
tp = aggFunc.Args[i].GetType(ectx).EvalType()
for candidateExpr, column := range exprToColumn {
if aggFunc.Args[i].Equal(lp.SCtx().GetExprCtx().GetEvalCtx(), candidateExpr) && candidateExpr.GetType(ectx).EvalType() == tp &&
if aggFunc.Args[i].Equal(ectx, candidateExpr) && candidateExpr.GetType(ectx).EvalType() == tp &&
x.Schema().ColumnIndex(column) != -1 {
aggFunc.Args[i] = column
appendSubstituteColumnStep(lp, candidateExpr, column, opt)
Expand All @@ -216,7 +216,7 @@ func (gc *gcSubstituter) substitute(ctx context.Context, lp base.LogicalPlan, ex
for i := 0; i < len(x.GroupByItems); i++ {
tp = x.GroupByItems[i].GetType(ectx).EvalType()
for candidateExpr, column := range exprToColumn {
if x.GroupByItems[i].Equal(lp.SCtx().GetExprCtx().GetEvalCtx(), candidateExpr) && candidateExpr.GetType(ectx).EvalType() == tp &&
if x.GroupByItems[i].Equal(ectx, candidateExpr) && candidateExpr.GetType(ectx).EvalType() == tp &&
x.Schema().ColumnIndex(column) != -1 {
x.GroupByItems[i] = column
appendSubstituteColumnStep(lp, candidateExpr, column, opt)
Expand Down
6 changes: 3 additions & 3 deletions pkg/planner/core/rule_inject_extra_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ func injectProjBelowUnion(un *PhysicalUnionAll) *PhysicalUnionAll {
// are columns or constants, we do not need to build the `proj`.
func InjectProjBelowAgg(aggPlan base.PhysicalPlan, aggFuncs []*aggregation.AggFuncDesc, groupByItems []expression.Expression) base.PhysicalPlan {
hasScalarFunc := false

coreusage.WrapCastForAggFuncs(aggPlan.SCtx().GetExprCtx(), aggFuncs)
exprCtx := aggPlan.SCtx().GetExprCtx()
coreusage.WrapCastForAggFuncs(exprCtx, aggFuncs)
for i := 0; !hasScalarFunc && i < len(aggFuncs); i++ {
for _, arg := range aggFuncs[i].Args {
_, isScalarFunc := arg.(*expression.ScalarFunction)
Expand All @@ -141,7 +141,7 @@ func InjectProjBelowAgg(aggPlan base.PhysicalPlan, aggFuncs []*aggregation.AggFu
projExprs := make([]expression.Expression, 0, cap(projSchemaCols))
cursor := 0

ectx := aggPlan.SCtx().GetExprCtx().GetEvalCtx()
ectx := exprCtx.GetEvalCtx()
for _, f := range aggFuncs {
for i, arg := range f.Args {
if _, isCnst := arg.(*expression.Constant); isCnst {
Expand Down

0 comments on commit 95edc2d

Please sign in to comment.