-
Notifications
You must be signed in to change notification settings - Fork 590
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
feat(binder): add const case-when evaluation optimization during binding #14965
Conversation
@@ -469,6 +469,60 @@ impl Binder { | |||
Ok(func_call.into()) | |||
} | |||
|
|||
/// The optimization check for the following case-when expression pattern | |||
/// e.g., select case 1 when (...) then (...) else (...) end; | |||
fn check_constant_case_when_optimization( |
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.
The reason I create another check function is that we can't check all the optimizable case-when patterns within only one pass, and they indeed have subtle but significant difference, which may not be generalized.
src/frontend/src/binder/expr/mod.rs
Outdated
// Here we reuse the `ConstantLookup` as the `FunctionCall` | ||
// to avoid creating a dummy `ConstCaseWhenEval` expression type | ||
// since we do not need to go through backend | ||
return Ok(FunctionCall::new( | ||
ExprType::ConstantLookup, | ||
constant_case_when_eval_inputs, | ||
)? | ||
.into()); |
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.
Can we just return constant_case_when_eval_inputs[0]
here? Then we don't even need to use a rule to convert it later.
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.
Then what type should we return, I doubt FunctionCall would work 🤔, also Literal may not be the appropriate one.
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.
This method returns an ExprImpl
, an enum that could be any expression type.
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.
Got it!
Then I think return a bound expression should work, and I'll remove the relevant rules. 😄
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.
LGTM
I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
As titled, the optimization goes to case-when expression in below format, e.g.,
related: #14586 (comment).
And since I'm new to optimizer, feel free to point out any part I may have missed and any suggestion is welcomed. 😄
Checklist
./risedev check
(or alias,./risedev c
)Documentation
Release note
If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.