github-actions[bot] commented on code in PR #62222:
URL: https://github.com/apache/doris/pull/62222#discussion_r3097735701


##########
be/src/exec/scan/olap_scanner.cpp:
##########
@@ -508,10 +508,12 @@ Status OlapScanner::_init_tablet_reader_params(
                 }
                 _tablet_reader_params.read_orderby_key_num_prefix_columns =
                         olap_scan_node.sort_info.is_asc_order.size();
-                _tablet_reader_params.read_orderby_key_limit = _limit;
 
-                if (_tablet_reader_params.read_orderby_key_limit > 0 &&
-                    olap_scan_local_state->_storage_no_merge()) {
+                // Storage-level topn optimization (read_orderby_key_limit +
+                // filter_block_conjuncts pushdown) is only valid for DUP_KEYS
+                // and UNIQUE_KEYS with MOW where no merge is needed.
+                if (_limit > 0 && olap_scan_local_state->_storage_no_merge()) {

Review Comment:
   `_storage_no_merge()` is broader than the storage top-N path can actually 
handle: it also returns true for `read_mor_as_dup()`.
   
   That makes `read_mor_as_dup + ORDER BY key LIMIT` set 
`read_orderby_key_limit` here, but `TabletReader::_init_orderby_keys_param()` 
still only populates `_orderby_key_columns` for physical `DUP_KEYS` / 
`UNIQUE_KEYS + MOW` tables (`be/src/storage/tablet/tablet_reader.cpp:391-440`). 
On MOR tables read as DUP, `_reader_context.read_orderby_key_columns` stays 
null, `VCollectIterator::init()` now switches into `LimitMode::TOPN`, and 
`_topn_next()` fails immediately with `InternalError("read_orderby_key_columns 
should not be nullptr")` 
(`be/src/storage/iterator/vcollect_iterator.cpp:87-92,331-333`).
   
   Before this change we still set `read_orderby_key`, but the old 
physical-table check in `VCollectIterator::init()` prevented the top-N path 
from being entered for MOR-as-DUP. Please keep the storage top-N optimization 
gated to the same physical cases as `_init_orderby_keys_param()` (or teach the 
storage layer to initialize order-by columns for `read_mor_as_dup` too) and add 
a regression test for this query shape.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to