-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
release-25.1: opt: add new optimizer session settings #140245
Conversation
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.
Thanks for opening a backport. Please check the backport criteria before merging:
If your backport adds new functionality, please ensure that the following additional criteria are satisfied:
Also, please add a brief release justification to the body of your PR to justify this |
There was a problem hiding this 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, 20 of 20 files at r2, all commit messages.
Reviewable status: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)
There was a problem hiding this 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: 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 :)
Backport:
optimizer_prefer_bounded_cardinality
session setting" (opt: addoptimizer_prefer_bounded_cardinality
session setting #139985)optimizer_min_row_count
session setting" (opt: addoptimizer_min_row_count
session setting #140065)Please see individual PRs for details.
/cc @cockroachdb/release
Release justification: Optimizer changes gated behind session settings.