From df6860d5e089aeb3e6fe1f91836c62162a11f9a1 Mon Sep 17 00:00:00 2001 From: "Constantin S. Pan" Date: Fri, 15 Mar 2019 15:22:22 +0000 Subject: [PATCH] Make the query planner respect LIMIT BY in remote queries --- dbms/src/Interpreters/InterpreterSelectQuery.cpp | 6 ++++++ .../queries/0_stateless/00409_shard_limit_by.reference | 5 +++++ dbms/tests/queries/0_stateless/00409_shard_limit_by.sql | 3 +++ 3 files changed, 14 insertions(+) diff --git a/dbms/src/Interpreters/InterpreterSelectQuery.cpp b/dbms/src/Interpreters/InterpreterSelectQuery.cpp index 83d53ca37b8..a76d3405533 100644 --- a/dbms/src/Interpreters/InterpreterSelectQuery.cpp +++ b/dbms/src/Interpreters/InterpreterSelectQuery.cpp @@ -623,6 +623,12 @@ void InterpreterSelectQuery::executeImpl(Pipeline & pipeline, const BlockInputSt if (expressions.has_order_by && query.limit_length) executeDistinct(pipeline, false, expressions.selected_columns); + if (expressions.has_limit_by) + { + executeExpression(pipeline, expressions.before_limit_by); + executeLimitBy(pipeline); + } + if (query.limit_length) executePreLimit(pipeline); } diff --git a/dbms/tests/queries/0_stateless/00409_shard_limit_by.reference b/dbms/tests/queries/0_stateless/00409_shard_limit_by.reference index f0f6c4e48ad..8aa9b8f42c0 100644 --- a/dbms/tests/queries/0_stateless/00409_shard_limit_by.reference +++ b/dbms/tests/queries/0_stateless/00409_shard_limit_by.reference @@ -19,3 +19,8 @@ 0 0 1 +100 +100 +101 +101 +102 diff --git a/dbms/tests/queries/0_stateless/00409_shard_limit_by.sql b/dbms/tests/queries/0_stateless/00409_shard_limit_by.sql index 982cff9a6c5..57d9182a9c8 100644 --- a/dbms/tests/queries/0_stateless/00409_shard_limit_by.sql +++ b/dbms/tests/queries/0_stateless/00409_shard_limit_by.sql @@ -29,4 +29,7 @@ SELECT dummy FROM remote('127.0.0.{2,3}', system.one) LIMIT 2 BY dummy; SELECT 1 as one FROM remote('127.0.0.{2,3}', system.one) LIMIT 1 BY one; +-- Distributed LIMIT BY with LIMIT +SELECT toInt8(number / 5 + 100) AS x FROM remote('127.0.0.1', system.numbers) LIMIT 2 BY x LIMIT 5; + DROP TABLE IF EXISTS test.limit_by;