fix: make HasProfileData an existence probe instead of a full-table scan - #6402
Open
javicj wants to merge 1 commit into
Open
fix: make HasProfileData an existence probe instead of a full-table scan#6402javicj wants to merge 1 commit into
javicj wants to merge 1 commit into
Conversation
HasProfileData delegated to ProfileTypes with a zero time range, which skips the time filter and runs a DISTINCT over every row in the table, only for the result to be reduced to a boolean. A LIMIT 1 probe returns the same answer after reading a single granule. HasProfileData backs the UI's empty-state check and runs on every page load.
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.
What does this PR do?
HasProfileDatadelegated toProfileTypeswith a zero time range.ProfileTypesskips its time filter when start and end are zero, so every call executed:
with no WHERE and no LIMIT — and the result was immediately reduced to
len(types) > 0. DISTINCT cannot terminate early, so this scanned the entiretable on every call just to answer a boolean.
HasProfileDatabacks the UI'sempty-state check and runs on every page load; with hundreds of millions of rows
this made the UI landing screen take seconds to minutes.
This replaces it with
SELECT 1 FROM <table> LIMIT 1, which reads one granuleand stops. Semantics are unchanged: both answer "does the table contain at
least one row", since any row necessarily has profile-type values (non-nullable
columns).
Why is it needed?
Observed in production with ~426M rows: the empty-state check was the single
most expensive query hitting ClickHouse, and under load it held connection
pool slots long enough to starve all other queries.
How to test it?
go test ./pkg/clickhouse/"no data yet" prompt; with an empty store, the prompt still shows. The
response is now immediate regardless of table size.