-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
planner: consider agg func type in cost model #12038
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -873,15 +873,22 @@ func (p *PhysicalStreamAgg) attach2Task(tasks ...task) task { | |
|
||
// GetCost computes cost of stream aggregation considering CPU/memory. | ||
func (p *PhysicalStreamAgg) GetCost(inputRows float64, isRoot bool) float64 { | ||
numAggFunc := len(p.AggFuncs) | ||
if numAggFunc == 0 { | ||
numAggFunc = 1 | ||
aggFactorSum := 0.0 | ||
for _, agg := range p.AggFuncs { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not extract a function for them? |
||
if fac, ok := aggFuncFactor[agg.Name]; ok { | ||
aggFactorSum += fac | ||
} else { | ||
aggFactorSum += aggFuncFactor["default"] | ||
} | ||
} | ||
if aggFactorSum == 0 { | ||
aggFactorSum = 1.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So no agg func has more cost that single There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My opinion is that bit operation costs lower than other base operations. |
||
} | ||
var cpuCost float64 | ||
if isRoot { | ||
cpuCost = inputRows * cpuFactor * float64(numAggFunc) | ||
cpuCost = inputRows * cpuFactor * aggFactorSum | ||
} else { | ||
cpuCost = inputRows * copCPUFactor * float64(numAggFunc) | ||
cpuCost = inputRows * copCPUFactor * aggFactorSum | ||
} | ||
rowsPerGroup := inputRows / p.statsInfo().RowCount | ||
memoryCost := rowsPerGroup * distinctFactor * memoryFactor * float64(p.numDistinctFunc()) | ||
|
@@ -954,23 +961,30 @@ func (p *PhysicalHashAgg) attach2Task(tasks ...task) task { | |
func (p *PhysicalHashAgg) GetCost(inputRows float64, isRoot bool) float64 { | ||
cardinality := p.statsInfo().RowCount | ||
numDistinctFunc := p.numDistinctFunc() | ||
numAggFunc := len(p.AggFuncs) | ||
if numAggFunc == 0 { | ||
numAggFunc = 1 | ||
aggFactorSum := 0.0 | ||
for _, agg := range p.AggFuncs { | ||
if fac, ok := aggFuncFactor[agg.Name]; ok { | ||
aggFactorSum += fac | ||
} else { | ||
aggFactorSum += aggFuncFactor["default"] | ||
} | ||
} | ||
if aggFactorSum == 0 { | ||
aggFactorSum = 1.0 | ||
} | ||
var cpuCost float64 | ||
if isRoot { | ||
cpuCost = inputRows * cpuFactor * float64(numAggFunc) | ||
cpuCost = inputRows * cpuFactor * aggFactorSum | ||
divisor, con := p.cpuCostDivisor(numDistinctFunc > 0) | ||
if divisor > 0 { | ||
cpuCost /= divisor | ||
// Cost of additional goroutines. | ||
cpuCost += (con + 1) * concurrencyFactor | ||
} | ||
} else { | ||
cpuCost = inputRows * copCPUFactor * float64(numAggFunc) | ||
cpuCost = inputRows * copCPUFactor * aggFactorSum | ||
} | ||
memoryCost := cardinality * memoryFactor * float64(numAggFunc) | ||
memoryCost := cardinality * memoryFactor * aggFactorSum | ||
// When aggregation has distinct flag, we would allocate a map for each group to | ||
// check duplication. | ||
memoryCost += inputRows * distinctFactor * memoryFactor * float64(numDistinctFunc) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you dicide their values?
And what is
defalut
for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default
is just for safety.