main: update optgen Op alias to match current memo group member#94112
Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom Dec 22, 2022
Merged
main: update optgen Op alias to match current memo group member#94112craig[bot] merged 1 commit intocockroachdb:masterfrom
craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
Member
Contributor
Author
|
The generated code looks like this with the fix: // [GenerateStreamingGroupByLimitOrderingHint]
{
_partlyExplored := _rootOrd < _rootState.start
aggregation := _root.Input
_state := _e.lookupExploreState(aggregation)
if !_state.fullyExplored {
_fullyExplored = false
}
var _member memo.RelExpr
for _ord := 0; _ord < _state.end; _ord++ {
if _member == nil {
_member = aggregation.FirstExpr()
} else {
_member = _member.NextExpr()
}
aggregation = _member
if !_partlyExplored || _ord >= _state.start {
if _member.Op() == opt.GroupByOp || _member.Op() == opt.DistinctOnOp {
...
... |
DrewKimball
approved these changes
Dec 21, 2022
Collaborator
DrewKimball
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained
Fixes cockroachdb#94042 This fixes a slightly confusing feature of optgen where an alias in a match rule is assigned to the first expression in the group, and may be of a different expression type than the allowed Ops in the match rule. Example: ``` [GenerateStreamingGroupByLimitOrderingHint, Explore] (Limit $aggregation:(GroupBy | DistinctOn ``` Given this match rule, it looks like `$aggregation` can only be a GroupBy or DistinctOn expression. But in cockroachdb#94042, it is sometimes a Select expression. The variable is later used to generate a new expression with the assumption it is one of the allowed Op types, causing a panic. This is fixed by updating the optgen rule gen code to keep the alias up-to-date with the current memo group member being examined in the match rule, as it cycles through all members in the group. Release note: None
msirek
commented
Dec 22, 2022
Contributor
Author
msirek
left a comment
There was a problem hiding this comment.
TFTR!
bors r=DrewKimball
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale)
Contributor
|
Build succeeded: |
This was referenced Dec 22, 2022
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #94042
This fixes a slightly confusing feature of optgen where an alias in a match rule is assigned to the first expression in the group, and may be of a different expression type than the allowed Ops in the match rule.
Example:
Given this match rule snippet, it looks like
$aggregationcan only be a GroupBy or DistinctOn expression. But in #94042, it is sometimes a Select expression. The variable is later used to generate a new expression with the assumption it is one of the allowed Op types, causing a panic.This is fixed by updating the optgen rule gen code to keep the alias up-to-date with the current memo group member being examined in the match rule, as it cycles through all members in the group.
Release note: None