-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Fix query cache with sparse columns #48500
Merged
alexey-milovidov
merged 1 commit into
ClickHouse:master
from
CurtizJ:fix-sparse-column-query-cache
Apr 7, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
1 change: 1 addition & 0 deletions
1
tests/queries/0_stateless/02708_query_cache_sparse_columns.reference
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
1 |
23 changes: 23 additions & 0 deletions
23
tests/queries/0_stateless/02708_query_cache_sparse_columns.sql
This file contains 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
-- Tags: no-parallel | ||
|
||
DROP TABLE IF EXISTS t_cache_sparse; | ||
SYSTEM DROP QUERY CACHE; | ||
|
||
CREATE TABLE t_cache_sparse (id UInt64, v UInt64) | ||
ENGINE = MergeTree ORDER BY id | ||
SETTINGS ratio_of_defaults_for_sparse_serialization = 0.9; | ||
|
||
SYSTEM STOP MERGES t_cache_sparse; | ||
|
||
INSERT INTO t_cache_sparse SELECT number, number FROM numbers(10000); | ||
INSERT INTO t_cache_sparse SELECT number, 0 FROM numbers(10000); | ||
|
||
SET allow_experimental_query_cache = 1; | ||
SET use_query_cache = 1; | ||
SET max_threads = 1; | ||
|
||
SELECT v FROM t_cache_sparse FORMAT Null; | ||
SELECT v FROM t_cache_sparse FORMAT Null; | ||
SELECT count() FROM system.query_cache WHERE query LIKE 'SELECT v FROM t_cache_sparse%'; | ||
|
||
DROP TABLE t_cache_sparse; |
Oops, something went wrong.
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.
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.
I don't understand - why don't allow to have sparse columns in the cache?
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.
Columns are squashed and we cannot squash sparse and non-sparse columns.
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.
Ok.
@rschu1ze, why is there a need for squashing for the query cache? Why don't we save a sequence of blocks as is?
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.
Sorry for the late reply.
Squashing is configurable but on by default. The motivation is
The disadvantage is that writing in the cache becomes more expensive. The question is should the cache optimize for insertion or for lookups? With the current approach, the user chooses specific queries which write to the cache (by adding
SETTINGS use_query_cache = 1
). This is different from a model where all or most queries get cached. With selected queries, entries in the cache will likely have a high hit rate, so we should make lookup faster at the cost of more expensive inserts. At least that's the theory 😄 - but in the end that's a heuristics.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.
Good. Let's keep squashing, but also allow cases with many blocks and even with many ports like totals and extremes.
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.
Okay. I can add logic to avoid squashing/splitting if the input blocks are already reasonably sized. And yes, multiple ports for totals and extremes should also be supported ... just did not think about this usecase initially.