Skip to content

Commit 3ac4a11

Browse files
committed
fix order by key topn slow since read unecessary data (apache#1197)
since key is already sorted and topn_next only need first N rows from each segment, but runtime predicate will filter some rows and read more than N rows. should add add for order by none-key column, since none-key column is not sorted and all rows should be read, so runtime predicate will reduce rows for topn node
1 parent 10e9f76 commit 3ac4a11

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎be/src/olap/rowset/segment_v2/segment_iterator.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,15 @@ void SegmentIterator::_vec_init_lazy_materialization() {
937937
}
938938

939939
// add runtime predicate to _col_predicates
940-
if (_opts.use_topn_opt) {
941-
auto& runtime_predicate =
942-
_opts.runtime_state->get_query_fragments_ctx()->get_runtime_predicate();
940+
// should NOT add for order by key,
941+
// since key is already sorted and topn_next only need first N rows from each segment,
942+
// but runtime predicate will filter some rows and read more than N rows.
943+
// should add add for order by none-key column, since none-key column is not sorted and
944+
// all rows should be read, so runtime predicate will reduce rows for topn node
945+
if (_opts.use_topn_opt &&
946+
!(_opts.read_orderby_key_columns != nullptr && !_opts.read_orderby_key_columns->empty())) {
947+
auto & runtime_predicate =
948+
_opts.runtime_state->get_query_fragments_ctx()->get_runtime_predicate();
943949
_runtime_predicate = runtime_predicate.get_predictate();
944950
if (_runtime_predicate) {
945951
_col_predicates.push_back(_runtime_predicate.get());

0 commit comments

Comments
 (0)