Skip to content
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

sql: add optimizer_use_limit_ordering_for_streaming_group_by session setting #94672

Conversation

msirek
Copy link
Contributor

@msirek msirek commented Jan 3, 2023

Fixes #93410

This commit adds the optimizer_use_limit_ordering_for_streaming_group_by session setting that defaults to true. When true, an exploration rule which uses the ordering specified in a
SELECT ... GROUP BY ... ORDER BY ... LIMIT n; statement as an interesting ordering to require from the input to the group-by expression, possibly eliminating a top-k operation. When false, the exploration rule is disabled.

Release note: None

@msirek msirek requested a review from a team as a code owner January 3, 2023 23:42
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@DrewKimball DrewKimball left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 11 of 11 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @rharding6373)

@@ -228,6 +228,10 @@ func (c *CustomFuncs) GenerateStreamingGroupByLimitOrderingHint(
groupingCols opt.ColSet,
newOrdering props.OrderingChoice,
) {
if !c.e.evalCtx.SessionData().OptimizerUseLimitOrderingForStreamingGroupBy {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add an xform test with this setting disabled and an expect-not to verify this works

Copy link
Collaborator

@rharding6373 rharding6373 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 2 of 0 LGTMs obtained (waiting on @msirek)

…setting

Fixes cockroachdb#93410

This commit adds the `optimizer_use_limit_ordering_for_streaming_group_by`
session setting that defaults to `true`. When `true`, an exploration
rule which uses the ordering specified in a
`SELECT ... GROUP BY ... ORDER BY ... LIMIT n;` statement as an
interesting ordering to require from the input to the group-by
expression, possibly eliminating a top-k operation.  When `false`, the
exploration rule is disabled.

Release note: None
@msirek msirek force-pushed the optimizer_use_limit_ordering_for_streaming_group_by branch from 905b302 to 63d9aed Compare January 5, 2023 02:34
Copy link
Contributor Author

@msirek msirek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTRs!
bors r+

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 2 stale) (waiting on @DrewKimball and @mgartner)


pkg/sql/opt/xform/groupby_funcs.go line 231 at r1 (raw file):

Previously, mgartner (Marcus Gartner) wrote…

nit: add an xform test with this setting disabled and an expect-not to verify this works

Done

@craig
Copy link
Contributor

craig bot commented Jan 5, 2023

Build succeeded:

@craig craig bot merged commit 4bfbe11 into cockroachdb:master Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suboptimal query plan on grouped aggregation with LIMIT and ORDER BY
5 participants