From 54cc8e1d2797f11e5af00d08c35372f9db44af38 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Fri, 22 Oct 2021 16:19:49 +0300 Subject: [PATCH] Fix LimitStep header after limit push down optimization. --- src/Processors/QueryPlan/LimitStep.cpp | 2 +- .../02100_limit_push_down_bug.reference | 0 .../0_stateless/02100_limit_push_down_bug.sql | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/02100_limit_push_down_bug.reference create mode 100644 tests/queries/0_stateless/02100_limit_push_down_bug.sql diff --git a/src/Processors/QueryPlan/LimitStep.cpp b/src/Processors/QueryPlan/LimitStep.cpp index 8c5e3e3c87c..aff7472e4aa 100644 --- a/src/Processors/QueryPlan/LimitStep.cpp +++ b/src/Processors/QueryPlan/LimitStep.cpp @@ -40,7 +40,7 @@ void LimitStep::updateInputStream(DataStream input_stream) { input_streams.clear(); input_streams.emplace_back(std::move(input_stream)); - output_stream = createOutputStream(input_streams.front(), output_stream->header, getDataStreamTraits()); + output_stream = createOutputStream(input_streams.front(), input_streams.front().header, getDataStreamTraits()); } void LimitStep::transformPipeline(QueryPipelineBuilder & pipeline, const BuildQueryPipelineSettings &) diff --git a/tests/queries/0_stateless/02100_limit_push_down_bug.reference b/tests/queries/0_stateless/02100_limit_push_down_bug.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/02100_limit_push_down_bug.sql b/tests/queries/0_stateless/02100_limit_push_down_bug.sql new file mode 100644 index 00000000000..2ba9d2b8818 --- /dev/null +++ b/tests/queries/0_stateless/02100_limit_push_down_bug.sql @@ -0,0 +1,21 @@ +drop table if exists tbl_repr; + +CREATE TABLE tbl_repr( +ts DateTime, +x String) +ENGINE=MergeTree ORDER BY ts; + + +SELECT * +FROM +( + SELECT + x, + length(x) + FROM tbl_repr + WHERE ts > now() + LIMIT 1 +) +WHERE x != ''; + +drop table if exists tbl_repr;