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

opt: consider limit hint when costing distinct-on expressions #122442

Merged
merged 3 commits into from
Apr 18, 2024

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Apr 16, 2024

opt: add coster tests for disctinct-on expressions

This commit adds coster tests for distinct-on expressions. There were no
such tests before.

Release note: None

opt: consider limit hint when costing distinct-on expressions

Limit hints are now considered when costing DistinctOn expressions,
similarly to streaming GroupBy expressions. This matches the behavior of
the execution logic, where a DistinctOn emits a row with distinct
grouping columns as soon as it is read from its input. It does not need
to read all of its input to begin emitting rows.

Release note (performance improvement): The optimizer now costs
distinct-on operators more accurately. It may produce more efficient
query plans in some cases.

Epic: CRDB-37714

opt: add optimizer_use_improved_distinct_on_limit_hint_costing

The optimizer_use_improved_distinct_on_limit_hint_costing session
setting has been added which enables the improved costing of DistinctOn
expressions with limit hints added in the previous commit. It is enabled
by default.

Release note: None

This commit adds coster tests for distinct-on expressions. There were no
such tests before.

Release note: None
@mgartner mgartner requested a review from a team April 16, 2024 15:01
@mgartner mgartner requested a review from a team as a code owner April 16, 2024 15:01
@mgartner mgartner requested review from michae2 and removed request for a team April 16, 2024 15:01
@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: Nice work!

Reviewed 1 of 1 files at r1, 3 of 3 files at r2, 12 of 12 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @michae2)

Limit hints are now considered when costing DistinctOn expressions,
similarly to streaming GroupBy expressions. This matches the behavior of
the execution logic, where a DistinctOn emits a row with distinct
grouping columns as soon as it is read from its input. It does not need
to read all of its input to begin emitting rows.

Release note (performance improvement): The optimizer now costs
distinct-on operators more accurately. It may produce more efficient
query plans in some cases.
The `optimizer_use_improved_distinct_on_limit_hint_costing` session
setting has been added which enables the improved costing of DistinctOn
expressions with limit hints added in the previous commit. It is enabled
by default.

Release note: None
outputRowCount = math.Min(outputRowCount, required.LimitHint)
} else if grouping.Op() == opt.DistinctOnOp &&
c.evalCtx.SessionData().OptimizerUseImprovedDistinctOnLimitHintCosting {
inputRowCount = distinctOnLimitHint(outputRowCount, required.LimitHint)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note: We might need to use streamingGroupByInputLimitHint for streaming distinct-on expressions, to make the plan changes go away.

@mgartner
Copy link
Collaborator Author

There are a few intriguing plan changes, mostly from streaming distinct-ons to hash distinct-ons. @DrewKimball and I spent some time looking at this and we aren't super concerned with the changes—they should have very little impact on performance, if any. #122644 tracks some potential follow-up work.

@mgartner mgartner added backport-23.1.x Flags PRs that need to be backported to 23.1 backport-23.2.x Flags PRs that need to be backported to 23.2. backport-24.1.x Flags PRs that need to be backported to 24.1. labels Apr 18, 2024
@mgartner
Copy link
Collaborator Author

bors r+

@craig craig bot merged commit d17ebfe into cockroachdb:master Apr 18, 2024
21 of 22 checks passed
Copy link

blathers-crl bot commented Apr 18, 2024

Encountered an error creating backports. Some common things that can go wrong:

  1. The backport branch might have already existed.
  2. There was a merge conflict.
  3. The backport branch contained merge commits.

You might need to create your backport manually using the backport tool.


error creating merge commit from af62526 to blathers/backport-release-23.1-122442: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.1.x failed. See errors above.


error creating merge commit from af62526 to blathers/backport-release-23.2-122442: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 23.2.x failed. See errors above.


error creating merge commit from af62526 to blathers/backport-release-24.1-122442: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []

you may need to manually resolve merge conflicts with the backport tool.

Backport to branch 24.1.x failed. See errors above.


🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.1.x Flags PRs that need to be backported to 23.1 backport-23.2.x Flags PRs that need to be backported to 23.2. backport-24.1.x Flags PRs that need to be backported to 24.1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants