Merge pull request #28266 from CurtizJ/fix-order-by-merge

Fix order by for `Merge` tables with `optimize_read_in_order`
This commit is contained in:
alexey-milovidov 2021-08-28 01:15:40 +03:00 committed by GitHub
commit 4eef445df9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 2 deletions

View File

@ -338,9 +338,10 @@ Pipe StorageMerge::read(
auto pipe = Pipe::unitePipes(std::move(pipes)); auto pipe = Pipe::unitePipes(std::move(pipes));
if (!pipe.empty()) if (!pipe.empty() && !query_info.input_order_info)
// It's possible to have many tables read from merge, resize(num_streams) might open too many files at the same time. // It's possible to have many tables read from merge, resize(num_streams) might open too many files at the same time.
// Using narrowPipe instead. // Using narrowPipe instead. But in case of reading in order of primary key, we cannot do it,
// because narrowPipe doesn't preserve order.
narrowPipe(pipe, num_streams); narrowPipe(pipe, num_streams);
return pipe; return pipe;

View File

@ -0,0 +1,5 @@
20
20
20
20
20

View File

@ -0,0 +1,22 @@
DROP TABLE IF EXISTS short;
DROP TABLE IF EXISTS long;
DROP TABLE IF EXISTS merged;
CREATE TABLE short (e Int64, t DateTime ) ENGINE = MergeTree PARTITION BY e ORDER BY t;
CREATE TABLE long (e Int64, t DateTime ) ENGINE = MergeTree PARTITION BY (e, toStartOfMonth(t)) ORDER BY t;
insert into short select number % 11, toDateTime('2021-01-01 00:00:00') + number from numbers(1000);
insert into long select number % 11, toDateTime('2021-01-01 00:00:00') + number from numbers(1000);
CREATE TABLE merged as short ENGINE = Merge(currentDatabase(), 'short|long');
select sum(e) from (select * from merged order by t limit 10) SETTINGS optimize_read_in_order = 0;
select sum(e) from (select * from merged order by t limit 10) SETTINGS max_threads = 1;
select sum(e) from (select * from merged order by t limit 10) SETTINGS max_threads = 3;
select sum(e) from (select * from merged order by t limit 10) SETTINGS max_threads = 10;
select sum(e) from (select * from merged order by t limit 10) SETTINGS max_threads = 50;
DROP TABLE IF EXISTS short;
DROP TABLE IF EXISTS long;
DROP TABLE IF EXISTS merged;