forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
43547: opt: add exploration rules for min/max => limit 1 transform r=andy-kimball a=andy-kimball Add new rules that work similarly to the existing ReplaceMaxWithLimit and ReplaceMinWithLimit rules, except that they recognize the non-Scalar GroupBy case. The new rules add an ordered LIMIT 1 to the input when it can be proven that there is at most one group, and there exists a single min/max aggregate function operating on that group. In that case, the GROUP BY can be entirely replaced by a PROJECT, similar to this: SELECT min(k) FROM kw WHERE w = 5 GROUP BY w => SELECT k FROM kw@w WHERE w = 5 Note that the Max and Min versions of this rule are not fully symmetric. This is because NULL values sort first in CRDB. This can interfere with the calculation of the Min function, because NULL values need to be ignored unless the group contains only NULL values (in which case the function returns NULL). Therefore, this rule only works when the MIN column is NOT NULL, as only in that case is one input row always sufficient to calculate MIN. Release note (sql change): Add optimization to scan over only 1 row when finding the MIN/MAX of a single aggregate group, as long as the correct index is present. Co-authored-by: Andrew Kimball <andyk@cockroachlabs.com>
- Loading branch information
Showing
21 changed files
with
806 additions
and
182 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
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
Oops, something went wrong.