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

release-24.1: opt/memo: improve zigzag join cost and selectivity estimation with multi-column stats #123106

Merged
merged 4 commits into from
Apr 30, 2024

Conversation

rytaft
Copy link
Collaborator

@rytaft rytaft commented Apr 26, 2024

Backport 4/4 commits from #120805.

/cc @cockroachdb/release


opt: update seek and distribution cost of zigzag join to match scan

Prior to this commit, the optimizer could prefer a zigzag join over a
scan even if they produced the same number of rows. This was because scans
always included the cost of at least one seek (involving random I/O) and
some distribution cost, while zigzag joins did not. This commit updates
the cost of zigzag joins to include seek and distribution costs so they
will never be chosen over scans unless they produce fewer rows.

This change is behind the setting optimizer_use_improved_zigzag_join_costing.

Release note (performance improvement): Added a new setting
optimizer_use_improved_zigzag_join_costing. When enabled, the cost of zigzag
joins is updated so they will be never be chosen over scans unless they
produce fewer rows. This change only matters if the setting enable_zigzag_join
is also true.

opt/memo: improve selectivity estimation with multi-column stats

This commit updates correlationFromMultiColDistinctCounts in statisticsBuilder
to use a tighter lower bound for the multi-column selectivity. This avoids
cases where we significantly over-estimate the selectivity of a multi-column
predicate.

Fixes #121397

Release note (performance improvement): Improved the selectivity estimation of
multi-column filters when the multi-column distinct count is high. This avoids
cases where we significantly over-estimate the selectivity of a multi-column
predicate and as a result can prevent the optimizer from choosing a bad query
plan.

sql: add setting optimizer_use_improved_multi_column_selectivity_estimate

Informs #121397

Release note (sql change): Added a setting
optimizer_use_improved_multi_column_selectivity_estimate, which if enabled,
causes the optimizer to use an improved selectivity estimate for multi-column
predicates. This setting will default to true on versions 24.2+, and false
on prior versions.

opt: improve variable names in selectivityFromMultiColDistinctCounts

This commit improves the variable names in
selectivityFromMultiColDistinctCounts in statisticsBuilder to be more
self-documenting.

Release note: None


Release justification: low-risk, high benefit change to existing functionality to unblock a customer

Prior to this commit, the optimizer could prefer a zigzag join over a
scan even if they produced the same number of rows. This was because scans
always included the cost of at least one seek (involving random I/O) and
some distribution cost, while zigzag joins did not. This commit updates
the cost of zigzag joins to include seek and distribution costs so they
will never be chosen over scans unless they produce fewer rows.

This change is behind the setting optimizer_use_improved_zigzag_join_costing.

Release note (performance improvement): Added a new setting
optimizer_use_improved_zigzag_join_costing. When enabled, the cost of zigzag
joins is updated so they will be never be chosen over scans unless they
produce fewer rows. This change only matters if the setting enable_zigzag_join
is also true.
This commit updates correlationFromMultiColDistinctCounts in statisticsBuilder
to use a tighter lower bound for the multi-column selectivity. This avoids
cases where we significantly over-estimate the selectivity of a multi-column
predicate.

Fixes cockroachdb#121397

Release note (performance improvement): Improved the selectivity estimation of
multi-column filters when the multi-column distinct count is high. This avoids
cases where we significantly over-estimate the selectivity of a multi-column
predicate and as a result can prevent the optimizer from choosing a bad query
plan.
@rytaft rytaft requested review from a team as code owners April 26, 2024 01:53
@rytaft rytaft requested review from dt and removed request for a team April 26, 2024 01:53
Copy link

blathers-crl bot commented Apr 26, 2024

Thanks for opening a backport.

Please check the backport criteria before merging:

  • Backports should only be created for serious
    issues
    or test-only changes.
  • Backports should not break backwards-compatibility.
  • Backports should change as little code as possible.
  • Backports should not change on-disk formats or node communication protocols.
  • Backports should not add new functionality (except as defined
    here).
  • Backports must not add, edit, or otherwise modify cluster versions; or add version gates.
  • All backports must be reviewed by the owning areas TL and one additional
    TL. For more information as to how that review should be conducted, please consult the backport
    policy
    .
If your backport adds new functionality, please ensure that the following additional criteria are satisfied:
  • There is a high priority need for the functionality that cannot wait until the next release and is difficult to address in another way.
  • The new functionality is additive-only and only runs for clusters which have specifically “opted in” to it (e.g. by a cluster setting).
  • New code is protected by a conditional check that is trivial to verify and ensures that it only runs for opt-in clusters. State changes must be further protected such that nodes running old binaries will not be negatively impacted by the new state (with a mixed version test added).
  • The PM and TL on the team that owns the changed code have signed off that the change obeys the above rules.
  • Your backport must be accompanied by a post to the appropriate Slack
    channel (#db-backports-point-releases or #db-backports-XX-X-release) for awareness and discussion.

Also, please add a brief release justification to the body of your PR to justify this
backport.

@blathers-crl blathers-crl bot added the backport Label PR's that are backports to older release branches label Apr 26, 2024
@cockroach-teamcity
Copy link
Member

This change is Reviewable

…mate

Informs cockroachdb#121397

Release note (sql change): Added a setting
optimizer_use_improved_multi_column_selectivity_estimate, which if enabled,
causes the optimizer to use an improved selectivity estimate for multi-column
predicates. This setting will default to true on versions 24.2+, and false
on prior versions.
This commit improves the variable names in
selectivityFromMultiColDistinctCounts in statisticsBuilder to be more
self-documenting.

Release note: None
@rytaft
Copy link
Collaborator Author

rytaft commented Apr 30, 2024

Friendly ping @rafiss

@rytaft rytaft merged commit 4acd79a into cockroachdb:release-24.1 Apr 30, 2024
19 of 20 checks passed
@rytaft rytaft deleted the backport24.1-120805 branch April 30, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Label PR's that are backports to older release branches
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants