@@ -167,7 +167,7 @@ Status OlapScanner::_init_tablet_reader_params(
167167 const std::vector<std::pair<string, std::shared_ptr<IBloomFilterFuncBase>>>& bloom_filters,
168168 const std::vector<FunctionFilter>& function_filters) {
169169 // if the table with rowset [0-x] or [0-1] [2-y], and [0-1] is empty
170- bool single_version =
170+ bool single_non_overlapping_version =
171171 (_tablet_reader_params.rs_readers .size () == 1 &&
172172 _tablet_reader_params.rs_readers [0 ]->rowset ()->start_version () == 0 &&
173173 !_tablet_reader_params.rs_readers [0 ]
@@ -182,14 +182,14 @@ Status OlapScanner::_init_tablet_reader_params(
182182 ->rowset_meta ()
183183 ->is_segments_overlapping ());
184184
185- _tablet_reader_params.direct_mode = single_version || _aggregation;
186-
187- RETURN_IF_ERROR (_init_return_columns (!_tablet_reader_params.direct_mode ));
185+ bool has_replace_col = false ;
186+ RETURN_IF_ERROR (_init_return_columns (!single_non_overlapping_version, has_replace_col));
188187
188+ _tablet_reader_params.aggregation = has_replace_col ? false : _aggregation;
189+ _tablet_reader_params.direct_mode = single_non_overlapping_version || _tablet_reader_params.aggregation ;
189190 _tablet_reader_params.tablet = _tablet;
190191 _tablet_reader_params.tablet_schema = _tablet_schema;
191192 _tablet_reader_params.reader_type = READER_QUERY ;
192- _tablet_reader_params.aggregation = _aggregation;
193193 _tablet_reader_params.version = Version (0 , _version);
194194
195195 // Condition
@@ -271,7 +271,7 @@ Status OlapScanner::_init_tablet_reader_params(
271271 return Status::OK ();
272272}
273273
274- Status OlapScanner::_init_return_columns (bool need_seq_col) {
274+ Status OlapScanner::_init_return_columns (bool need_seq_col, bool &has_replace_col ) {
275275 for (auto slot : _tuple_desc->slots ()) {
276276 if (!slot->is_materialized ()) {
277277 continue ;
@@ -291,20 +291,23 @@ Status OlapScanner::_init_return_columns(bool need_seq_col) {
291291 _query_slots.push_back (slot);
292292 }
293293
294- // expand the sequence column
295- if (_tablet_schema->has_sequence_col () && need_seq_col) {
296- bool has_replace_col = false ;
294+ has_replace_col = false ;
295+ if (_tablet->keys_type () == UNIQUE_KEYS || _tablet->keys_type () == AGG_KEYS ) {
297296 for (auto col : _return_columns) {
298297 if (_tablet_schema->column (col).aggregation () ==
299298 FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE ) {
300299 has_replace_col = true ;
301300 break ;
302301 }
303302 }
304- if (auto sequence_col_idx = _tablet_schema->sequence_col_idx ();
305- has_replace_col && std::find (_return_columns.begin (), _return_columns.end (),
306- sequence_col_idx) == _return_columns.end ()) {
307- _return_columns.push_back (sequence_col_idx);
303+
304+ // handle SEQ
305+ if (_tablet_schema->has_sequence_col () && need_seq_col && has_replace_col) {
306+ auto sequence_col_idx = _tablet_schema->sequence_col_idx ();
307+ if (std::find (_return_columns.begin (), _return_columns.end (),
308+ sequence_col_idx) == _return_columns.end ()) {
309+ _return_columns.push_back (sequence_col_idx);
310+ }
308311 }
309312 }
310313
0 commit comments