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-23.1.20-rc: stats: more conservative lower bound for downward-trending forecasts #122990

Conversation

michae2
Copy link
Collaborator

@michae2 michae2 commented Apr 24, 2024

Backport:

/cc @cockroachdb/release


stats: more conservative lower bound for downward-trending forecasts

Instead of 0 as a lower bound for predictions, use 1/3 times the lowest prior observation. This will avoid predicting zero rows for a statistic unless we really observed zero rows somewhat recently.

Fixes: #119967

Release note (bug fix): Statistics forecasts of zero rows can cause bad plans. This commit changes forecasting to avoid predicting zero rows for most downward-trending statistics.

sql/stats: turn forecasting constants into cluster settings

Turn three constants used for statistics forecasting into cluster settings. (These must be cluster settings rather than session variables because forecasting happens when reloading table statistics in the stats cache, which can be independent of any session.)

Informs: #119967

Release note (sql change): Introduce three new cluster settings for controlling table statistics forecasting:

  1. sql.stats.forecasts.min_observations is the minimum number of observed statistics required to produce a forecast.

  2. sql.stats.forecasts.min_goodness_of_fit is the minimum R² (goodness of fit) measurement required from all predictive models to use a forecast.

  3. sql.stats.forecasts.max_decrease is the most a prediction can decrease, expressed as the minimum ratio of the prediction to the lowest prior observation.


Release justification: specially-requested fix for plan regression bug.

Instead of 0 as a lower bound for predictions, use 1/3 times the lowest
prior observation. This will avoid predicting zero rows for a statistic
unless we really observed zero rows somewhat recently.

Fixes: cockroachdb#119967

Release note (bug fix): Statistics forecasts of zero rows can cause bad
plans. This commit changes forecasting to avoid predicting zero rows for
most downward-trending statistics.
@michae2 michae2 requested a review from a team as a code owner April 24, 2024 17:31
Copy link

blathers-crl bot commented Apr 24, 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 24, 2024
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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

@michae2
Copy link
Collaborator Author

michae2 commented Apr 24, 2024

Fixes for the tests coming up, but this is RFAL.

@michae2 michae2 force-pushed the backport23.1.20-rc-122273-122779 branch from fd4a722 to ad6f459 Compare April 24, 2024 22:52
Copy link
Collaborator

@mgartner mgartner 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 3 of 3 files at r1, 4 of 4 files at r3, 5 of 5 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @michae2)

"sql.stats.forecasts.max_decrease",
"the most a prediction is allowed to decrease, expressed as the minimum ratio of the prediction "+
"to the lowest prior observation",
1.0/3.0,
Copy link
Collaborator

@mgartner mgartner Apr 25, 2024

Choose a reason for hiding this comment

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

Should we set this to 1 by default in backports to retain the old behavior? Would that reduce risk of this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I will do that.

@michae2 michae2 force-pushed the backport23.1.20-rc-122273-122779 branch from ad6f459 to 8294fe2 Compare April 25, 2024 05:52
Turn three constants used for statistics forecasting into cluster
settings. (These must be cluster settings rather than session variables
because forecasting happens when reloading table statistics in the stats
cache, which can be independent of any session.)

Informs: cockroachdb#119967

Release note (sql change): Introduce three new cluster settings for
controlling table statistics forecasting:

1. `sql.stats.forecasts.min_observations` is the minimum number of
   observed statistics required to produce a forecast.

2. `sql.stats.forecasts.min_goodness_of_fit` is the minimum R² (goodness
   of fit) measurement required from all predictive models to use a
   forecast.

3. `sql.stats.forecasts.max_decrease` is the most a prediction can
   decrease, expressed as the minimum ratio of the prediction to the
   lowest prior observation.
@michae2 michae2 force-pushed the backport23.1.20-rc-122273-122779 branch from 8294fe2 to 15a5b0e Compare April 25, 2024 06:23
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 3 of 3 files at r1, 4 of 4 files at r3, 5 of 5 files at r5, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner)

@michae2 michae2 merged commit 7f7551b into cockroachdb:release-23.1.20-rc Apr 25, 2024
6 checks passed
@michae2 michae2 deleted the backport23.1.20-rc-122273-122779 branch April 25, 2024 16:03
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

5 participants