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-25.1: opt: add new optimizer session settings #140245

Merged

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Jan 31, 2025

Backport:

Please see individual PRs for details.

/cc @cockroachdb/release

Release justification: Optimizer changes gated behind session settings.

Release note (sql change): The `optimizer_prefer_bounded_cardinality`
session setting has been added which instructs the optimizer to prefer
query plans where every expression has a guaranteed upper-bound on the
number of rows it will process. This may help the optimizer produce
better query plans in some cases. This setting is disabled by default.
Informs cockroachdb#64570
Informs cockroachdb#130201

Release note (sql change): The `optimizer_min_row_count` session setting
has been added which sets a lower bound on row count estimates for
relational expressions during query planning. A value of zero, which is
the default, indicates no lower bound. Note that if this is set to a
value greater than zero, a row count of zero can still be estimated for
expressions with a cardinality of zero, e.g., for a contradictory
filter. Setting this to a value higher than 0, such as 1, may yield
better query plans in some cases, such as when statistics are frequently
stale and inaccurate.
@mgartner mgartner requested a review from a team January 31, 2025 19:24
@mgartner mgartner requested a review from a team as a code owner January 31, 2025 19:24
@mgartner mgartner requested review from yuzefovich and removed request for a team January 31, 2025 19:24
Copy link

blathers-crl bot commented Jan 31, 2025

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. 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 Jan 31, 2025
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Collaborator

@rytaft rytaft 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 14 of 14 files at r1, 20 of 20 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

@mgartner mgartner merged commit 42f0c1b into cockroachdb:release-25.1 Jan 31, 2025
19 of 20 checks passed
@mgartner mgartner deleted the backport25.1-139985-140065 branch January 31, 2025 20:24
Copy link
Member

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

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

Reviewed 14 of 14 files at r1, 19 of 20 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained


pkg/sql/opt/props/statistics.go line 145 at r2 (raw file):

		s.RowCount = 0
	} else if r := s.RowCount * selectivity.AsFloat(); r < s.minRowCount {
		s.Selectivity.Multiply(MakeSelectivityFromFraction(s.minRowCount, s.RowCount))

Just to double check my understanding here. If we were to apply selectivity to s, the row count would get below minRowCount, so we don't want to do that. We update RowCount to minRowCount to not go below the defined lower bound; we also need to keep s.Selectivity in sync with s.RowCount, so we update the selectivity accordingly. Right?


pkg/sql/vars.go line 3776 at r2 (raw file):

				return err
			}
			// Note that we permit fractions above 1.0 to allow for giving

nit: copy-pasted comment isn't applicable here :)

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.

4 participants