forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
colexec: optimize any_not_null func for hash aggregation
When we're performing hash aggregation, we know that there will be exactly one group. This insight allows us optimize the aggregate functions, and this commit performs the optimization of any_not_null. Now we will have two separate files for both aggregator kinds (hash and ordered), and that part is handled by a preprocessing step that replaces `_AGGKIND` template "variable" with the corresponding aggregator kind. I looked into introducing some base struct for aggregates to reuse, but it is rather complicated at the moment - some aggregate functions iterate over `[]*oneArgOverload`, and we could flatten that out. However, other functions operate with a custom "tmpl info" struct. Furthermore, extending the struct to include `AggKind` variable would require refactoring the templates themselves because we assume that `.` (dot) of the template usually is at `lastArgWidthOverload` struct. Probably in order to provide some "aggregate base tmpl info" struct that would help with hash vs ordered aggregation generation we would need to introduce an interface which custom tmpl infos will implement. Release note: None
- Loading branch information
1 parent
70e04ec
commit 2bf8764
Showing
7 changed files
with
103 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
) | ||
|
||
const ( | ||
// aggKindTmplVar specifies the template "variable" that describes the kind | ||
// of aggregator using an aggregate function. It is replaced with either | ||
// "Hash" or "Ordered" before executing the template. | ||
aggKindTmplVar = "_AGGKIND" | ||
hashAggKind = "Hash" | ||
orderedAggKind = "Ordered" | ||
) | ||
|
||
func registerAggGenerator(aggGen generator, filenameSuffix, dep string) { | ||
aggGeneratorAdapter := func(aggKind string) generator { | ||
return func(inputFileContents string, wr io.Writer) error { | ||
inputFileContents = strings.ReplaceAll(inputFileContents, aggKindTmplVar, aggKind) | ||
return aggGen(inputFileContents, wr) | ||
} | ||
} | ||
for _, aggKind := range []string{hashAggKind, orderedAggKind} { | ||
registerGenerator( | ||
aggGeneratorAdapter(aggKind), | ||
fmt.Sprintf("%s_%s", strings.ToLower(aggKind), filenameSuffix), | ||
dep, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters