From e8079c8ecd98c1ca7b7cd1d4c62de8ca4aba67be Mon Sep 17 00:00:00 2001 From: alesapin Date: Fri, 5 Apr 2019 15:57:22 +0300 Subject: [PATCH] Add empty reads to cache --- dbms/src/Compression/CachedCompressedReadBuffer.cpp | 10 +++++----- ...3_test_fix_extra_seek_on_compressed_cache.reference | 2 +- .../00933_test_fix_extra_seek_on_compressed_cache.sh | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dbms/src/Compression/CachedCompressedReadBuffer.cpp b/dbms/src/Compression/CachedCompressedReadBuffer.cpp index 52d3281369b..b39d04cf03f 100644 --- a/dbms/src/Compression/CachedCompressedReadBuffer.cpp +++ b/dbms/src/Compression/CachedCompressedReadBuffer.cpp @@ -53,16 +53,16 @@ bool CachedCompressedReadBuffer::nextImpl() owned_cell->data.resize(size_decompressed + owned_cell->additional_bytes); decompress(owned_cell->data.data(), size_decompressed, size_compressed_without_checksum); - /// Put data into cache. - cache->set(key, owned_cell); } + + /// Put data into cache. + /// NOTE: Even if we don't read anything (compressed_size == 0) + /// because we can reuse this information and don't reopen file in future + cache->set(key, owned_cell); } if (owned_cell->data.size() == 0) - { - owned_cell = nullptr; return false; - } working_buffer = Buffer(owned_cell->data.data(), owned_cell->data.data() + owned_cell->data.size() - owned_cell->additional_bytes); diff --git a/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.reference b/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.reference index cf4a0cf7529..797f208c02b 100644 --- a/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.reference +++ b/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.reference @@ -1 +1 @@ -36 13 +0 36 14 diff --git a/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.sh b/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.sh index f4378cab89e..faefe039403 100755 --- a/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.sh +++ b/dbms/tests/queries/0_stateless/00933_test_fix_extra_seek_on_compressed_cache.sh @@ -18,7 +18,7 @@ $CLICKHOUSE_CLIENT --use_uncompressed_cache=1 --query_id="test-query-uncompresse $CLICKHOUSE_CLIENT --query="SYSTEM FLUSH LOGS" -$CLICKHOUSE_CLIENT --query="SELECT ProfileEvents.Values[indexOf(ProfileEvents.Names, 'ReadCompressedBytes')], ProfileEvents.Values[indexOf(ProfileEvents.Names, 'UncompressedCacheHits')] AS hit FROM system.query_log WHERE (query_id = 'test-query-uncompressed-cache') AND (type = 2) ORDER BY event_time DESC LIMIT 1" +$CLICKHOUSE_CLIENT --query="SELECT ProfileEvents.Values[indexOf(ProfileEvents.Names, 'Seek')], ProfileEvents.Values[indexOf(ProfileEvents.Names, 'ReadCompressedBytes')], ProfileEvents.Values[indexOf(ProfileEvents.Names, 'UncompressedCacheHits')] AS hit FROM system.query_log WHERE (query_id = 'test-query-uncompressed-cache') AND (type = 2) ORDER BY event_time DESC LIMIT 1" $CLICKHOUSE_CLIENT --query="DROP TABLE IF EXISTS test.small_table"