sql/stats: change order of operations in histogram.adjustCounts #86493
Labels
A-sql-table-stats
Table statistics (and their automatic refresh).
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
T-sql-queries
SQL Queries Team
Follow up from #79872. This issue tracks this TODO in
histogram.adjustCounts
:cockroach/pkg/sql/stats/histogram.go
Lines 314 to 316 in 6a51183
We use
histogram.adjustCounts
to adjust an existing histogram to match a given row count and distinct count. It is used both by statistics collection and statistics forecasting. While working on statistics forecasting, I noticed that sometimesadjustCounts
produces unexpected adjustments, and I believe this is because it accounts for the new distinct count before accounting for the new row count. If those were reversed, the adjustments would be better (at least in simple cases).For example:
Because this is a
TIME
column we cannot currently forecast the histogram, so instead we calladjustCounts
on the latest histogram with row count = 24 and distinct count = 18. I think the adjusted histogram should look like:But instead, it currently is:
Jira issue: CRDB-18781
The text was updated successfully, but these errors were encountered: