From 5608f157497cbca402cad192e4f86c31dc86868b Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 25 Jun 2020 22:15:41 +0300 Subject: [PATCH] Revive mmap IO --- .../MergeTree/MergeTreeDataSelectExecutor.cpp | 1 + src/Storages/MergeTree/MergeTreeIOSettings.h | 3 ++- src/Storages/MergeTree/MergeTreeReaderCompact.cpp | 5 +++-- .../01343_min_bytes_to_use_mmap_io.reference | 2 ++ .../0_stateless/01343_min_bytes_to_use_mmap_io.sql | 11 +++++++++++ 5 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.reference create mode 100644 tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.sql diff --git a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index 4929bf4dbcb..901f947dd6e 100644 --- a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -608,6 +608,7 @@ Pipes MergeTreeDataSelectExecutor::readFromParts( MergeTreeReaderSettings reader_settings = { .min_bytes_to_use_direct_io = settings.min_bytes_to_use_direct_io, + .min_bytes_to_use_mmap_io = settings.min_bytes_to_use_mmap_io, .max_read_buffer_size = settings.max_read_buffer_size, .save_marks_in_cache = true }; diff --git a/src/Storages/MergeTree/MergeTreeIOSettings.h b/src/Storages/MergeTree/MergeTreeIOSettings.h index f5c57659052..0a37b18925b 100644 --- a/src/Storages/MergeTree/MergeTreeIOSettings.h +++ b/src/Storages/MergeTree/MergeTreeIOSettings.h @@ -10,7 +10,7 @@ struct MergeTreeReaderSettings size_t min_bytes_to_use_direct_io = 0; size_t min_bytes_to_use_mmap_io = 0; size_t max_read_buffer_size = DBMS_DEFAULT_BUFFER_SIZE; - /// If save_marks_in_cache is false, then, if marks are not in cache, + /// If save_marks_in_cache is false, then, if marks are not in cache, /// we will load them but won't save in the cache, to avoid evicting other data. bool save_marks_in_cache = false; }; @@ -33,4 +33,5 @@ struct MergeTreeWriterSettings size_t estimated_size = 0; }; + } diff --git a/src/Storages/MergeTree/MergeTreeReaderCompact.cpp b/src/Storages/MergeTree/MergeTreeReaderCompact.cpp index 64e9deec744..c47f8b396d8 100644 --- a/src/Storages/MergeTree/MergeTreeReaderCompact.cpp +++ b/src/Storages/MergeTree/MergeTreeReaderCompact.cpp @@ -57,7 +57,7 @@ MergeTreeReaderCompact::MergeTreeReaderCompact( buffer_size, 0, settings.min_bytes_to_use_direct_io, - 0); + settings.min_bytes_to_use_mmap_io); }, uncompressed_cache); @@ -71,7 +71,8 @@ MergeTreeReaderCompact::MergeTreeReaderCompact( { auto buffer = std::make_unique( - data_part->volume->getDisk()->readFile(full_data_path, buffer_size, 0, settings.min_bytes_to_use_direct_io, 0)); + data_part->volume->getDisk()->readFile( + full_data_path, buffer_size, 0, settings.min_bytes_to_use_direct_io, settings.min_bytes_to_use_mmap_io)); if (profile_callback_) buffer->setProfileCallback(profile_callback_, clock_type_); diff --git a/tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.reference b/tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.reference new file mode 100644 index 00000000000..620777635fc --- /dev/null +++ b/tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.reference @@ -0,0 +1,2 @@ +Hello, world +1 diff --git a/tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.sql b/tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.sql new file mode 100644 index 00000000000..9e6e3708c9a --- /dev/null +++ b/tests/queries/0_stateless/01343_min_bytes_to_use_mmap_io.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS test; +CREATE TABLE test (x String) ENGINE = MergeTree ORDER BY tuple(); +INSERT INTO test VALUES ('Hello, world'); + +SET min_bytes_to_use_mmap_io = 1; +SELECT * FROM test; + +SYSTEM FLUSH LOGS; +SELECT PE.Values FROM system.query_log ARRAY JOIN ProfileEvents AS PE WHERE event_date >= yesterday() AND event_time >= now() - 300 AND query LIKE 'SELECT * FROM test%' AND PE.Names = 'CreatedReadBufferMMap' AND type = 2 ORDER BY event_time DESC LIMIT 1; + +DROP TABLE test;