From 2efa9bacde9ce99a3b7ca677ee85533801f16b39 Mon Sep 17 00:00:00 2001 From: Han Fei Date: Fri, 13 Oct 2017 16:23:57 +0800 Subject: [PATCH] plan: fix bug about copy function. (#4765) --- plan/explain_test.go | 2 +- plan/new_physical_plan_builder.go | 2 +- plan/plan.go | 4 ++-- plan/stats.go | 7 ++++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plan/explain_test.go b/plan/explain_test.go index a4f6bcd9b7..6202465005 100644 --- a/plan/explain_test.go +++ b/plan/explain_test.go @@ -206,7 +206,7 @@ func (s *testExplainSuite) TestExplain(c *C) { "IndexScan_23 cop table:t2, index:c1, range:[,+inf], out of order:false 1.25", "TableScan_24 cop table:t2, keep order:false 1.25", "IndexLookUp_25 Selection_4 root index:IndexScan_23, table:TableScan_24 1.25", - "Selection_4 Limit_16 IndexLookUp_25 root eq(test.t1.c1, test.t2.c1) 6400", + "Selection_4 Limit_16 IndexLookUp_25 root eq(test.t1.c1, test.t2.c1) 1", "Limit_16 MaxOneRow_9 Selection_4 root offset:0, count:1 1", "MaxOneRow_9 Apply_13 Limit_16 root 1", "Apply_13 Projection_2 TableReader_15,MaxOneRow_9 root left outer join, small:MaxOneRow_9, right:MaxOneRow_9 8000", diff --git a/plan/new_physical_plan_builder.go b/plan/new_physical_plan_builder.go index a9b6c00ab2..a0f5965884 100644 --- a/plan/new_physical_plan_builder.go +++ b/plan/new_physical_plan_builder.go @@ -1030,7 +1030,7 @@ func (p *baseLogicalPlan) generatePhysicalPlans() []PhysicalPlan { } func (p *basePhysicalPlan) getChildrenPossibleProps(prop *requiredProp) [][]*requiredProp { - p.expectedCnt = prop.expectedCnt + p.basePlan.expectedCnt = prop.expectedCnt // By default, physicalPlan can always match the orders. props := make([]*requiredProp, 0, len(p.basePlan.children)) for range p.basePlan.children { diff --git a/plan/plan.go b/plan/plan.go index 471680a4bc..c268f83177 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -296,8 +296,6 @@ type baseLogicalPlan struct { type basePhysicalPlan struct { basePlan *basePlan - // expectedCnt means this operator may be closed after fetching expectedCnt records. - expectedCnt float64 } // ExplainInfo implements PhysicalPlan interface. @@ -453,6 +451,8 @@ type basePlan struct { ctx context.Context self Plan profile *statsProfile + // expectedCnt means this operator may be closed after fetching expectedCnt records. + expectedCnt float64 } func (p *basePlan) copy() *basePlan { diff --git a/plan/stats.go b/plan/stats.go index fbec9a8cbb..a81a69c634 100644 --- a/plan/stats.go +++ b/plan/stats.go @@ -40,9 +40,10 @@ func (s *statsProfile) collapse(factor float64) *statsProfile { func (p *basePhysicalPlan) statsProfile() *statsProfile { profile := p.basePlan.profile - if p.expectedCnt > 0 && p.expectedCnt < profile.count { - factor := p.expectedCnt / profile.count - profile.count = p.expectedCnt + expectedCnt := p.basePlan.expectedCnt + if expectedCnt > 0 && expectedCnt < profile.count { + factor := expectedCnt / profile.count + profile.count = expectedCnt for i := range profile.cardinality { profile.cardinality[i] = profile.cardinality[i] * factor }