From e32aba0d7035d69bde0090eb09535aafca4403e2 Mon Sep 17 00:00:00 2001 From: SeaRise <846579815@qq.com> Date: Mon, 23 Mar 2020 20:29:32 -0500 Subject: [PATCH] planner: implement BuildKeyInfo of LogicalTopN and LogicalTableDual (#15543) --- planner/core/rule_build_key_info.go | 16 ++++++++++++++++ .../core/testdata/plan_suite_unexported_out.json | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/planner/core/rule_build_key_info.go b/planner/core/rule_build_key_info.go index 1ec83ed113..aaf9de1efc 100644 --- a/planner/core/rule_build_key_info.go +++ b/planner/core/rule_build_key_info.go @@ -111,6 +111,22 @@ func (p *LogicalLimit) BuildKeyInfo(selfSchema *expression.Schema, childSchema [ } } +// BuildKeyInfo implements LogicalPlan BuildKeyInfo interface. +func (p *LogicalTopN) BuildKeyInfo(selfSchema *expression.Schema, childSchema []*expression.Schema) { + p.baseLogicalPlan.BuildKeyInfo(selfSchema, childSchema) + if p.Count == 1 { + p.maxOneRow = true + } +} + +// BuildKeyInfo implements LogicalPlan BuildKeyInfo interface. +func (p *LogicalTableDual) BuildKeyInfo(selfSchema *expression.Schema, childSchema []*expression.Schema) { + p.baseLogicalPlan.BuildKeyInfo(selfSchema, childSchema) + if p.RowCount == 1 { + p.maxOneRow = true + } +} + // A bijection exists between columns of a projection's schema and this projection's Exprs. // Sometimes we need a schema made by expr of Exprs to convert a column in child's schema to a column in this projection's Schema. func (p *LogicalProjection) buildSchemaByExprs(selfSchema *expression.Schema) *expression.Schema { diff --git a/planner/core/testdata/plan_suite_unexported_out.json b/planner/core/testdata/plan_suite_unexported_out.json index 567486bedb..6afb5519c3 100644 --- a/planner/core/testdata/plan_suite_unexported_out.json +++ b/planner/core/testdata/plan_suite_unexported_out.json @@ -169,7 +169,7 @@ "Err": false }, { - "Best": "Apply{UnionAll{UnionAll{Dual->Projection->Dual->Projection}->Aggr(firstrow(Column#4))->Projection->Dual->Projection}->Dual->Projection->MaxOneRow}->Sort->Projection", + "Best": "Join{UnionAll{UnionAll{Dual->Projection->Dual->Projection}->Aggr(firstrow(Column#4))->Projection->Dual->Projection}->Dual}->Sort->Projection", "Err": false } ]