Skip to content

Commit

Permalink
planner: move logical union all to logicalop pkg. (#55402)
Browse files Browse the repository at this point in the history
ref #51664, ref #52714
  • Loading branch information
AilinKid authored Aug 15, 2024
1 parent 34d275d commit c74a233
Show file tree
Hide file tree
Showing 22 changed files with 68 additions and 55 deletions.
2 changes: 1 addition & 1 deletion pkg/planner/cascades/implementation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (*ImplUnionAll) Match(_ *memo.GroupExpr, prop *property.PhysicalProperty) (

// OnImplement implements ImplementationRule OnImplement interface.
func (*ImplUnionAll) OnImplement(expr *memo.GroupExpr, reqProp *property.PhysicalProperty) ([]memo.Implementation, error) {
logicalUnion := expr.ExprNode.(*plannercore.LogicalUnionAll)
logicalUnion := expr.ExprNode.(*logicalop.LogicalUnionAll)
chReqProps := make([]*property.PhysicalProperty, len(expr.Children))
for i := range expr.Children {
chReqProps[i] = &property.PhysicalProperty{ExpectedCnt: reqProp.ExpectedCnt}
Expand Down
6 changes: 3 additions & 3 deletions pkg/planner/cascades/transformation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (r *PushLimitDownUnionAll) Match(expr *memo.ExprIter) bool {
// It will transform `Limit->UnionAll->X` to `Limit->UnionAll->Limit->X`.
func (r *PushLimitDownUnionAll) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error) {
limit := old.GetExpr().ExprNode.(*logicalop.LogicalLimit)
unionAll := old.Children[0].GetExpr().ExprNode.(*plannercore.LogicalUnionAll)
unionAll := old.Children[0].GetExpr().ExprNode.(*logicalop.LogicalUnionAll)
unionAllSchema := old.Children[0].Group.Prop.Schema

newLimit := logicalop.LogicalLimit{
Expand Down Expand Up @@ -1086,7 +1086,7 @@ func NewRulePushSelDownUnionAll() Transformation {
// It will transform `Selection->UnionAll->x` to `UnionAll->Selection->x`.
func (*PushSelDownUnionAll) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error) {
sel := old.GetExpr().ExprNode.(*logicalop.LogicalSelection)
unionAll := old.Children[0].GetExpr().ExprNode.(*plannercore.LogicalUnionAll)
unionAll := old.Children[0].GetExpr().ExprNode.(*logicalop.LogicalUnionAll)
childGroups := old.Children[0].GetExpr().Children

newUnionAllExpr := memo.NewGroupExpr(unionAll)
Expand Down Expand Up @@ -1365,7 +1365,7 @@ func (r *PushTopNDownUnionAll) Match(expr *memo.ExprIter) bool {
// It will transform `TopN->UnionAll->X` to `TopN->UnionAll->TopN->X`.
func (r *PushTopNDownUnionAll) OnTransform(old *memo.ExprIter) (newExprs []*memo.GroupExpr, eraseOld bool, eraseAll bool, err error) {
topN := old.GetExpr().ExprNode.(*logicalop.LogicalTopN)
unionAll := old.Children[0].GetExpr().ExprNode.(*plannercore.LogicalUnionAll)
unionAll := old.Children[0].GetExpr().ExprNode.(*logicalop.LogicalUnionAll)

newTopN := logicalop.LogicalTopN{
Count: topN.Count + topN.Offset,
Expand Down
2 changes: 0 additions & 2 deletions pkg/planner/core/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ go_library(
"logical_expand.go",
"logical_index_scan.go",
"logical_initialize.go",
"logical_partition_union_all.go",
"logical_plan_builder.go",
"logical_plans.go",
"logical_table_scan.go",
"logical_tikv_single_gather.go",
"logical_union_all.go",
"memtable_infoschema_extractor.go",
"memtable_predicate_extractor.go",
"mock.go",
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/casetest/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func TestGroupNDVs(t *testing.T) {
case *logicalop.LogicalApply:
lp = lp.Children()[0]
stack = append(stack, v.Children()[1])
case *core.LogicalUnionAll:
case *logicalop.LogicalUnionAll:
lp = lp.Children()[0]
for i := 1; i < len(v.Children()); i++ {
stack = append(stack, v.Children()[i])
Expand Down
6 changes: 3 additions & 3 deletions pkg/planner/core/collect_column_stats_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (c *columnStatsUsageCollector) collectPredicateColumnsForJoin(p *logicalop.
c.addPredicateColumnsFromExpressions(exprs)
}

func (c *columnStatsUsageCollector) collectPredicateColumnsForUnionAll(p *LogicalUnionAll) {
func (c *columnStatsUsageCollector) collectPredicateColumnsForUnionAll(p *logicalop.LogicalUnionAll) {
// statistics of the ith column of UnionAll come from statistics of the ith column of each child.
schemas := make([]*expression.Schema, 0, len(p.Children()))
relatedCols := make([]*expression.Column, 0, len(p.Children()))
Expand Down Expand Up @@ -289,9 +289,9 @@ func (c *columnStatsUsageCollector) collectFromPlan(lp base.LogicalPlan) {
for _, item := range x.ByItems {
c.addPredicateColumnsFromExpressions([]expression.Expression{item.Expr})
}
case *LogicalUnionAll:
case *logicalop.LogicalUnionAll:
c.collectPredicateColumnsForUnionAll(x)
case *LogicalPartitionUnionAll:
case *logicalop.LogicalPartitionUnionAll:
c.collectPredicateColumnsForUnionAll(&x.LogicalUnionAll)
case *LogicalCTE:
// Visit seedPartLogicalPlan and recursivePartLogicalPlan first.
Expand Down
2 changes: 2 additions & 0 deletions pkg/planner/core/core_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ func init() {
utilfuncp.ExhaustPhysicalPlans4LogicalApply = exhaustPhysicalPlans4LogicalApply
utilfuncp.ExhaustPhysicalPlans4LogicalLimit = exhaustPhysicalPlans4LogicalLimit
utilfuncp.ExhaustPhysicalPlans4LogicalWindow = exhaustPhysicalPlans4LogicalWindow
utilfuncp.ExhaustPhysicalPlans4LogicalUnionAll = exhaustPhysicalPlans4LogicalUnionAll
utilfuncp.ExhaustPhysicalPlans4LogicalSequence = exhaustPhysicalPlans4LogicalSequence
utilfuncp.ExhaustPhysicalPlans4LogicalSelection = exhaustPhysicalPlans4LogicalSelection
utilfuncp.ExhaustPhysicalPlans4LogicalMaxOneRow = exhaustPhysicalPlans4LogicalMaxOneRow
utilfuncp.ExhaustPhysicalPlans4LogicalUnionScan = exhaustPhysicalPlans4LogicalUnionScan
utilfuncp.ExhaustPhysicalPlans4LogicalProjection = exhaustPhysicalPlans4LogicalProjection
utilfuncp.ExhaustPhysicalPlans4LogicalAggregation = exhaustPhysicalPlans4LogicalAggregation
utilfuncp.ExhaustPhysicalPlans4LogicalPartitionUnionAll = exhaustPhysicalPlans4LogicalPartitionUnionAll

utilfuncp.GetActualProbeCntFromProbeParents = getActualProbeCntFromProbeParents
utilfuncp.GetEstimatedProbeCntFromProbeParents = getEstimatedProbeCntFromProbeParents
Expand Down
8 changes: 5 additions & 3 deletions pkg/planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -2446,7 +2446,7 @@ func canPushToCopImpl(lp base.LogicalPlan, storeTp kv.StoreType, considerDual bo
// Once aggregation is pushed to cop, the cache data can't be use any more.
return false
}
case *LogicalUnionAll:
case *logicalop.LogicalUnionAll:
if storeTp != kv.TiFlash {
return false
}
Expand Down Expand Up @@ -2951,7 +2951,8 @@ func exhaustPhysicalPlans4LogicalLock(lp base.LogicalPlan, prop *property.Physic
return []base.PhysicalPlan{lock}, true, nil
}

func exhaustUnionAllPhysicalPlans(p *LogicalUnionAll, prop *property.PhysicalProperty) ([]base.PhysicalPlan, bool, error) {
func exhaustPhysicalPlans4LogicalUnionAll(lp base.LogicalPlan, prop *property.PhysicalProperty) ([]base.PhysicalPlan, bool, error) {
p := lp.(*logicalop.LogicalUnionAll)
// TODO: UnionAll can not pass any order, but we can change it to sort merge to keep order.
if !prop.IsSortItemEmpty() || (prop.IsFlashProp() && prop.TaskTp != property.MppTaskType) {
return nil, true, nil
Expand Down Expand Up @@ -2995,7 +2996,8 @@ func exhaustUnionAllPhysicalPlans(p *LogicalUnionAll, prop *property.PhysicalPro
return []base.PhysicalPlan{ua}, true, nil
}

func exhaustPartitionUnionAllPhysicalPlans(p *LogicalPartitionUnionAll, prop *property.PhysicalProperty) ([]base.PhysicalPlan, bool, error) {
func exhaustPhysicalPlans4LogicalPartitionUnionAll(lp base.LogicalPlan, prop *property.PhysicalProperty) ([]base.PhysicalPlan, bool, error) {
p := lp.(*logicalop.LogicalPartitionUnionAll)
uas, flagHint, err := p.LogicalUnionAll.ExhaustPhysicalPlans(prop)
if err != nil {
return nil, false, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ func (er *expressionRewriter) toColumn(v *ast.ColumnName) {
return
}
}
if _, ok := planCtx.plan.(*LogicalUnionAll); ok && v.Table.O != "" {
if _, ok := planCtx.plan.(*logicalop.LogicalUnionAll); ok && v.Table.O != "" {
er.err = plannererrors.ErrTablenameNotAllowedHere.GenWithStackByArgs(v.Table.O, "SELECT", clauseMsg[planCtx.builder.curClause])
return
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ func (b *PlanBuilder) setUnionFlen(resultTp *types.FieldType, cols []expression.
}
}

func (b *PlanBuilder) buildProjection4Union(_ context.Context, u *LogicalUnionAll) error {
func (b *PlanBuilder) buildProjection4Union(_ context.Context, u *logicalop.LogicalUnionAll) error {
unionCols := make([]*expression.Column, 0, u.Children()[0].Schema().Len())
names := make([]*types.FieldName, 0, u.Children()[0].Schema().Len())

Expand Down Expand Up @@ -1894,7 +1894,7 @@ func (b *PlanBuilder) buildUnionAll(ctx context.Context, subPlan []base.LogicalP
if len(subPlan) == 0 {
return nil, nil
}
u := LogicalUnionAll{}.Init(b.ctx, b.getSelectOffset())
u := logicalop.LogicalUnionAll{}.Init(b.ctx, b.getSelectOffset())
u.SetChildren(subPlan...)
err := b.buildProjection4Union(ctx, u)
return u, err
Expand All @@ -1921,7 +1921,7 @@ func (b *PlanBuilder) buildSort(ctx context.Context, p base.LogicalPlan, byItems

func (b *PlanBuilder) buildSortWithCheck(ctx context.Context, p base.LogicalPlan, byItems []*ast.ByItem, aggMapper map[*ast.AggregateFuncExpr]int, windowMapper map[*ast.WindowFuncExpr]int,
projExprs []expression.Expression, oldLen int, hasDistinct bool) (*logicalop.LogicalSort, error) {
if _, isUnion := p.(*LogicalUnionAll); isUnion {
if _, isUnion := p.(*logicalop.LogicalUnionAll); isUnion {
b.curClause = globalOrderByClause
} else {
b.curClause = orderByClause
Expand Down
3 changes: 2 additions & 1 deletion pkg/planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ var (
_ base.LogicalPlan = &TiKVSingleGather{}
_ base.LogicalPlan = &LogicalTableScan{}
_ base.LogicalPlan = &LogicalIndexScan{}
_ base.LogicalPlan = &LogicalUnionAll{}
_ base.LogicalPlan = &logicalop.LogicalUnionAll{}
_ base.LogicalPlan = &logicalop.LogicalPartitionUnionAll{}
_ base.LogicalPlan = &logicalop.LogicalSort{}
_ base.LogicalPlan = &logicalop.LogicalLock{}
_ base.LogicalPlan = &logicalop.LogicalLimit{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/logical_plans_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ func TestAllocID(t *testing.T) {
func checkDataSourceCols(p base.LogicalPlan, t *testing.T, ans map[int][]string, comment string) {
ectx := p.SCtx().GetExprCtx().GetEvalCtx()
switch v := p.(type) {
case *DataSource, *LogicalUnionAll, *logicalop.LogicalLimit:
case *DataSource, *logicalop.LogicalUnionAll, *logicalop.LogicalLimit:
testdata.OnRecord(func() {
ans[p.ID()] = make([]string, p.Schema().Len())
})
Expand Down
2 changes: 2 additions & 0 deletions pkg/planner/core/operator/logicalop/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"logical_lock.go",
"logical_max_one_row.go",
"logical_mem_table.go",
"logical_partition_union_all.go",
"logical_projection.go",
"logical_schema_producer.go",
"logical_selection.go",
Expand All @@ -21,6 +22,7 @@ go_library(
"logical_sort.go",
"logical_table_dual.go",
"logical_top_n.go",
"logical_union_all.go",
"logical_union_scan.go",
"logical_window.go",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package core
package logicalop

import (
"github.com/pingcap/tidb/pkg/planner/core/base"
"github.com/pingcap/tidb/pkg/planner/core/operator/logicalop"
"github.com/pingcap/tidb/pkg/planner/property"
"github.com/pingcap/tidb/pkg/planner/util/utilfuncp"
"github.com/pingcap/tidb/pkg/util/plancodec"
)

Expand All @@ -28,15 +28,15 @@ type LogicalPartitionUnionAll struct {

// Init initializes LogicalPartitionUnionAll.
func (p LogicalPartitionUnionAll) Init(ctx base.PlanContext, offset int) *LogicalPartitionUnionAll {
p.BaseLogicalPlan = logicalop.NewBaseLogicalPlan(ctx, plancodec.TypePartitionUnion, &p, offset)
p.BaseLogicalPlan = NewBaseLogicalPlan(ctx, plancodec.TypePartitionUnion, &p, offset)
return &p
}

// *************************** start implementation of LogicalPlan interface ***************************

// ExhaustPhysicalPlans implements LogicalPlan interface.
func (p *LogicalPartitionUnionAll) ExhaustPhysicalPlans(prop *property.PhysicalProperty) ([]base.PhysicalPlan, bool, error) {
return exhaustPartitionUnionAllPhysicalPlans(p, prop)
return utilfuncp.ExhaustPhysicalPlans4LogicalPartitionUnionAll(p, prop)
}

// *************************** end implementation of LogicalPlan interface ***************************
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package core
package logicalop

import (
"fmt"

"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/planner/core/base"
"github.com/pingcap/tidb/pkg/planner/core/operator/logicalop"
"github.com/pingcap/tidb/pkg/planner/property"
"github.com/pingcap/tidb/pkg/planner/util"
"github.com/pingcap/tidb/pkg/planner/util/optimizetrace"
Expand All @@ -28,12 +29,12 @@ import (

// LogicalUnionAll represents LogicalUnionAll plan.
type LogicalUnionAll struct {
logicalop.LogicalSchemaProducer
LogicalSchemaProducer
}

// Init initializes LogicalUnionAll.
func (p LogicalUnionAll) Init(ctx base.PlanContext, offset int) *LogicalUnionAll {
p.BaseLogicalPlan = logicalop.NewBaseLogicalPlan(ctx, plancodec.TypeUnion, &p, offset)
p.BaseLogicalPlan = NewBaseLogicalPlan(ctx, plancodec.TypeUnion, &p, offset)
return &p
}

Expand Down Expand Up @@ -97,7 +98,7 @@ func (p *LogicalUnionAll) PruneColumns(parentUsedCols []*expression.Column, opt
for j, col := range schema.Columns {
exprs[j] = col
}
proj := logicalop.LogicalProjection{Exprs: exprs}.Init(p.SCtx(), p.QueryBlockOffset())
proj := LogicalProjection{Exprs: exprs}.Init(p.SCtx(), p.QueryBlockOffset())
proj.SetSchema(schema)

proj.SetChildren(child)
Expand All @@ -114,14 +115,14 @@ func (p *LogicalUnionAll) PruneColumns(parentUsedCols []*expression.Column, opt

// PushDownTopN implements the base.LogicalPlan.<5th> interface.
func (p *LogicalUnionAll) PushDownTopN(topNLogicalPlan base.LogicalPlan, opt *optimizetrace.LogicalOptimizeOp) base.LogicalPlan {
var topN *logicalop.LogicalTopN
var topN *LogicalTopN
if topNLogicalPlan != nil {
topN = topNLogicalPlan.(*logicalop.LogicalTopN)
topN = topNLogicalPlan.(*LogicalTopN)
}
for i, child := range p.Children() {
var newTopN *logicalop.LogicalTopN
var newTopN *LogicalTopN
if topN != nil {
newTopN = logicalop.LogicalTopN{Count: topN.Count + topN.Offset, PreferLimitToCop: topN.PreferLimitToCop}.Init(p.SCtx(), topN.QueryBlockOffset())
newTopN = LogicalTopN{Count: topN.Count + topN.Offset, PreferLimitToCop: topN.PreferLimitToCop}.Init(p.SCtx(), topN.QueryBlockOffset())
for _, by := range topN.ByItems {
newTopN.ByItems = append(newTopN.ByItems, &util.ByItems{Expr: by.Expr, Desc: by.Desc})
}
Expand Down Expand Up @@ -169,7 +170,7 @@ func (p *LogicalUnionAll) DeriveStats(childStats []*property.StatsInfo, selfSche

// ExhaustPhysicalPlans implements base.LogicalPlan.<14th> interface.
func (p *LogicalUnionAll) ExhaustPhysicalPlans(prop *property.PhysicalProperty) ([]base.PhysicalPlan, bool, error) {
return exhaustUnionAllPhysicalPlans(p, prop)
return utilfuncp.ExhaustPhysicalPlans4LogicalUnionAll(p, prop)
}

// ExtractCorrelatedCols inherits BaseLogicalPlan.LogicalPlan.<15th> implementation.
Expand All @@ -193,3 +194,13 @@ func (p *LogicalUnionAll) ExhaustPhysicalPlans(prop *property.PhysicalProperty)
// ConvertOuterToInnerJoin inherits BaseLogicalPlan.LogicalPlan.<24th> implementation.

// *************************** end implementation of logicalPlan interface ***************************

func appendNewTopNTraceStep(topN *LogicalTopN, union *LogicalUnionAll, opt *optimizetrace.LogicalOptimizeOp) {
reason := func() string {
return ""
}
action := func() string {
return fmt.Sprintf("%v_%v is added and pushed down across %v_%v", topN.TP(), topN.ID(), union.TP(), union.ID())
}
opt.AppendStepToCurrent(topN.ID(), topN.TP(), reason, action)
}
8 changes: 4 additions & 4 deletions pkg/planner/core/rule_aggregation_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (a *AggregationPushDownSolver) Optimize(_ context.Context, p base.LogicalPl
return newLogicalPlan, planChanged, err
}

func (a *AggregationPushDownSolver) tryAggPushDownForUnion(union *LogicalUnionAll, agg *logicalop.LogicalAggregation, opt *optimizetrace.LogicalOptimizeOp) error {
func (a *AggregationPushDownSolver) tryAggPushDownForUnion(union *logicalop.LogicalUnionAll, agg *logicalop.LogicalAggregation, opt *optimizetrace.LogicalOptimizeOp) error {
for _, aggFunc := range agg.AggFuncs {
if !a.isDecomposableWithUnion(aggFunc) {
return nil
Expand Down Expand Up @@ -661,12 +661,12 @@ func (a *AggregationPushDownSolver) aggPushDown(p base.LogicalPlan, opt *optimiz
appendAggPushDownAcrossProjTraceStep(agg, proj, opt)
}
}
if union, ok1 := child.(*LogicalUnionAll); ok1 && p.SCtx().GetSessionVars().AllowAggPushDown {
if union, ok1 := child.(*logicalop.LogicalUnionAll); ok1 && p.SCtx().GetSessionVars().AllowAggPushDown {
err := a.tryAggPushDownForUnion(union, agg, opt)
if err != nil {
return nil, err
}
} else if union, ok1 := child.(*LogicalPartitionUnionAll); ok1 {
} else if union, ok1 := child.(*logicalop.LogicalPartitionUnionAll); ok1 {
err := a.tryAggPushDownForUnion(&union.LogicalUnionAll, agg, opt)
if err != nil {
return nil, err
Expand Down Expand Up @@ -737,7 +737,7 @@ func appendAggPushDownAcrossProjTraceStep(agg *logicalop.LogicalAggregation, pro
opt.AppendStepToCurrent(agg.ID(), agg.TP(), reason, action)
}

func appendAggPushDownAcrossUnionTraceStep(union *LogicalUnionAll, agg *logicalop.LogicalAggregation, opt *optimizetrace.LogicalOptimizeOp) {
func appendAggPushDownAcrossUnionTraceStep(union *logicalop.LogicalUnionAll, agg *logicalop.LogicalAggregation, opt *optimizetrace.LogicalOptimizeOp) {
evalCtx := union.SCtx().GetExprCtx().GetEvalCtx()
reason := func() string {
buffer := bytes.NewBufferString(fmt.Sprintf("%v_%v functions[", agg.TP(), agg.ID()))
Expand Down
2 changes: 1 addition & 1 deletion pkg/planner/core/rule_eliminate_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (pe *ProjectionEliminator) eliminate(p base.LogicalPlan, replace map[string
}
proj, isProj := p.(*logicalop.LogicalProjection)
childFlag := canEliminate
if _, isUnion := p.(*LogicalUnionAll); isUnion {
if _, isUnion := p.(*logicalop.LogicalUnionAll); isUnion {
childFlag = false
} else if _, isAgg := p.(*logicalop.LogicalAggregation); isAgg || isProj {
childFlag = true
Expand Down
4 changes: 2 additions & 2 deletions pkg/planner/core/rule_partition_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *PartitionProcessor) rewriteDataSource(lp base.LogicalPlan, opt *optimiz
if err != nil {
return nil, err
}
if ua, ok := ds.(*LogicalPartitionUnionAll); ok {
if ua, ok := ds.(*logicalop.LogicalPartitionUnionAll); ok {
// Adjust the UnionScan->Union->DataSource1, DataSource2 ... to
// Union->(UnionScan->DataSource1), (UnionScan->DataSource2)
children := make([]base.LogicalPlan, 0, len(ua.Children()))
Expand Down Expand Up @@ -1878,7 +1878,7 @@ func (s *PartitionProcessor) makeUnionAllChildren(ds *DataSource, pi *model.Part
appendMakeUnionAllChildrenTranceStep(ds, usedDefinition, children[0], children, opt)
return children[0], nil
}
unionAll := LogicalPartitionUnionAll{}.Init(ds.SCtx(), ds.QueryBlockOffset())
unionAll := logicalop.LogicalPartitionUnionAll{}.Init(ds.SCtx(), ds.QueryBlockOffset())
unionAll.SetChildren(children...)
unionAll.SetSchema(ds.Schema().Clone())
appendMakeUnionAllChildrenTranceStep(ds, usedDefinition, unionAll, children, opt)
Expand Down
11 changes: 0 additions & 11 deletions pkg/planner/core/rule_topn_push_down.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package core

import (
"context"
"fmt"

"github.com/pingcap/tidb/pkg/planner/core/base"
"github.com/pingcap/tidb/pkg/planner/core/operator/logicalop"
Expand Down Expand Up @@ -55,13 +54,3 @@ func pushDownTopNForBaseLogicalPlan(lp base.LogicalPlan, topNLogicalPlan base.Lo
func (*PushDownTopNOptimizer) Name() string {
return "topn_push_down"
}

func appendNewTopNTraceStep(topN *logicalop.LogicalTopN, union *LogicalUnionAll, opt *optimizetrace.LogicalOptimizeOp) {
reason := func() string {
return ""
}
action := func() string {
return fmt.Sprintf("%v_%v is added and pushed down across %v_%v", topN.TP(), topN.ID(), union.TP(), union.ID())
}
opt.AppendStepToCurrent(topN.ID(), topN.TP(), reason, action)
}
Loading

0 comments on commit c74a233

Please sign in to comment.