From 6f091fa2832681dcc496a776bd671023124720b1 Mon Sep 17 00:00:00 2001 From: AilinKid <314806019@qq.com> Date: Sun, 7 Apr 2024 16:11:49 +0800 Subject: [PATCH] make fmt Signed-off-by: AilinKid <314806019@qq.com> --- pkg/planner/util/coreusage/costMisc.go | 18 +++++++++++++++++- pkg/planner/util/coreusage/optTracer.go | 9 +++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/pkg/planner/util/coreusage/costMisc.go b/pkg/planner/util/coreusage/costMisc.go index cfdb599878f0a..9d53651942ee2 100644 --- a/pkg/planner/util/coreusage/costMisc.go +++ b/pkg/planner/util/coreusage/costMisc.go @@ -16,32 +16,39 @@ const ( CostFlagTrace ) +// CostVer2 is a structure of cost basic of version2 type CostVer2 struct { cost float64 trace *CostTrace } +// GetCost returns the cost value of the costVer2 func (c *CostVer2) GetCost() float64 { return c.cost } +// GetTrace returns the trace of current costVer2 func (c *CostVer2) GetTrace() *CostTrace { return c.trace } +// CostTrace record the basic factor and formula in cost est. type CostTrace struct { factorCosts map[string]float64 // map[factorName]cost, used to calibrate the cost model formula string // It used to trace the cost calculation. } +// GetFormula return the formula of current costTrace. func (c *CostTrace) GetFormula() string { return c.formula } +// GetFactorCosts return the factors of current costTrace. func (c *CostTrace) GetFactorCosts() map[string]float64 { return c.factorCosts } +// NewZeroCostVer2 return a new zero costVer2. func NewZeroCostVer2(trace bool) (ret CostVer2) { if trace { ret.trace = &CostTrace{make(map[string]float64), ""} @@ -53,6 +60,7 @@ func hasCostFlag(costFlag, flag uint64) bool { return (costFlag & flag) > 0 } +// TraceCost indicates whether to trace cost. func TraceCost(option *PlanCostOption) bool { if option != nil && hasCostFlag(option.CostFlag, CostFlagTrace) { return true @@ -60,7 +68,9 @@ func TraceCost(option *PlanCostOption) bool { return false } -func NewCostVer2(option *PlanCostOption, factor CostVer2Factor, cost float64, lazyFormula func() string) (ret CostVer2) { +// NewCostVer2 is the constructor of CostVer2. +func NewCostVer2(option *PlanCostOption, factor CostVer2Factor, cost float64, + lazyFormula func() string) (ret CostVer2) { ret.cost = cost if TraceCost(option) { ret.trace = &CostTrace{make(map[string]float64), ""} @@ -70,15 +80,18 @@ func NewCostVer2(option *PlanCostOption, factor CostVer2Factor, cost float64, la return ret } +// CostVer2Factor is a record of internal cost factor. type CostVer2Factor struct { Name string Value float64 } +// String return the current CostVer2Factor's format string. func (f CostVer2Factor) String() string { return fmt.Sprintf("%s(%v)", f.Name, f.Value) } +// SumCostVer2 sum the cost up of all the passed args. func SumCostVer2(costs ...CostVer2) (ret CostVer2) { if len(costs) == 0 { return @@ -101,6 +114,7 @@ func SumCostVer2(costs ...CostVer2) (ret CostVer2) { return ret } +// DivCostVer2 is div utility func of CostVer2. func DivCostVer2(cost CostVer2, denominator float64) (ret CostVer2) { ret.cost = cost.cost / denominator if cost.trace != nil { @@ -113,6 +127,7 @@ func DivCostVer2(cost CostVer2, denominator float64) (ret CostVer2) { return ret } +// MulCostVer2 is mul utility func of CostVer2. func MulCostVer2(cost CostVer2, scale float64) (ret CostVer2) { ret.cost = cost.cost * scale if cost.trace != nil { @@ -125,4 +140,5 @@ func MulCostVer2(cost CostVer2, scale float64) (ret CostVer2) { return ret } +// ZeroCostVer2 is a pre-defined zero CostVer2. var ZeroCostVer2 = NewZeroCostVer2(false) diff --git a/pkg/planner/util/coreusage/optTracer.go b/pkg/planner/util/coreusage/optTracer.go index f1df95cc1df37..d7a6a0cd38a13 100644 --- a/pkg/planner/util/coreusage/optTracer.go +++ b/pkg/planner/util/coreusage/optTracer.go @@ -20,7 +20,7 @@ import "github.com/pingcap/tidb/pkg/util/tracing" // logicalOptRule inside the accommodated pkg `util` should only be depended on by logical `rule` pkg. // // rule related -----> core/util -//**************************************** below logical optimize trace related ****************************************** +//********************** below logical optimize trace related ************************* // LogicalOptimizeOp is logical optimizing option for tracing. type LogicalOptimizeOp struct { @@ -68,7 +68,7 @@ func (op *LogicalOptimizeOp) RecordFinalLogicalPlan(build func() *tracing.PlanTr op.tracer.RecordFinalLogicalPlan(build()) } -//**************************************** below physical optimize trace related ****************************************** +//********************** below physical optimize trace related ************************* // PhysicalOptimizeOp is logical optimizing option for tracing. type PhysicalOptimizeOp struct { @@ -76,19 +76,23 @@ type PhysicalOptimizeOp struct { tracer *tracing.PhysicalOptimizeTracer } +// DefaultPhysicalOptimizeOption is default physical optimizing option. func DefaultPhysicalOptimizeOption() *PhysicalOptimizeOp { return &PhysicalOptimizeOp{} } +// WithEnableOptimizeTracer is utility func to append the PhysicalOptimizeTracer into current PhysicalOptimizeOp. func (op *PhysicalOptimizeOp) WithEnableOptimizeTracer(tracer *tracing.PhysicalOptimizeTracer) *PhysicalOptimizeOp { op.tracer = tracer return op } +// AppendCandidate is utility func to append the CandidatePlanTrace into current PhysicalOptimizeOp. func (op *PhysicalOptimizeOp) AppendCandidate(c *tracing.CandidatePlanTrace) { op.tracer.AppendCandidate(c) } +// GetTracer returns the current op's PhysicalOptimizeTracer. func (op *PhysicalOptimizeOp) GetTracer() *tracing.PhysicalOptimizeTracer { return op.tracer } @@ -104,6 +108,7 @@ type PlanCostOption struct { tracer *PhysicalOptimizeOp } +// GetTracer returns the current op's PhysicalOptimizeOp. func (op *PlanCostOption) GetTracer() *PhysicalOptimizeOp { return op.tracer }