Skip to content

Commit

Permalink
plan, executor: clean code (pingcap#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfei1991 authored and zimulala committed Jan 22, 2017
1 parent 884f772 commit 6ae4b77
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 93 deletions.
6 changes: 0 additions & 6 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ func (b *executorBuilder) build(p plan.Plan) Executor {
return b.buildDeallocate(v)
case *plan.Delete:
return b.buildDelete(v)
case *plan.Distinct:
return b.buildDistinct(v)
case *plan.Execute:
return b.buildExecute(v)
case *plan.Explain:
Expand Down Expand Up @@ -192,10 +190,6 @@ func (b *executorBuilder) buildLimit(v *plan.Limit) Executor {
return e
}

func (b *executorBuilder) buildDistinct(v *plan.Distinct) Executor {
return &DistinctExec{Src: b.build(v.GetChildByIndex(0)), schema: v.GetSchema()}
}

func (b *executorBuilder) buildPrepare(v *plan.Prepare) Executor {
return &PrepareExec{
Ctx: b.ctx,
Expand Down
46 changes: 0 additions & 46 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ import (
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/terror"
"github.com/pingcap/tidb/util/distinct"
"github.com/pingcap/tidb/util/types"
)

var (
_ Executor = &ApplyExec{}
_ Executor = &CheckTableExec{}
_ Executor = &DistinctExec{}
_ Executor = &DummyScanExec{}
_ Executor = &ExistsExec{}
_ Executor = &HashAggExec{}
Expand Down Expand Up @@ -309,50 +307,6 @@ type orderByRow struct {
row *Row
}

// DistinctExec represents Distinct executor.
// It ignores duplicate rows from source Executor by using a *distinct.Checker which maintains
// a map to check duplication.
// Because every distinct row will be added to the map, the memory usage might be very high.
type DistinctExec struct {
Src Executor
checker *distinct.Checker
schema expression.Schema
}

// Schema implements the Executor Schema interface.
func (e *DistinctExec) Schema() expression.Schema {
return e.schema
}

// Next implements the Executor Next interface.
func (e *DistinctExec) Next() (*Row, error) {
if e.checker == nil {
e.checker = distinct.CreateDistinctChecker()
}
for {
row, err := e.Src.Next()
if err != nil {
return nil, errors.Trace(err)
}
if row == nil {
return nil, nil
}
ok, err := e.checker.Check(types.DatumsToInterfaces(row.Data))
if err != nil {
return nil, errors.Trace(err)
}
if !ok {
continue
}
return row, nil
}
}

// Close implements the Executor Close interface.
func (e *DistinctExec) Close() error {
return e.Src.Close()
}

// ReverseExec produces reverse ordered result, it is used to wrap executors that do not support reverse scan.
type ReverseExec struct {
Src Executor
Expand Down
5 changes: 0 additions & 5 deletions plan/match_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,6 @@ func (p *Limit) matchProperty(_ *requiredProperty, _ ...*physicalPlanInfo) *phys
panic("You can't call this function!")
}

// matchProperty implements PhysicalPlan matchProperty interface.
func (p *Distinct) matchProperty(_ *requiredProperty, _ ...*physicalPlanInfo) *physicalPlanInfo {
panic("You can't call this function!")
}

// matchProperty implements PhysicalPlan matchProperty interface.
func (p *TableDual) matchProperty(_ *requiredProperty, _ ...*physicalPlanInfo) *physicalPlanInfo {
panic("You can't call this function!")
Expand Down
23 changes: 0 additions & 23 deletions plan/physical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1028,29 +1028,6 @@ func (p *Apply) convert2PhysicalPlan(prop *requiredProperty) (*physicalPlanInfo,
return info, nil
}

// convert2PhysicalPlan implements the LogicalPlan convert2PhysicalPlan interface.
// TODO: support streaming distinct.
func (p *Distinct) convert2PhysicalPlan(prop *requiredProperty) (*physicalPlanInfo, error) {
info, err := p.getPlanInfo(prop)
if err != nil {
return nil, errors.Trace(err)
}
if info != nil {
return info, nil
}
child := p.GetChildByIndex(0).(LogicalPlan)
limit := prop.limit
info, err = child.convert2PhysicalPlan(removeLimit(prop))
if err != nil {
return nil, errors.Trace(err)
}
info = addPlanToResponse(p, info)
info.count = uint64(float64(info.count) * distinctFactor)
info = enforceProperty(limitProperty(limit), info)
p.storePlanInfo(prop, info)
return info, nil
}

// physicalInitialize will set value of some attributes after convert2PhysicalPlan process.
// Currently, only attribute "correlated" is considered.
func physicalInitialize(p PhysicalPlan) {
Expand Down
6 changes: 0 additions & 6 deletions plan/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,12 +666,6 @@ func (p *PhysicalHashJoin) SetCorrelated() {
}
}

// Copy implements the PhysicalPlan Copy interface.
func (p *Distinct) Copy() PhysicalPlan {
np := *p
return &np
}

// Copy implements the PhysicalPlan Copy interface.
func (p *Selection) Copy() PhysicalPlan {
np := *p
Expand Down
5 changes: 0 additions & 5 deletions plan/plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ type Limit struct {
Count uint64
}

// Distinct represents Distinct plan.
type Distinct struct {
baseLogicalPlan
}

// Prepare represents prepare plan.
type Prepare struct {
basePlan
Expand Down
2 changes: 0 additions & 2 deletions plan/stringer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ func toString(in Plan, strs []string, idxs []int) ([]string, []int) {
}
}
str += ")"
case *Distinct:
str = "Distinct"
case *Trim:
str = "Trim"
case *Cache:
Expand Down

0 comments on commit 6ae4b77

Please sign in to comment.