Skip to content

Commit 6f091fa

Browse files
committed
make fmt
Signed-off-by: AilinKid <[email protected]>
1 parent dbfe731 commit 6f091fa

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

pkg/planner/util/coreusage/costMisc.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,39 @@ const (
1616
CostFlagTrace
1717
)
1818

19+
// CostVer2 is a structure of cost basic of version2
1920
type CostVer2 struct {
2021
cost float64
2122
trace *CostTrace
2223
}
2324

25+
// GetCost returns the cost value of the costVer2
2426
func (c *CostVer2) GetCost() float64 {
2527
return c.cost
2628
}
2729

30+
// GetTrace returns the trace of current costVer2
2831
func (c *CostVer2) GetTrace() *CostTrace {
2932
return c.trace
3033
}
3134

35+
// CostTrace record the basic factor and formula in cost est.
3236
type CostTrace struct {
3337
factorCosts map[string]float64 // map[factorName]cost, used to calibrate the cost model
3438
formula string // It used to trace the cost calculation.
3539
}
3640

41+
// GetFormula return the formula of current costTrace.
3742
func (c *CostTrace) GetFormula() string {
3843
return c.formula
3944
}
4045

46+
// GetFactorCosts return the factors of current costTrace.
4147
func (c *CostTrace) GetFactorCosts() map[string]float64 {
4248
return c.factorCosts
4349
}
4450

51+
// NewZeroCostVer2 return a new zero costVer2.
4552
func NewZeroCostVer2(trace bool) (ret CostVer2) {
4653
if trace {
4754
ret.trace = &CostTrace{make(map[string]float64), ""}
@@ -53,14 +60,17 @@ func hasCostFlag(costFlag, flag uint64) bool {
5360
return (costFlag & flag) > 0
5461
}
5562

63+
// TraceCost indicates whether to trace cost.
5664
func TraceCost(option *PlanCostOption) bool {
5765
if option != nil && hasCostFlag(option.CostFlag, CostFlagTrace) {
5866
return true
5967
}
6068
return false
6169
}
6270

63-
func NewCostVer2(option *PlanCostOption, factor CostVer2Factor, cost float64, lazyFormula func() string) (ret CostVer2) {
71+
// NewCostVer2 is the constructor of CostVer2.
72+
func NewCostVer2(option *PlanCostOption, factor CostVer2Factor, cost float64,
73+
lazyFormula func() string) (ret CostVer2) {
6474
ret.cost = cost
6575
if TraceCost(option) {
6676
ret.trace = &CostTrace{make(map[string]float64), ""}
@@ -70,15 +80,18 @@ func NewCostVer2(option *PlanCostOption, factor CostVer2Factor, cost float64, la
7080
return ret
7181
}
7282

83+
// CostVer2Factor is a record of internal cost factor.
7384
type CostVer2Factor struct {
7485
Name string
7586
Value float64
7687
}
7788

89+
// String return the current CostVer2Factor's format string.
7890
func (f CostVer2Factor) String() string {
7991
return fmt.Sprintf("%s(%v)", f.Name, f.Value)
8092
}
8193

94+
// SumCostVer2 sum the cost up of all the passed args.
8295
func SumCostVer2(costs ...CostVer2) (ret CostVer2) {
8396
if len(costs) == 0 {
8497
return
@@ -101,6 +114,7 @@ func SumCostVer2(costs ...CostVer2) (ret CostVer2) {
101114
return ret
102115
}
103116

117+
// DivCostVer2 is div utility func of CostVer2.
104118
func DivCostVer2(cost CostVer2, denominator float64) (ret CostVer2) {
105119
ret.cost = cost.cost / denominator
106120
if cost.trace != nil {
@@ -113,6 +127,7 @@ func DivCostVer2(cost CostVer2, denominator float64) (ret CostVer2) {
113127
return ret
114128
}
115129

130+
// MulCostVer2 is mul utility func of CostVer2.
116131
func MulCostVer2(cost CostVer2, scale float64) (ret CostVer2) {
117132
ret.cost = cost.cost * scale
118133
if cost.trace != nil {
@@ -125,4 +140,5 @@ func MulCostVer2(cost CostVer2, scale float64) (ret CostVer2) {
125140
return ret
126141
}
127142

143+
// ZeroCostVer2 is a pre-defined zero CostVer2.
128144
var ZeroCostVer2 = NewZeroCostVer2(false)

pkg/planner/util/coreusage/optTracer.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import "github.com/pingcap/tidb/pkg/util/tracing"
2020
// logicalOptRule inside the accommodated pkg `util` should only be depended on by logical `rule` pkg.
2121
//
2222
// rule related -----> core/util
23-
//**************************************** below logical optimize trace related ******************************************
23+
//********************** below logical optimize trace related *************************
2424

2525
// LogicalOptimizeOp is logical optimizing option for tracing.
2626
type LogicalOptimizeOp struct {
@@ -68,27 +68,31 @@ func (op *LogicalOptimizeOp) RecordFinalLogicalPlan(build func() *tracing.PlanTr
6868
op.tracer.RecordFinalLogicalPlan(build())
6969
}
7070

71-
//**************************************** below physical optimize trace related ******************************************
71+
//********************** below physical optimize trace related *************************
7272

7373
// PhysicalOptimizeOp is logical optimizing option for tracing.
7474
type PhysicalOptimizeOp struct {
7575
// tracer is goring to track optimize steps during physical optimizing
7676
tracer *tracing.PhysicalOptimizeTracer
7777
}
7878

79+
// DefaultPhysicalOptimizeOption is default physical optimizing option.
7980
func DefaultPhysicalOptimizeOption() *PhysicalOptimizeOp {
8081
return &PhysicalOptimizeOp{}
8182
}
8283

84+
// WithEnableOptimizeTracer is utility func to append the PhysicalOptimizeTracer into current PhysicalOptimizeOp.
8385
func (op *PhysicalOptimizeOp) WithEnableOptimizeTracer(tracer *tracing.PhysicalOptimizeTracer) *PhysicalOptimizeOp {
8486
op.tracer = tracer
8587
return op
8688
}
8789

90+
// AppendCandidate is utility func to append the CandidatePlanTrace into current PhysicalOptimizeOp.
8891
func (op *PhysicalOptimizeOp) AppendCandidate(c *tracing.CandidatePlanTrace) {
8992
op.tracer.AppendCandidate(c)
9093
}
9194

95+
// GetTracer returns the current op's PhysicalOptimizeTracer.
9296
func (op *PhysicalOptimizeOp) GetTracer() *tracing.PhysicalOptimizeTracer {
9397
return op.tracer
9498
}
@@ -104,6 +108,7 @@ type PlanCostOption struct {
104108
tracer *PhysicalOptimizeOp
105109
}
106110

111+
// GetTracer returns the current op's PhysicalOptimizeOp.
107112
func (op *PlanCostOption) GetTracer() *PhysicalOptimizeOp {
108113
return op.tracer
109114
}

0 commit comments

Comments
 (0)