Repository navigation
pkg/clickhouse: answer HasProfileData with one row, not a scan - #6417
Closed
guettlibot wants to merge 1 commit into
Closed
guettlibot wants to merge 1 commit into
guettlibot wants to merge 1 commit into
Conversation
HasProfileData asks whether the table holds any data at all. It answered by calling ProfileTypes(UnixMilli(0), UnixMilli(0)), and ProfileTypes applies its time filter only when both bounds are non-zero -- so the cheapest question in the API ran an unbounded SELECT DISTINCT over six columns, a full scan of a table that grows without bound. Measured on a server with 72 hours of retention: 108,591,120 rows and 7.9 GB read to return 9 rows, 1.3 seconds warm and 61 seconds cold. The UI calls this to decide whether to show its empty state, so the cost was paid on page loads rather than on anything a user asked for. Existence needs one row. The query is a small function so a test can pin its shape without a server: this needs a live ClickHouse to execute, while the regression is entirely visible in the statement.
This was referenced Oct 3, 2026
Author
|
Closing as a duplicate of #6402, which makes the same change a month earlier and more concisely. I filed this without searching existing PRs first — my mistake. I have moved the production measurements (108,591,120 rows / 7.9 GB read to return 9 rows; 1.3s warm, 61s cold) and a note about |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Independent of #6415 and #6416 — branches from
main, touches onlypkg/clickhouse/querier.go.What
HasProfileDataasks whether the table holds any data at all. It answered by callingProfileTypes(time.UnixMilli(0), time.UnixMilli(0)):and
ProfileTypesapplies its time filter only when both bounds are non-zero:With
(0, 0)the filter is skipped, so the cheapest question in the API ran an unboundedSELECT DISTINCTover six columns — a full scan of a table that grows without bound.Measured
On a server with 72 hours of retention:
108,591,120 rows / 7.9 GB read to return 9 rows — 1.3s warm, 61s cold. The UI calls this to decide whether to show its empty state, so the cost lands on page loads rather than on anything a user asked for.
Fix
Existence needs one row:
The statement lives in a small function so a test can pin its shape without a server — executing it needs a live ClickHouse, while the regression is entirely visible in the SQL. The test asserts
LIMIT 1and the absence ofDISTINCT/GROUP BY/ORDER BY.ProfileTypesitself is unchanged; its zero-bounds behaviour is left exactly as it is, since other callers may rely on the all-time semantics.