-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
opt: add FoldFunctionWithNullArg normalization rule #62924
Conversation
The first commit is from #62893. |
This might be proof that we can fold ANY function where cockroach/pkg/sql/sem/tree/eval.go Line 4005 in f7f895c
It looks like a function is never really evaluated in that case. So maybe I can lift the restrictions on the function being non-volatile and a normal function? |
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.
To decide whether to support volatile and non-normal functions, maybe check what the TypeCheck
code does for non-typed NULLs? Might also be useful to get the perspective from @yuzefovich on the execution side. But it seems to me like at least volatile functions should be safe to fold here. Not 100% sure about non-normal functions.
Reviewed 3 of 3 files at r1, 5 of 5 files at r2.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @RaduBerinde)
LGTM In principle, we can have a volatile function that has some side-effect, even if it always returns NULL on NULL input. But I don't think we have any real cases like that, and as you pointed out, the existing code wouldn't evaluate it anyway:
Let's add to the documentation for |
1ed91cd
to
034d894
Compare
Good idea. Done. |
This commit adds the `FoldFunctionWithNullArg` normalization rule which folds a function that does not allow Null arguments to Null when one of the arguments is Null. See the documentation for the new rule for more details. Release note (performance improvement): The optimizer now folds functions to `NULL` when the function does not allow `NULL` arguments and one of the arguments is a `NULL` constant. As a result, more efficient query plans will be produced for queries with these types of function calls.
034d894
to
f415ac4
Compare
@RaduBerinde mind taking a final look before I merge? |
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.
Reviewable status:
complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @rytaft)
TFTRs! bors r+ |
Build succeeded: |
This commit adds the
FoldFunctionWithNullArg
normalization rule whichfolds a function that does not allow Null arguments to Null when one of
the arguments is Null. See the documentation for the new rule for more
details.
Release note (performance improvement): The optimizer now folds
functions to
NULL
when the function does not allowNULL
argumentsand one of the arguments is a
NULL
constant. As a result, moreefficient query plans will be produced for queries with these types of
function calls.