-
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: disable GenerateParameterizedJoin
for custom query plans
#128409
opt: disable GenerateParameterizedJoin
for custom query plans
#128409
Conversation
In cockroachdb#85935 we introduced the `set` flag to set session settings in optimizer tests and a few flags that were already controlling session settings were removed. The documentation of those old flags has been removed. Release note: None
The exploration rule `GenerateParameterizedJoin` is now disabled when a custom query plan is being built. The mechanism for toggling this rule is using either `Optimizer.Optimize()` which disables the rule or `Optimizer.OptimizeGeneric()` which enables the rule. Note that the rule is not toggled by the `plan_cache_mode` session setting, because the `auto` mode may build custom or generic query plans. Also, changing the `plan_cache_mode` session setting does not make memos stale as other session settings do, because generic memos are kept separate from the unoptimized memos reused to build custom plans. Release note: None
Optgen now supports the "Generic" tag and the `IsGeneric()` method has been added to `RuleName` which returns true if the rule has the tag. The new method is used to disable rules that optimize generic query plans when custom plans are being built. Release note: None
I'll backport only the second commit to 23.2 and 24.1. See the conversation in #128085 (review). |
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.
Reviewed 1 of 1 files at r1, 6 of 6 files at r2, 3 of 3 files at r3, all commit messages.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @michae2, and @rytaft)
pkg/sql/opt/xform/optimizer.go
line 244 at r2 (raw file):
originalMatchedRule := o.matchedRule defer func() { o.matchedRule = originalMatchedRule }() o.matchedRule = func(r opt.RuleName) bool {
[nit] I'm open to pushback, but I'd prefer to make generic rule checks part of the generated rule code (probably here and here). We could use the Generic
tag to do that. For the backportable portion, we could just make the check part of the GenerateParameterizedJoin
rule as a custom func. What do you think?
Previously, DrewKimball (Drew Kimball) wrote…
Any reason you can't just check the value of |
I agree with avoiding use of
Ya, we could just check |
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.
Why doesn't the HasPlaceholdersOrStableExprs
check at the beginning of the rule suffice for disabling the rule when optimizing custom plans? It seems like that check will always be false when optimizing a custom plan. But maybe I'm missing something?
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @DrewKimball and @rytaft)
It mostly does. However, if we fail to fold a stable function during normalization, then we'll leave the unfolded function in the memo. In those rare cases, GenerateParameterizedJoin could fire during exploration even if In any case, I think the simplest and safest thing to do is what @rytaft suggests and add a simple check for |
Please review the alternative PR #129050. |
opt: remove documentation of old flags
In #85935 we introduced the
set
flag to set session settings inoptimizer tests and a few flags that were already controlling session
settings were removed. The documentation of those old flags has been
removed.
Release note: None
opt: disable
GenerateParameterizedJoin
for custom query plansThe exploration rule
GenerateParameterizedJoin
is now disabled when acustom query plan is being built. The mechanism for toggling this rule
is using either
Optimizer.Optimize()
which disables the rule orOptimizer.OptimizeGeneric()
which enables the rule. Note that the ruleis not toggled by the
plan_cache_mode
session setting, because theauto
mode may build custom or generic query plans. Also, changing theplan_cache_mode
session setting does not make memos stale as othersession settings do, because generic memos are kept separate from the
unoptimized memos reused to build custom plans.
Epic: None
Release note: None
opt: add "Generic" optgen tag
Optgen now supports the "Generic" tag and the
IsGeneric()
method hasbeen added to
RuleName
which returns true if the rule has the tag. Thenew method is used to disable rules that optimize generic query plans
when custom plans are being built.
Release note: None