Skip to content

Conversation

@mgartner
Copy link
Collaborator

@mgartner mgartner commented Nov 3, 2025

Backport:

Please see individual PRs for details.

/cc @cockroachdb/release


Release justification: Low-risk planning improvement for generic query plans.

@mgartner mgartner requested review from a team and michae2 November 3, 2025 17:33
@mgartner mgartner requested a review from a team as a code owner November 3, 2025 17:33
@blathers-crl
Copy link

blathers-crl bot commented Nov 3, 2025

Thanks for opening a backport.

Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate.

@blathers-crl blathers-crl bot added backport Label PR's that are backports to older release branches T-sql-queries SQL Queries Team labels Nov 3, 2025
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@mgartner mgartner changed the title release-25.3: TODO release-25.3: opt: estimate worst-case selectivity of placeholder equalities Nov 3, 2025
Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm:

@michae2 reviewed 14 of 14 files at r1, 10 of 10 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @mgartner)

Previously, we calculated the selectivity of placeholder equality
filters, e.g., `x = $1`, using the distinct count of a column and total
row count. This represented an average-case selectivity.

Now, we instead estimate the worst-case selectivity using the maximum
frequency of the histogram of the constrained column. This helps avoid
choosing a generic query plan under `plan_cache_mode=auto` that performs
poorly for heavy-hitter placeholder values.

Fixes cockroachdb#151373

Release note (performance improvement): The cost of generic query plans
is now calculated based on worst-case selectivities for placeholder
equalities (e.g., x = $1). This reduces the chance of suboptimal generic
query plans being chosen when `plan_cache_mode=auto`.
The `optimizer_use_max_frequency_selectivity` session setting has been
added. It is enabled by default. Disabling it reverts the selectivity
improvements added in cockroachdb#151409.

Release note: None
@mgartner mgartner force-pushed the backport25.3-151409-156654 branch from 7509c85 to 6bfc131 Compare November 4, 2025 21:19
@mgartner mgartner merged commit 369640a into cockroachdb:release-25.3 Nov 4, 2025
14 of 15 checks passed
@mgartner mgartner deleted the backport25.3-151409-156654 branch November 4, 2025 22:22
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 T-sql-queries SQL Queries Team target-release-25.3.6

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants