Merge pull request #49593 from ClickHouse/rs/qc-empty-chunk

Query Cache: Safeguard against empty chunks
This commit is contained in:
robot-clickhouse-ci-1 2023-05-07 02:20:54 +02:00 committed by GitHub
commit d1ad3ea24e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -1514,7 +1514,7 @@ Default value: `0`.
## query_cache_max_size_in_bytes {#query-cache-max-size-in-bytes}
The maximum amount of memory (in bytes) the current user may allocate in the query cache. 0 means unlimited.
The maximum amount of memory (in bytes) the current user may allocate in the [query cache](../query-cache.md). 0 means unlimited.
Possible values:
@ -1524,7 +1524,7 @@ Default value: 0 (no restriction).
## query_cache_max_entries {#query-cache-max-entries}
The maximum number of query results the current user may store in the query cache. 0 means unlimited.
The maximum number of query results the current user may store in the [query cache](../query-cache.md). 0 means unlimited.
Possible values:

View File

@ -206,6 +206,15 @@ void QueryCache::Writer::buffer(Chunk && chunk, ChunkType chunk_type)
if (skip_insert)
return;
/// Reading from the query cache is implemented using processor `SourceFromChunks` which inherits from `ISource`.
/// The latter has logic which finishes processing (= calls `.finish()` on the output port + returns `Status::Finished`)
/// when the derived class returns an empty chunk. If this empty chunk is not the last chunk,
/// i.e. if it is followed by non-empty chunks, the query result will be incorrect.
/// This situation should theoretically never occur in practice but who knows...
/// To be on the safe side, writing into the query cache now rejects empty chunks and thereby avoids this scenario.
if (chunk.empty())
return;
std::lock_guard lock(mutex);
switch (chunk_type)