Skip to content

Commit a021bb4

Browse files
authored
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 9e36496 commit a021bb4

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,13 @@ void SegmentIterator::_vec_init_lazy_materialization() {
15731573
}
15741574

15751575
// add runtime predicate to _col_predicates
1576-
if (_opts.use_topn_opt) {
1576+
// should NOT add for order by key,
1577+
// since key is already sorted and topn_next only need first N rows from each segment,
1578+
// but runtime predicate will filter some rows and read more than N rows.
1579+
// should add add for order by none-key column, since none-key column is not sorted and
1580+
// all rows should be read, so runtime predicate will reduce rows for topn node
1581+
if (_opts.use_topn_opt &&
1582+
!(_opts.read_orderby_key_columns != nullptr && !_opts.read_orderby_key_columns->empty())) {
15771583
auto & runtime_predicate =
15781584
_opts.runtime_state->get_query_fragments_ctx()->get_runtime_predicate();
15791585
_runtime_predicate = runtime_predicate.get_predictate();

0 commit comments

Comments
 (0)