Skip to content

Commit

Permalink
[Enhancement] add limit operator before union gather (#53102)
Browse files Browse the repository at this point in the history
Signed-off-by: stdpain <[email protected]>
  • Loading branch information
stdpain authored Nov 22, 2024
1 parent 81ddcf7 commit 5411897
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
8 changes: 7 additions & 1 deletion be/src/exec/union_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,18 @@ pipeline::OpFactories UnionNode::decompose_to_pipeline(pipeline::PipelineBuilder
this->init_runtime_filter_for_operator(operators_list[i].back().get(), context, rc_rf_probe_collector);
}

if (limit() != -1) {
for (size_t i = 0; i < operators_list.size(); ++i) {
operators_list[i].emplace_back(
std::make_shared<LimitOperatorFactory>(context->next_operator_id(), id(), limit()));
}
}

auto final_operators = context->maybe_gather_pipelines_to_one(runtime_state(), id(), operators_list);
if (limit() != -1) {
final_operators.emplace_back(
std::make_shared<LimitOperatorFactory>(context->next_operator_id(), id(), limit()));
}

return final_operators;
}

Expand Down
28 changes: 28 additions & 0 deletions test/sql/test_union/R/test_union_all_with_limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- name: test_union_all_with_limit
CREATE TABLE `t0` (
`c0` int(11) NULL COMMENT "",
`c1` varchar(20) NULL COMMENT "",
`c2` varchar(200) NULL COMMENT "",
`c3` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`c0`, `c1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`c0`, `c1`) BUCKETS 48
PROPERTIES (
"colocate_with" = "${uuid0}",
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT",
"enable_persistent_index" = "false",
"replicated_storage" = "true",
"compression" = "LZ4"
);
-- result:
-- !result
insert into t0 SELECT generate_series, generate_series, generate_series, generate_series FROM TABLE(generate_series(1, 40960));
-- result:
-- !result
select count(*) from (select c0 from t0 union all select distinct c0 from t0 limit 1)t;
-- result:
1
-- !result
24 changes: 24 additions & 0 deletions test/sql/test_union/T/test_union_all_with_limit
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- name: test_union_all_with_limit

CREATE TABLE `t0` (
`c0` int(11) NULL COMMENT "",
`c1` varchar(20) NULL COMMENT "",
`c2` varchar(200) NULL COMMENT "",
`c3` int(11) NULL COMMENT ""
) ENGINE=OLAP
DUPLICATE KEY(`c0`, `c1`)
COMMENT "OLAP"
DISTRIBUTED BY HASH(`c0`, `c1`) BUCKETS 48
PROPERTIES (
"colocate_with" = "${uuid0}",
"replication_num" = "1",
"in_memory" = "false",
"storage_format" = "DEFAULT",
"enable_persistent_index" = "false",
"replicated_storage" = "true",
"compression" = "LZ4"
);

insert into t0 SELECT generate_series, generate_series, generate_series, generate_series FROM TABLE(generate_series(1, 40960));

select count(*) from (select c0 from t0 union all select distinct c0 from t0 limit 1)t;

0 comments on commit 5411897

Please sign in to comment.