Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleFall committed May 13, 2022
1 parent 1d34a5b commit 09473a6
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 176 deletions.
2 changes: 1 addition & 1 deletion expression/aggregation/agg_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (desc *baseFuncDesc) GetTiPBExpr(tryWindowDesc bool) (tp tipb.ExprType) {
tp = tipb.ExprType_StddevSamp
}

if tipb.ExprType(tp) != 0 || !tryWindowDesc {
if tp != tipb.ExprType_Null || !tryWindowDesc {
return
}

Expand Down
5 changes: 3 additions & 2 deletions expression/aggregation/window_func.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
package aggregation

import (
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tipb/go-tipb"
"strings"

"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tipb/go-tipb"
)

// WindowFuncDesc describes a window function signature, only used in planner.
Expand Down Expand Up @@ -119,6 +119,7 @@ func WindowFuncToPBExpr(sctx sessionctx.Context, client kv.Client, desc *WindowF
return &tipb.Expr{Tp: tp, Children: children, FieldType: expression.ToPBFieldType(desc.RetTp)}
}

// CanPushDownToTiFlash control whether a window function desc can be push down to tiflash.
func (s *WindowFuncDesc) CanPushDownToTiFlash() bool {
// window functions
switch s.Name {
Expand Down
25 changes: 13 additions & 12 deletions planner/core/exhaust_physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -2222,6 +2222,7 @@ func disableAggPushDownToCop(p LogicalPlan) {
}
}

// GetPartitionKeys gets partition keys for a logical window, it will assign column id for expressions.
func (lw *LogicalWindow) GetPartitionKeys() []*property.MPPPartitionColumn {
partitionByCols := make([]*property.MPPPartitionColumn, 0, len(lw.GetPartitionByCols()))
for _, item := range lw.PartitionBy {
Expand Down Expand Up @@ -2317,12 +2318,12 @@ func (lw *LogicalWindow) tryToGetMppWindows(prop *property.PhysicalProperty) []P
return []PhysicalPlan{window}
}

func (p *LogicalWindow) exhaustPhysicalPlans(prop *property.PhysicalProperty) ([]PhysicalPlan, bool, error) {
func (lw *LogicalWindow) exhaustPhysicalPlans(prop *property.PhysicalProperty) ([]PhysicalPlan, bool, error) {
windows := make([]PhysicalPlan, 0, 2)

canPushToTiFlash := p.canPushToCop(kv.TiFlash)
if p.ctx.GetSessionVars().IsMPPAllowed() && canPushToTiFlash {
mppWindows := p.tryToGetMppWindows(prop)
canPushToTiFlash := lw.canPushToCop(kv.TiFlash)
if lw.ctx.GetSessionVars().IsMPPAllowed() && canPushToTiFlash {
mppWindows := lw.tryToGetMppWindows(prop)
windows = append(windows, mppWindows...)
}

Expand All @@ -2331,19 +2332,19 @@ func (p *LogicalWindow) exhaustPhysicalPlans(prop *property.PhysicalProperty) ([
return windows, true, nil
}
var byItems []property.SortItem
byItems = append(byItems, p.PartitionBy...)
byItems = append(byItems, p.OrderBy...)
byItems = append(byItems, lw.PartitionBy...)
byItems = append(byItems, lw.OrderBy...)
childProperty := &property.PhysicalProperty{ExpectedCnt: math.MaxFloat64, SortItems: byItems, CanAddEnforcer: true}
if !prop.IsPrefix(childProperty) {
return nil, true, nil
}
window := PhysicalWindow{
WindowFuncDescs: p.WindowFuncDescs,
PartitionBy: p.PartitionBy,
OrderBy: p.OrderBy,
Frame: p.Frame,
}.Init(p.ctx, p.stats.ScaleByExpectCnt(prop.ExpectedCnt), p.blockOffset, childProperty)
window.SetSchema(p.Schema())
WindowFuncDescs: lw.WindowFuncDescs,
PartitionBy: lw.PartitionBy,
OrderBy: lw.OrderBy,
Frame: lw.Frame,
}.Init(lw.ctx, lw.stats.ScaleByExpectCnt(prop.ExpectedCnt), lw.blockOffset, childProperty)
window.SetSchema(lw.Schema())

windows = append(windows, window)
return windows, true, nil
Expand Down
25 changes: 0 additions & 25 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,31 +204,6 @@ func (p *baseLogicalPlan) rebuildChildTasks(childTasks *[]task, pp PhysicalPlan,
return nil
}

func updateBestTask(bestTask, curTask task, mppEnforced bool) task {
if bestTask.invalid() {
return curTask
}
if curTask.invalid() {
return bestTask
}

if mppEnforced {
_, bestIsMpp := bestTask.(*mppTask)
_, curIsMpp := curTask.(*mppTask)

if curIsMpp && !bestIsMpp {
return curTask
}
if !curIsMpp && bestIsMpp {
return bestTask
}
}
if curTask.cost() < bestTask.cost() {
bestTask = curTask
}
return bestTask
}

func (p *baseLogicalPlan) enumeratePhysicalPlans4Task(physicalPlans []PhysicalPlan, prop *property.PhysicalProperty, addEnforcer bool, planCounter *PlanCounterTp, opt *physicalOptimizeOp) (task, int64, error) {
var bestTask task = invalidTask
var curCntPlan, cntPlan int64
Expand Down
7 changes: 3 additions & 4 deletions planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,7 @@ type WindowFrame struct {
End *FrameBound
}

// Clone copies a window frame totally.
func (wf *WindowFrame) Clone() *WindowFrame {
cloned := new(WindowFrame)
*cloned = *wf
Expand All @@ -1645,6 +1646,7 @@ type FrameBound struct {
CmpFuncs []expression.CompareFunc
}

// Clone copies a frame bound totally.
func (fb *FrameBound) Clone() *FrameBound {
cloned := new(FrameBound)
*cloned = *fb
Expand All @@ -1653,10 +1655,7 @@ func (fb *FrameBound) Clone() *FrameBound {
for _, it := range fb.CalcFuncs {
cloned.CalcFuncs = append(cloned.CalcFuncs, it.Clone())
}
cloned.CmpFuncs = make([]expression.CompareFunc, 0, len(fb.CmpFuncs))
for _, it := range fb.CmpFuncs {
cloned.CmpFuncs = append(cloned.CmpFuncs, it)
}
cloned.CmpFuncs = fb.CmpFuncs

return cloned
}
Expand Down
2 changes: 1 addition & 1 deletion planner/core/plan_to_pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func (p *PhysicalWindow) ToPB(ctx sessionctx.Context, storeType kv.StoreType) (*
// ToPB implements PhysicalPlan ToPB interface.
func (p *PhysicalSort) ToPB(ctx sessionctx.Context, storeType kv.StoreType) (*tipb.Executor, error) {
if !p.IsPartialSort {
return nil, errors.Errorf("sort %s can't convert to pb, because it isn't a partial sort.", p.basePlan.ExplainID())
return nil, errors.Errorf("sort %s can't convert to pb, because it isn't a partial sort", p.basePlan.ExplainID())
}

sc := ctx.GetSessionVars().StmtCtx
Expand Down
12 changes: 6 additions & 6 deletions planner/core/testdata/enforce_mpp_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@
"SQL": "explain format = 'brief' SELECT a, ROW_NUMBER() OVER (ORDER BY a) FROM t; -- 5. window unsupported",
"Plan": [
"TableReader 10000.00 root data:ExchangeSender",
"└─ExchangeSender 10000.00 cop[tiflash] ExchangeType: PassThrough",
" └─Window 10000.00 cop[tiflash] row_number()->Column#7 over(order by test.t.a rows between current row and current row)",
" └─Sort 10000.00 cop[tiflash] test.t.a",
" └─ExchangeReceiver 10000.00 cop[tiflash] ",
" └─ExchangeSender 10000.00 cop[tiflash] ExchangeType: PassThrough",
" └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
"└─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough",
" └─Window 10000.00 mpp[tiflash] row_number()->Column#7 over(order by test.t.a rows between current row and current row)",
" └─Sort 10000.00 mpp[tiflash] test.t.a",
" └─ExchangeReceiver 10000.00 mpp[tiflash] ",
" └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough",
" └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo"
],
"Warn": null
},
Expand Down
40 changes: 22 additions & 18 deletions planner/core/testdata/integration_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -4617,15 +4617,17 @@
{
"SQL": "desc format = 'brief' select * from (select id-2 as b from t) B join (select id-2 as b from t) A on A.b=B.b",
"Plan": [
"HashJoin 10000.00 root inner join, equal:[eq(Column#13, Column#26)]",
"├─TableReader(Build) 8000.00 root data:Projection",
"│ └─Projection 8000.00 cop[tiflash] minus(test.t.id, 2)->Column#26",
"│ └─Selection 8000.00 cop[tiflash] not(isnull(minus(test.t.id, 2)))",
"│ └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo",
"└─TableReader(Probe) 8000.00 root data:Projection",
" └─Projection 8000.00 cop[tiflash] minus(test.t.id, 2)->Column#13",
" └─Selection 8000.00 cop[tiflash] not(isnull(minus(test.t.id, 2)))",
" └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
"TableReader 10000.00 root data:ExchangeSender",
"└─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough",
" └─HashJoin 10000.00 mpp[tiflash] inner join, equal:[eq(Column#13, Column#26)]",
" ├─ExchangeReceiver(Build) 8000.00 mpp[tiflash] ",
" │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: Broadcast",
" │ └─Projection 8000.00 mpp[tiflash] minus(test.t.id, 2)->Column#13",
" │ └─Selection 8000.00 mpp[tiflash] not(isnull(minus(test.t.id, 2)))",
" │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo",
" └─Projection(Probe) 8000.00 mpp[tiflash] minus(test.t.id, 2)->Column#26",
" └─Selection 8000.00 mpp[tiflash] not(isnull(minus(test.t.id, 2)))",
" └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo"
]
},
{
Expand Down Expand Up @@ -4669,15 +4671,17 @@
"SQL": "desc format = 'brief' select A.b, B.b from (select id-2 as b from t) B join (select id-2 as b from t) A on A.b=B.b",
"Plan": [
"Projection 10000.00 root Column#26, Column#13",
"└─HashJoin 10000.00 root inner join, equal:[eq(Column#13, Column#26)]",
" ├─TableReader(Build) 8000.00 root data:Projection",
" │ └─Projection 8000.00 cop[tiflash] minus(test.t.id, 2)->Column#26",
" │ └─Selection 8000.00 cop[tiflash] not(isnull(minus(test.t.id, 2)))",
" │ └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo",
" └─TableReader(Probe) 8000.00 root data:Projection",
" └─Projection 8000.00 cop[tiflash] minus(test.t.id, 2)->Column#13",
" └─Selection 8000.00 cop[tiflash] not(isnull(minus(test.t.id, 2)))",
" └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo"
"└─TableReader 10000.00 root data:ExchangeSender",
" └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough",
" └─HashJoin 10000.00 mpp[tiflash] inner join, equal:[eq(Column#13, Column#26)]",
" ├─ExchangeReceiver(Build) 8000.00 mpp[tiflash] ",
" │ └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: Broadcast",
" │ └─Projection 8000.00 mpp[tiflash] minus(test.t.id, 2)->Column#13",
" │ └─Selection 8000.00 mpp[tiflash] not(isnull(minus(test.t.id, 2)))",
" │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo",
" └─Projection(Probe) 8000.00 mpp[tiflash] minus(test.t.id, 2)->Column#26",
" └─Selection 8000.00 mpp[tiflash] not(isnull(minus(test.t.id, 2)))",
" └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo"
]
},
{
Expand Down
Loading

0 comments on commit 09473a6

Please sign in to comment.