-
Notifications
You must be signed in to change notification settings - Fork 9k
Update two-stacks thresholds of promql function deriv() #118987
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
Merged
nikitamikhaylov
merged 1 commit into
ClickHouse:master
from
vitlibar:timeseries-two-stacks-thresholds
Sep 9, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,20 +6,20 @@ | |
|
|
||
| <!-- | ||
| Benchmarks the `timeSeries*ToGrid` aggregate functions, focusing on the grid-filling stage | ||
| (`doInsertResultInto`). Only the linear-regression functions (`timeSeriesDerivToGrid` / | ||
| `timeSeriesPredictLinearToGrid`) choose there between recomputing each window and the sliding two-stack | ||
| queue, governed by `AVG_POPULATED_BPW_TO_ENABLE_TWO_STACKS` / `BPW_TO_FORCE_TWO_STACKS`; the other | ||
| functions always recompute. | ||
| (`doInsertResultInto`). Of the functions benchmarked here, only the linear-regression functions | ||
| (`timeSeriesDerivToGrid` / `timeSeriesPredictLinearToGrid`) choose there between recomputing each window | ||
| and the sliding two-stack queue, governed by `AVG_POPULATED_BPW_TO_ENABLE_TWO_STACKS` / | ||
| `BPW_TO_FORCE_TWO_STACKS`; the other functions here always recompute. | ||
|
|
||
| The grid is long (10001 points) and there is roughly one sample per grid step, so the number of populated | ||
| buckets in a window is about `window / step` and the same buckets are re-visited at every grid point. This | ||
| makes the per-grid-point work in `doInsertResultInto` dominate over the one-off bucketing/aggregation of the | ||
| samples (which would instead dominate if many samples fell into each bucket). | ||
|
|
||
| `window` is swept across the two-stack thresholds (with ~1 populated bucket per step, the average populated | ||
| buckets per window ~= window/step): 50/step=5 (below AVG_POPULATED_BPW_TO_ENABLE_TWO_STACKS=10 -> recompute), | ||
| 160/step=16 (between the thresholds -> two-stacks via the average path), and 1000/step=100 | ||
| (>= BPW_TO_FORCE_TWO_STACKS=20 -> two-stacks via the hard cap). The data is dense (~1 sample per bucket), so | ||
| buckets per window ~= window/step): 30/step=3 (below AVG_POPULATED_BPW_TO_ENABLE_TWO_STACKS=4 -> recompute), | ||
| 80/step=8 (between the thresholds -> two-stacks via the average path), and 1000/step=100 | ||
| (>= BPW_TO_FORCE_TWO_STACKS=12 -> two-stacks via the hard cap). The data is dense (~1 sample per bucket), so | ||
| every query uses the range-scan bucket iteration; the sparse scenario below covers the collect-and-sort path. | ||
| Functions are ordered from the cheapest per-bucket merge (resample, instant, changes) to the most expensive | ||
| (linear regression). | ||
|
|
@@ -28,8 +28,8 @@ | |
| <substitution> | ||
| <name>window</name> | ||
| <values> | ||
| <value>50</value> | ||
| <value>160</value> | ||
| <value>30</value> | ||
| <value>80</value> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also the performance and stateless tests were adjusted to follow their claimed scenarios. |
||
| <value>1000</value> | ||
| </values> | ||
| </substitution> | ||
|
|
@@ -91,7 +91,7 @@ | |
| <query>SELECT id, timeSeriesPredictLinearToGrid(0, 100000, 10, {window}, 60)(timestamp, value) FROM ts_grid GROUP BY id FORMAT Null</query> | ||
|
|
||
| <!-- Sort-path coverage on the sparse table, at a single fixed window=1000 (buckets_per_window=100 >= | ||
| BPW_TO_FORCE_TWO_STACKS=20, so the regression functions force two-stacks): the cheapest function (resample) | ||
| BPW_TO_FORCE_TWO_STACKS=12, so the regression functions force two-stacks): the cheapest function (resample) | ||
| plus the two regression functions. The literal window (no {window}) means each runs once, not per sweep. --> | ||
| <query>SELECT id, timeSeriesResampleToGridWithStaleness(0, 100000, 10, 1000)(timestamp, value) FROM ts_grid_sparse GROUP BY id FORMAT Null</query> | ||
| <query>SELECT id, timeSeriesDerivToGrid(0, 100000, 10, 1000)(timestamp, value) FROM ts_grid_sparse GROUP BY id FORMAT Null</query> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 5 additions & 4 deletions
9
tests/queries/0_stateless/04319_timeseries_window_memoization.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Recent measurements after our optimizations showed different values than what were measured originally:
ClickHouse/src/AggregateFunctions/examples/timeseries_to_grid_two_stack_vs_recompute.out
Lines 23 to 24 in a05aaa1
So these thresholds in the code should be updated