diff --git a/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index 0b87b241d85..392708b45f2 100644 --- a/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/dbms/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -61,6 +61,7 @@ namespace std #include #include #include +#include namespace ProfileEvents { @@ -802,6 +803,15 @@ Pipes MergeTreeDataSelectExecutor::spreadMarkRangesAmongStreams( res.emplace_back(std::move(source)); } + + /// Use ConcatProcessor to concat sources together. + /// It is needed to read in parts order (and so in PK order) if single thread is used. + if (res.size() > 1) + { + auto concat = std::make_shared(res.front().getHeader(), res.size()); + Pipe pipe(std::move(res), std::move(concat)); + res = { std::move(pipe) }; + } } return res;