Coverage Report

Created: 2026-07-06 08:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/segment/column_reader.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "storage/segment/column_reader.h"
19
20
#include <assert.h>
21
#include <gen_cpp/Descriptors_types.h>
22
#include <gen_cpp/segment_v2.pb.h>
23
#include <glog/logging.h>
24
25
#include <algorithm>
26
#include <memory>
27
#include <ostream>
28
#include <set>
29
#include <string>
30
#include <utility>
31
32
#include "common/compiler_util.h" // IWYU pragma: keep
33
#include "common/status.h"
34
#include "core/assert_cast.h"
35
#include "core/binary_cast.hpp"
36
#include "core/column/column.h"
37
#include "core/column/column_array.h"
38
#include "core/column/column_map.h"
39
#include "core/column/column_nullable.h"
40
#include "core/column/column_struct.h"
41
#include "core/column/column_vector.h"
42
#include "core/data_type/data_type_agg_state.h"
43
#include "core/data_type/data_type_factory.hpp"
44
#include "core/data_type/data_type_nullable.h"
45
#include "core/data_type/define_primitive_type.h"
46
#include "core/decimal12.h"
47
#include "core/string_ref.h"
48
#include "core/types.h"
49
#include "core/value/decimalv2_value.h"
50
#include "core/value/vdatetime_value.h" //for VecDateTime
51
#include "io/fs/file_reader.h"
52
#include "storage/index/ann/ann_index_reader.h"
53
#include "storage/index/bloom_filter/bloom_filter.h"
54
#include "storage/index/bloom_filter/bloom_filter_index_reader.h"
55
#include "storage/index/index_file_reader.h"
56
#include "storage/index/index_reader.h"
57
#include "storage/index/inverted/analyzer/analyzer.h"
58
#include "storage/index/inverted/inverted_index_reader.h"
59
#include "storage/index/zone_map/zone_map_index.h"
60
#include "storage/iterators.h"
61
#include "storage/olap_common.h"
62
#include "storage/predicate/block_column_predicate.h"
63
#include "storage/predicate/column_predicate.h"
64
#include "storage/segment/binary_dict_page.h" // for BinaryDictPageDecoder
65
#include "storage/segment/binary_plain_page.h"
66
#include "storage/segment/column_meta_accessor.h"
67
#include "storage/segment/encoding_info.h" // for EncodingInfo
68
#include "storage/segment/page_decoder.h"
69
#include "storage/segment/page_handle.h" // for PageHandle
70
#include "storage/segment/page_io.h"
71
#include "storage/segment/page_pointer.h" // for PagePointer
72
#include "storage/segment/row_ranges.h"
73
#include "storage/segment/segment.h"
74
#include "storage/segment/segment_prefetcher.h"
75
#include "storage/segment/variant/variant_column_reader.h"
76
#include "storage/tablet/tablet_schema.h"
77
#include "storage/types.h" // for TypeInfo
78
#include "util/bitmap.h"
79
#include "util/block_compression.h"
80
#include "util/concurrency_stats.h"
81
#include "util/defer_op.h"
82
#include "util/rle_encoding.h" // for RleDecoder
83
#include "util/slice.h"
84
85
namespace doris::segment_v2 {
86
#include "storage/segment/column_reader.h"
87
88
630
inline bool read_as_string(PrimitiveType type) {
89
630
    return type == PrimitiveType::TYPE_STRING || type == PrimitiveType::INVALID_TYPE ||
90
630
           type == PrimitiveType::TYPE_BITMAP || type == PrimitiveType::TYPE_FIXED_LENGTH_OBJECT;
91
630
}
92
93
13.3k
bool is_current_level_meta_access_path(const TColumnAccessPath& path) {
94
13.3k
    if (path.data_access_path.path.size() != 1) {
95
1.33k
        return false;
96
1.33k
    }
97
11.9k
    const auto& component = path.data_access_path.path[0];
98
11.9k
    return StringCaseEqual()(component, ColumnIterator::ACCESS_OFFSET) ||
99
11.9k
           StringCaseEqual()(component, ColumnIterator::ACCESS_NULL);
100
13.3k
}
101
102
bool is_current_level_data_access_path(const TColumnAccessPath& path,
103
61.9k
                                       const std::string& column_name) {
104
61.9k
    return path.data_access_path.path.size() == 1 &&
105
61.9k
           StringCaseEqual()(path.data_access_path.path[0], column_name);
106
61.9k
}
107
108
110k
void remove_current_level_meta_access_paths(TColumnAccessPaths& paths) {
109
110k
    auto removed = std::ranges::remove_if(paths, is_current_level_meta_access_path);
110
110k
    paths.erase(removed.begin(), removed.end());
111
110k
}
112
113
Status ColumnReader::create_array(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
114
                                  const io::FileReaderSPtr& file_reader,
115
48.6k
                                  std::shared_ptr<ColumnReader>* reader) {
116
48.6k
    DCHECK(meta.children_columns_size() == 2 || meta.children_columns_size() == 3);
117
118
48.6k
    std::shared_ptr<ColumnReader> item_reader;
119
48.6k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(0),
120
48.6k
                                         meta.children_columns(0).num_rows(), file_reader,
121
48.6k
                                         &item_reader));
122
123
48.6k
    std::shared_ptr<ColumnReader> offset_reader;
124
48.6k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(1),
125
48.6k
                                         meta.children_columns(1).num_rows(), file_reader,
126
48.6k
                                         &offset_reader));
127
128
48.6k
    std::shared_ptr<ColumnReader> null_reader;
129
48.6k
    if (meta.is_nullable()) {
130
33.5k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(2),
131
33.5k
                                             meta.children_columns(2).num_rows(), file_reader,
132
33.5k
                                             &null_reader));
133
33.5k
    }
134
135
    // The num rows of the array reader equals to the num rows of the length reader.
136
48.6k
    uint64_t array_num_rows = meta.children_columns(1).num_rows();
137
48.6k
    std::shared_ptr<ColumnReader> array_reader(
138
48.6k
            new ColumnReader(opts, meta, array_num_rows, file_reader));
139
    //  array reader do not need to init
140
48.6k
    array_reader->_sub_readers.resize(meta.children_columns_size());
141
48.6k
    array_reader->_sub_readers[0] = std::move(item_reader);
142
48.6k
    array_reader->_sub_readers[1] = std::move(offset_reader);
143
48.6k
    if (meta.is_nullable()) {
144
33.4k
        array_reader->_sub_readers[2] = std::move(null_reader);
145
33.4k
    }
146
48.6k
    array_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_ARRAY;
147
48.6k
    *reader = std::move(array_reader);
148
48.6k
    return Status::OK();
149
48.6k
}
150
151
Status ColumnReader::create_map(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
152
                                const io::FileReaderSPtr& file_reader,
153
30.2k
                                std::shared_ptr<ColumnReader>* reader) {
154
    // map reader now has 3 sub readers for key, value, offsets(scalar), null(scala)
155
30.2k
    DCHECK(meta.children_columns_size() == 3 || meta.children_columns_size() == 4);
156
30.2k
    std::shared_ptr<ColumnReader> key_reader;
157
30.2k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(0),
158
30.2k
                                         meta.children_columns(0).num_rows(), file_reader,
159
30.2k
                                         &key_reader));
160
30.2k
    std::shared_ptr<ColumnReader> val_reader;
161
30.2k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(1),
162
30.2k
                                         meta.children_columns(1).num_rows(), file_reader,
163
30.2k
                                         &val_reader));
164
30.2k
    std::shared_ptr<ColumnReader> offset_reader;
165
30.2k
    RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(2),
166
30.2k
                                         meta.children_columns(2).num_rows(), file_reader,
167
30.2k
                                         &offset_reader));
168
30.2k
    std::shared_ptr<ColumnReader> null_reader;
169
30.2k
    if (meta.is_nullable()) {
170
12.3k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(3),
171
12.3k
                                             meta.children_columns(3).num_rows(), file_reader,
172
12.3k
                                             &null_reader));
173
12.3k
    }
174
175
    // The num rows of the map reader equals to the num rows of the length reader.
176
30.2k
    uint64_t map_num_rows = meta.children_columns(2).num_rows();
177
30.2k
    std::shared_ptr<ColumnReader> map_reader(
178
30.2k
            new ColumnReader(opts, meta, map_num_rows, file_reader));
179
30.2k
    map_reader->_sub_readers.resize(meta.children_columns_size());
180
181
30.2k
    map_reader->_sub_readers[0] = std::move(key_reader);
182
30.2k
    map_reader->_sub_readers[1] = std::move(val_reader);
183
30.2k
    map_reader->_sub_readers[2] = std::move(offset_reader);
184
30.2k
    if (meta.is_nullable()) {
185
12.3k
        map_reader->_sub_readers[3] = std::move(null_reader);
186
12.3k
    }
187
30.2k
    map_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_MAP;
188
30.2k
    *reader = std::move(map_reader);
189
30.2k
    return Status::OK();
190
30.2k
}
191
192
Status ColumnReader::create_struct(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
193
                                   uint64_t num_rows, const io::FileReaderSPtr& file_reader,
194
2.85k
                                   std::shared_ptr<ColumnReader>* reader) {
195
    // not support empty struct
196
2.85k
    DCHECK(meta.children_columns_size() >= 1);
197
    // create struct column reader
198
2.85k
    std::shared_ptr<ColumnReader> struct_reader(
199
2.85k
            new ColumnReader(opts, meta, num_rows, file_reader));
200
2.85k
    struct_reader->_sub_readers.reserve(meta.children_columns_size());
201
    // now we support struct column can add the children columns according to the schema-change behavior
202
16.7k
    for (int i = 0; i < meta.children_columns_size(); i++) {
203
13.8k
        std::shared_ptr<ColumnReader> sub_reader;
204
13.8k
        RETURN_IF_ERROR(ColumnReader::create(opts, meta.children_columns(i),
205
13.8k
                                             meta.children_columns(i).num_rows(), file_reader,
206
13.8k
                                             &sub_reader));
207
13.8k
        struct_reader->_sub_readers.push_back(std::move(sub_reader));
208
13.8k
    }
209
2.85k
    struct_reader->_meta_type = FieldType::OLAP_FIELD_TYPE_STRUCT;
210
2.85k
    *reader = std::move(struct_reader);
211
2.85k
    return Status::OK();
212
2.85k
}
213
214
Status ColumnReader::create_agg_state(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
215
                                      uint64_t num_rows, const io::FileReaderSPtr& file_reader,
216
629
                                      std::shared_ptr<ColumnReader>* reader) {
217
629
    if (!meta.has_function_name()) { // meet old version ColumnMetaPB
218
0
        std::shared_ptr<ColumnReader> reader_local(
219
0
                new ColumnReader(opts, meta, num_rows, file_reader));
220
0
        RETURN_IF_ERROR(reader_local->init(&meta));
221
0
        *reader = std::move(reader_local);
222
0
        return Status::OK();
223
0
    }
224
225
629
    auto data_type = DataTypeFactory::instance().create_data_type(meta);
226
629
    const auto* agg_state_type = assert_cast<const DataTypeAggState*>(data_type.get());
227
629
    agg_state_type->check_function_compatibility(opts.be_exec_version);
228
629
    auto type = agg_state_type->get_serialized_type()->get_primitive_type();
229
230
629
    if (read_as_string(type)) {
231
584
        std::shared_ptr<ColumnReader> reader_local(
232
584
                new ColumnReader(opts, meta, num_rows, file_reader));
233
584
        RETURN_IF_ERROR(reader_local->init(&meta));
234
584
        *reader = std::move(reader_local);
235
584
        return Status::OK();
236
584
    } else if (type == PrimitiveType::TYPE_MAP) {
237
34
        return create_map(opts, meta, file_reader, reader);
238
34
    } else if (type == PrimitiveType::TYPE_ARRAY) {
239
10
        return create_array(opts, meta, file_reader, reader);
240
10
    } else if (type == PrimitiveType::TYPE_STRUCT) {
241
0
        return create_struct(opts, meta, num_rows, file_reader, reader);
242
0
    }
243
244
1
    return Status::InternalError("Not supported type: {}, serialized type: {}",
245
1
                                 agg_state_type->get_name(), int(type));
246
629
}
247
248
97.8k
bool ColumnReader::is_compaction_reader_type(ReaderType type) {
249
97.8k
    return type == ReaderType::READER_BASE_COMPACTION ||
250
97.8k
           type == ReaderType::READER_CUMULATIVE_COMPACTION ||
251
97.8k
           type == ReaderType::READER_COLD_DATA_COMPACTION ||
252
97.8k
           type == ReaderType::READER_SEGMENT_COMPACTION ||
253
97.8k
           type == ReaderType::READER_FULL_COMPACTION;
254
97.8k
}
255
256
Status ColumnReader::create(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
257
                            uint64_t num_rows, const io::FileReaderSPtr& file_reader,
258
5.97M
                            std::shared_ptr<ColumnReader>* reader) {
259
5.97M
    if (opts.const_value.has_value()) {
260
3
        *reader = std::make_shared<ConstantColumnReader>(*opts.const_value);
261
3
        return Status::OK();
262
3
    }
263
5.97M
    if (is_scalar_type((FieldType)meta.type())) {
264
5.88M
        std::shared_ptr<ColumnReader> reader_local(
265
5.88M
                new ColumnReader(opts, meta, num_rows, file_reader));
266
5.88M
        RETURN_IF_ERROR(reader_local->init(&meta));
267
5.88M
        *reader = std::move(reader_local);
268
5.88M
        return Status::OK();
269
5.88M
    } else {
270
89.5k
        auto type = (FieldType)meta.type();
271
89.5k
        switch (type) {
272
630
        case FieldType::OLAP_FIELD_TYPE_AGG_STATE: {
273
630
            return create_agg_state(opts, meta, num_rows, file_reader, reader);
274
0
        }
275
2.85k
        case FieldType::OLAP_FIELD_TYPE_STRUCT: {
276
2.85k
            return create_struct(opts, meta, num_rows, file_reader, reader);
277
0
        }
278
48.8k
        case FieldType::OLAP_FIELD_TYPE_ARRAY: {
279
48.8k
            return create_array(opts, meta, file_reader, reader);
280
0
        }
281
30.2k
        case FieldType::OLAP_FIELD_TYPE_MAP: {
282
30.2k
            return create_map(opts, meta, file_reader, reader);
283
0
        }
284
7.27k
        case FieldType::OLAP_FIELD_TYPE_VARIANT: {
285
            // Read variant only root data using a single ColumnReader
286
7.27k
            std::shared_ptr<ColumnReader> reader_local(
287
7.27k
                    new ColumnReader(opts, meta, num_rows, file_reader));
288
7.27k
            RETURN_IF_ERROR(reader_local->init(&meta));
289
7.27k
            *reader = std::move(reader_local);
290
7.27k
            return Status::OK();
291
7.27k
        }
292
0
        default:
293
0
            return Status::NotSupported("unsupported type for ColumnReader: {}",
294
0
                                        std::to_string(int(type)));
295
89.5k
        }
296
89.5k
    }
297
5.97M
}
298
299
7.73k
ColumnReader::ColumnReader() = default;
300
301
ColumnReader::ColumnReader(const ColumnReaderOptions& opts, const ColumnMetaPB& meta,
302
                           uint64_t num_rows, io::FileReaderSPtr file_reader)
303
5.97M
        : _use_index_page_cache(!config::disable_storage_page_cache),
304
5.97M
          _opts(opts),
305
5.97M
          _num_rows(num_rows),
306
5.97M
          _file_reader(std::move(file_reader)),
307
5.97M
          _dict_encoding_type(UNKNOWN_DICT_ENCODING) {
308
5.97M
    _meta_length = meta.length();
309
5.97M
    _meta_type = (FieldType)meta.type();
310
5.97M
    if (_meta_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
311
48.7k
        _meta_children_column_type = (FieldType)meta.children_columns(0).type();
312
48.7k
    }
313
5.97M
    _data_type = DataTypeFactory::instance().create_data_type(meta);
314
5.97M
    _meta_is_nullable = meta.is_nullable();
315
5.97M
    _meta_dict_page = meta.dict_page();
316
5.97M
    _meta_compression = meta.compression();
317
5.97M
}
318
319
5.79M
ColumnReader::~ColumnReader() = default;
320
321
5.89M
int64_t ColumnReader::get_metadata_size() const {
322
5.89M
    return sizeof(ColumnReader) + (_segment_zone_map ? _segment_zone_map->ByteSizeLong() : 0);
323
5.89M
}
324
325
#ifdef BE_TEST
326
/// This function is only used in UT to verify the correctness of data read from zone map
327
/// See UT case 'SegCompactionMoWTest.SegCompactionInterleaveWithBig_ooooOOoOooooooooO'
328
/// be/test/olap/segcompaction_mow_test.cpp
329
void ColumnReader::check_data_by_zone_map_for_test(const MutableColumnPtr& dst) const {
330
    if (!_segment_zone_map) {
331
        return;
332
    }
333
334
    const auto rows = dst->size();
335
    if (rows == 0) {
336
        return;
337
    }
338
339
    FieldType type = _type;
340
341
    if (type != FieldType::OLAP_FIELD_TYPE_INT) {
342
        return;
343
    }
344
345
    auto* non_nullable_column =
346
            is_column_nullable(*dst)
347
                    ? assert_cast<ColumnNullable*>(dst.get())->get_nested_column_ptr().get()
348
                    : dst.get();
349
350
    /// Only verify when the destination column carries Field-accessible TYPE_INT data.
351
    if (check_and_get_column<ColumnVector<TYPE_INT>>(non_nullable_column) == nullptr) {
352
        return;
353
    }
354
355
    ZoneMap zone_map;
356
    THROW_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
357
358
    if (zone_map.has_null) {
359
        return;
360
    }
361
362
    for (size_t i = 0; i != rows; ++i) {
363
        Field field;
364
        dst->get(i, field);
365
        DCHECK(!field.is_null());
366
        const auto v = field.get<TYPE_INT>();
367
        DCHECK_GE(v, zone_map.min_value.get<TYPE_INT>());
368
        DCHECK_LE(v, zone_map.max_value.get<TYPE_INT>());
369
    }
370
}
371
#endif
372
373
5.88M
Status ColumnReader::init(const ColumnMetaPB* meta) {
374
5.88M
    _type = (FieldType)meta->type();
375
376
5.88M
    if (meta->has_be_exec_version()) {
377
5.70M
        _be_exec_version = meta->be_exec_version();
378
5.70M
    }
379
380
5.89M
    if (_type == FieldType::OLAP_FIELD_TYPE_NONE || _type == FieldType::OLAP_FIELD_TYPE_UNKNOWN) {
381
0
        return Status::NotSupported("unsupported typeinfo, type={}", meta->type());
382
0
    }
383
5.88M
    RETURN_IF_ERROR(EncodingInfo::get(_type, meta->encoding(), &_encoding_info));
384
385
17.3M
    for (int i = 0; i < meta->indexes_size(); i++) {
386
11.4M
        const auto& index_meta = meta->indexes(i);
387
11.4M
        switch (index_meta.type()) {
388
0
        case BITMAP_INDEX:
389
0
            break;
390
5.86M
        case ORDINAL_INDEX:
391
5.86M
            _ordinal_index.reset(
392
5.86M
                    new OrdinalIndexReader(_file_reader, _num_rows, index_meta.ordinal_index()));
393
5.86M
            break;
394
5.59M
        case ZONE_MAP_INDEX:
395
5.59M
            _segment_zone_map =
396
5.59M
                    std::make_unique<ZoneMapPB>(index_meta.zone_map_index().segment_zone_map());
397
5.59M
            _zone_map_index.reset(new ZoneMapIndexReader(
398
5.59M
                    _file_reader, index_meta.zone_map_index().page_zone_maps()));
399
5.59M
            break;
400
4.73k
        case BLOOM_FILTER_INDEX:
401
4.73k
            _bloom_filter_index.reset(
402
4.73k
                    new BloomFilterIndexReader(_file_reader, index_meta.bloom_filter_index()));
403
4.73k
            break;
404
0
        case NESTED_OFFSETS_INDEX:
405
0
            break;
406
0
        default:
407
0
            return Status::Corruption("Bad file {}: invalid column index type {}",
408
0
                                      _file_reader->path().native(), index_meta.type());
409
11.4M
        }
410
11.4M
    }
411
5.88M
    update_metadata_size();
412
413
    // ArrayColumnWriter writes a single empty array and flushes. In this scenario,
414
    // the item writer doesn't write any data and the corresponding ordinal index is empty.
415
5.88M
    if (_ordinal_index == nullptr && !is_empty()) {
416
0
        return Status::Corruption("Bad file {}: missing ordinal index for column {}",
417
0
                                  _file_reader->path().native(), meta->column_id());
418
0
    }
419
420
5.88M
    return Status::OK();
421
5.88M
}
422
423
Status ColumnReader::new_index_iterator(const std::shared_ptr<IndexFileReader>& index_file_reader,
424
                                        const TabletIndex* index_meta, const std::string& rowset_id,
425
                                        uint32_t segment_id, size_t rows_of_segment,
426
73.6k
                                        std::unique_ptr<IndexIterator>* iterator) {
427
73.6k
    RETURN_IF_ERROR(
428
73.6k
            _load_index(index_file_reader, index_meta, rowset_id, segment_id, rows_of_segment));
429
73.6k
    {
430
73.6k
        std::shared_lock<std::shared_mutex> rlock(_load_index_lock);
431
73.6k
        auto iter = _index_readers.find(index_meta->index_id());
432
73.8k
        if (iter != _index_readers.end()) {
433
73.8k
            if (iter->second != nullptr) {
434
73.8k
                RETURN_IF_ERROR(iter->second->new_iterator(iterator));
435
73.8k
            }
436
73.8k
        }
437
73.6k
    }
438
73.6k
    return Status::OK();
439
73.6k
}
440
441
Status ColumnReader::read_page(const ColumnIteratorOptions& iter_opts, const PagePointer& pp,
442
                               PageHandle* handle, Slice* page_body, PageFooterPB* footer,
443
1.89M
                               BlockCompressionCodec* codec) const {
444
1.89M
    SCOPED_CONCURRENCY_COUNT(ConcurrencyStatsManager::instance().column_reader_read_page);
445
1.89M
    iter_opts.sanity_check();
446
1.89M
    PageReadOptions opts(iter_opts.io_ctx);
447
1.89M
    opts.verify_checksum = _opts.verify_checksum;
448
1.89M
    opts.use_page_cache = iter_opts.use_page_cache;
449
1.89M
    opts.kept_in_memory = _opts.kept_in_memory;
450
1.89M
    opts.type = iter_opts.type;
451
1.89M
    opts.file_reader = iter_opts.file_reader;
452
1.89M
    opts.page_pointer = pp;
453
1.89M
    opts.codec = codec;
454
1.89M
    opts.stats = iter_opts.stats;
455
1.89M
    opts.encoding_info = _encoding_info;
456
457
1.89M
    return PageIO::read_and_decompress_page(opts, handle, page_body, footer);
458
1.89M
}
459
460
Status ColumnReader::get_row_ranges_by_zone_map(
461
        const AndBlockColumnPredicate* col_predicates,
462
        const std::vector<std::shared_ptr<const ColumnPredicate>>* delete_predicates,
463
100k
        RowRanges* row_ranges, const ColumnIteratorOptions& iter_opts) {
464
100k
    std::vector<uint32_t> page_indexes;
465
100k
    RETURN_IF_ERROR(
466
100k
            _get_filtered_pages(col_predicates, delete_predicates, &page_indexes, iter_opts));
467
100k
    RETURN_IF_ERROR(_calculate_row_ranges(page_indexes, row_ranges, iter_opts));
468
100k
    return Status::OK();
469
100k
}
470
471
10.8k
Status ColumnReader::next_batch_of_zone_map(size_t* n, MutableColumnPtr& dst) const {
472
10.8k
    if (_segment_zone_map == nullptr) {
473
0
        return Status::InternalError("segment zonemap not exist");
474
0
    }
475
    // TODO: this work to get min/max value seems should only do once
476
10.8k
    ZoneMap zone_map;
477
10.8k
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
478
479
10.8k
    dst->reserve(*n);
480
10.8k
    if (!zone_map.has_not_null) {
481
608
        assert_cast<ColumnNullable&>(*dst).insert_many_defaults(*n);
482
608
        return Status::OK();
483
608
    }
484
10.2k
    dst->insert(zone_map.max_value);
485
20.5k
    for (int i = 1; i < *n; ++i) {
486
10.2k
        dst->insert(zone_map.min_value);
487
10.2k
    }
488
10.2k
    return Status::OK();
489
10.8k
}
490
491
Status ColumnReader::match_condition(const AndBlockColumnPredicate* col_predicates,
492
1.59M
                                     bool* matched) const {
493
1.59M
    *matched = true;
494
1.59M
    if (_zone_map_index == nullptr) {
495
0
        return Status::OK();
496
0
    }
497
1.59M
    ZoneMap zone_map;
498
1.59M
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
499
500
1.59M
    *matched = _zone_map_match_condition(zone_map, col_predicates);
501
1.59M
    return Status::OK();
502
1.59M
}
503
504
Status ConstantColumnReader::match_condition(const AndBlockColumnPredicate* col_predicates,
505
3
                                             bool* matched) const {
506
3
    ZoneMap zone_map;
507
3
    zone_map.min_value = _value;
508
3
    zone_map.max_value = _value;
509
3
    zone_map.has_not_null = !_value.is_null();
510
    // evaluate_and returns false iff no value in [min, max] (i.e. the real constant) can satisfy
511
    // the predicates; predicates that don't support zonemap conservatively return true.
512
3
    *matched = col_predicates->evaluate_and(zone_map);
513
3
    return Status::OK();
514
3
}
515
516
Status ColumnReader::prune_predicates_by_zone_map(
517
        std::vector<std::shared_ptr<ColumnPredicate>>& predicates, const int column_id,
518
17.9M
        bool* pruned) const {
519
17.9M
    *pruned = false;
520
17.9M
    if (_zone_map_index == nullptr) {
521
26.1k
        return Status::OK();
522
26.1k
    }
523
524
17.8M
    ZoneMap zone_map;
525
17.8M
    RETURN_IF_ERROR(ZoneMap::from_proto(*_segment_zone_map, _data_type, zone_map));
526
17.8M
    if (zone_map.pass_all) {
527
0
        return Status::OK();
528
0
    }
529
530
36.0M
    for (auto it = predicates.begin(); it != predicates.end();) {
531
18.1M
        auto predicate = *it;
532
18.1M
        if (predicate->column_id() == column_id && predicate->is_always_true(zone_map)) {
533
11.7k
            *pruned = true;
534
11.7k
            it = predicates.erase(it);
535
18.1M
        } else {
536
18.1M
            ++it;
537
18.1M
        }
538
18.1M
    }
539
17.8M
    return Status::OK();
540
17.8M
}
541
542
bool ColumnReader::_zone_map_match_condition(const ZoneMap& zone_map,
543
1.68M
                                             const AndBlockColumnPredicate* col_predicates) const {
544
1.68M
    if (zone_map.pass_all) {
545
0
        return true;
546
0
    }
547
548
1.68M
    return col_predicates->evaluate_and(zone_map);
549
1.68M
}
550
551
Status ColumnReader::_get_filtered_pages(
552
        const AndBlockColumnPredicate* col_predicates,
553
        const std::vector<std::shared_ptr<const ColumnPredicate>>* delete_predicates,
554
100k
        std::vector<uint32_t>* page_indexes, const ColumnIteratorOptions& iter_opts) {
555
100k
    RETURN_IF_ERROR(_load_zone_map_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
556
557
100k
    const std::vector<ZoneMapPB>& zone_maps = _zone_map_index->page_zone_maps();
558
100k
    size_t page_size = _zone_map_index->num_pages();
559
248k
    for (size_t i = 0; i < page_size; ++i) {
560
148k
        if (zone_maps[i].pass_all()) {
561
64.4k
            page_indexes->push_back(cast_set<uint32_t>(i));
562
83.9k
        } else {
563
83.9k
            segment_v2::ZoneMap zone_map;
564
83.9k
            RETURN_IF_ERROR(ZoneMap::from_proto(zone_maps[i], _data_type, zone_map));
565
84.2k
            if (_zone_map_match_condition(zone_map, col_predicates)) {
566
84.2k
                bool should_read = true;
567
84.2k
                if (delete_predicates != nullptr) {
568
4
                    for (auto del_pred : *delete_predicates) {
569
                        // TODO: Both `min_value` and `max_value` should be 0 or neither should be 0.
570
                        //  So nullable only need to judge once.
571
4
                        if (del_pred->evaluate_del(zone_map)) {
572
1
                            should_read = false;
573
1
                            break;
574
1
                        }
575
4
                    }
576
3
                }
577
84.2k
                if (should_read) {
578
84.2k
                    page_indexes->push_back(cast_set<uint32_t>(i));
579
84.2k
                }
580
84.2k
            }
581
83.9k
        }
582
148k
    }
583
18.4E
    VLOG(1) << "total-pages: " << page_size << " not-filtered-pages: " << page_indexes->size()
584
18.4E
            << " filtered-percent:"
585
18.4E
            << 1.0 - (static_cast<double>(page_indexes->size()) /
586
18.4E
                      (static_cast<double>(page_size) * 1.0));
587
100k
    return Status::OK();
588
100k
}
589
590
Status ColumnReader::_calculate_row_ranges(const std::vector<uint32_t>& page_indexes,
591
                                           RowRanges* row_ranges,
592
99.9k
                                           const ColumnIteratorOptions& iter_opts) {
593
99.9k
    row_ranges->clear();
594
99.9k
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
595
148k
    for (auto i : page_indexes) {
596
148k
        ordinal_t page_first_id = _ordinal_index->get_first_ordinal(i);
597
148k
        ordinal_t page_last_id = _ordinal_index->get_last_ordinal(i);
598
148k
        RowRanges page_row_ranges(RowRanges::create_single(page_first_id, page_last_id + 1));
599
148k
        RowRanges::ranges_union(*row_ranges, page_row_ranges, row_ranges);
600
148k
    }
601
99.9k
    return Status::OK();
602
99.9k
}
603
604
Status ColumnReader::get_row_ranges_by_bloom_filter(const AndBlockColumnPredicate* col_predicates,
605
                                                    RowRanges* row_ranges,
606
112
                                                    const ColumnIteratorOptions& iter_opts) {
607
112
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
608
112
    RETURN_IF_ERROR(
609
112
            _load_bloom_filter_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
610
112
    RowRanges bf_row_ranges;
611
112
    std::unique_ptr<BloomFilterIndexIterator> bf_iter;
612
112
    RETURN_IF_ERROR(_bloom_filter_index->new_iterator(&bf_iter, iter_opts.stats));
613
112
    size_t range_size = row_ranges->range_size();
614
    // get covered page ids
615
112
    std::set<uint32_t> page_ids;
616
224
    for (int i = 0; i < range_size; ++i) {
617
112
        int64_t from = row_ranges->get_range_from(i);
618
112
        int64_t idx = from;
619
112
        int64_t to = row_ranges->get_range_to(i);
620
112
        auto iter = _ordinal_index->seek_at_or_before(from);
621
430
        while (idx < to && iter.valid()) {
622
318
            page_ids.insert(iter.page_index());
623
318
            idx = iter.last_ordinal() + 1;
624
318
            iter.next();
625
318
        }
626
112
    }
627
323
    for (auto& pid : page_ids) {
628
323
        std::unique_ptr<BloomFilter> bf;
629
323
        RETURN_IF_ERROR(bf_iter->read_bloom_filter(pid, &bf));
630
323
        if (col_predicates->evaluate_and(bf.get())) {
631
35
            bf_row_ranges.add(RowRange(_ordinal_index->get_first_ordinal(pid),
632
35
                                       _ordinal_index->get_last_ordinal(pid) + 1));
633
35
        }
634
323
    }
635
112
    RowRanges::ranges_intersection(*row_ranges, bf_row_ranges, row_ranges);
636
112
    return Status::OK();
637
112
}
638
639
Status ColumnReader::_load_ordinal_index(bool use_page_cache, bool kept_in_memory,
640
1.58M
                                         const ColumnIteratorOptions& iter_opts) {
641
1.58M
    if (!_ordinal_index) {
642
0
        return Status::InternalError("ordinal_index not inited");
643
0
    }
644
1.58M
    return _ordinal_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
645
1.58M
}
646
647
Status ColumnReader::_load_zone_map_index(bool use_page_cache, bool kept_in_memory,
648
100k
                                          const ColumnIteratorOptions& iter_opts) {
649
100k
    if (_zone_map_index != nullptr) {
650
100k
        return _zone_map_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
651
100k
    }
652
76
    return Status::OK();
653
100k
}
654
655
2.77k
Status ColumnReader::get_segment_zone_map(segment_v2::ZoneMap* zone_map) const {
656
2.77k
    DORIS_CHECK(zone_map != nullptr);
657
2.77k
    DORIS_CHECK(_segment_zone_map != nullptr);
658
2.77k
    return ZoneMap::from_proto(*_segment_zone_map, _data_type, *zone_map);
659
2.77k
}
660
661
1
Status ConstantColumnReader::get_segment_zone_map(segment_v2::ZoneMap* zone_map) const {
662
1
    zone_map->min_value = _value;
663
1
    zone_map->max_value = _value;
664
1
    zone_map->has_not_null = !_value.is_null();
665
1
    return Status::OK();
666
1
}
667
668
Status ColumnReader::get_page_zone_maps(const ColumnIteratorOptions& iter_opts,
669
606
                                        const std::vector<ZoneMapPB>** zone_maps) {
670
606
    DORIS_CHECK(zone_maps != nullptr);
671
606
    if (_zone_map_index == nullptr) {
672
0
        *zone_maps = nullptr;
673
0
        return Status::OK();
674
0
    }
675
606
    RETURN_IF_ERROR(_load_zone_map_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
676
606
    *zone_maps = &_zone_map_index->page_zone_maps();
677
606
    return Status::OK();
678
606
}
679
680
Status ColumnReader::get_row_range_for_page(uint32_t page_index,
681
                                            const ColumnIteratorOptions& iter_opts,
682
1.06k
                                            RowRange* row_range) {
683
1.06k
    DORIS_CHECK(row_range != nullptr);
684
1.06k
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
685
1.06k
    DORIS_CHECK(page_index < _ordinal_index->num_data_pages());
686
1.06k
    *row_range = RowRange(_ordinal_index->get_first_ordinal(page_index),
687
1.06k
                          _ordinal_index->get_last_ordinal(page_index) + 1);
688
1.06k
    return Status::OK();
689
1.06k
}
690
691
Status ColumnReader::_load_index(const std::shared_ptr<IndexFileReader>& index_file_reader,
692
                                 const TabletIndex* index_meta, const std::string& rowset_id,
693
73.6k
                                 uint32_t segment_id, size_t rows_of_segment) {
694
73.6k
    std::unique_lock<std::shared_mutex> wlock(_load_index_lock);
695
696
73.6k
    if (index_meta == nullptr) {
697
0
        return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
698
0
                "Failed to load inverted index: index metadata is null");
699
0
    }
700
701
73.6k
    auto it = _index_readers.find(index_meta->index_id());
702
73.6k
    if (it != _index_readers.end()) {
703
39.0k
        return Status::OK();
704
39.0k
    }
705
706
34.5k
    bool should_analyzer =
707
34.5k
            inverted_index::InvertedIndexAnalyzer::should_analyzer(index_meta->properties());
708
709
34.5k
    FieldType type;
710
34.5k
    if (_meta_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
711
2.14k
        type = _meta_children_column_type;
712
32.3k
    } else {
713
32.3k
        type = _type;
714
32.3k
    }
715
716
34.5k
    if (index_meta->index_type() == IndexType::ANN) {
717
65
        _index_readers[index_meta->index_id()] = std::make_shared<AnnIndexReader>(
718
65
                index_meta, index_file_reader, rowset_id, segment_id, rows_of_segment);
719
65
        return Status::OK();
720
65
    }
721
722
34.4k
    IndexReaderPtr index_reader;
723
724
34.4k
    if (is_string_type(type)) {
725
12.3k
        if (should_analyzer) {
726
5.92k
            try {
727
5.92k
                index_reader = FullTextIndexReader::create_shared(index_meta, index_file_reader);
728
5.92k
            } catch (const CLuceneError& e) {
729
0
                return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
730
0
                        "create FullTextIndexReader error: {}", e.what());
731
0
            }
732
6.42k
        } else {
733
6.42k
            try {
734
6.42k
                index_reader =
735
6.42k
                        StringTypeInvertedIndexReader::create_shared(index_meta, index_file_reader);
736
6.42k
            } catch (const CLuceneError& e) {
737
0
                return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
738
0
                        "create StringTypeInvertedIndexReader error: {}", e.what());
739
0
            }
740
6.42k
        }
741
22.3k
    } else if (is_numeric_type(type)) {
742
22.3k
        try {
743
22.3k
            index_reader = BkdIndexReader::create_shared(index_meta, index_file_reader);
744
22.3k
        } catch (const CLuceneError& e) {
745
0
            return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
746
0
                    "create BkdIndexReader error: {}", e.what());
747
0
        }
748
18.4E
    } else {
749
18.4E
        return Status::Error<ErrorCode::INVERTED_INDEX_NOT_SUPPORTED>(
750
18.4E
                "Field type {} is not supported for inverted index", type);
751
18.4E
    }
752
34.7k
    _index_readers[index_meta->index_id()] = index_reader;
753
34.7k
    return Status::OK();
754
34.4k
}
755
756
80.2k
bool ColumnReader::has_bloom_filter_index(bool ngram) const {
757
80.3k
    if (_bloom_filter_index == nullptr) return false;
758
759
18.4E
    if (ngram) {
760
77
        return _bloom_filter_index->algorithm() == BloomFilterAlgorithmPB::NGRAM_BLOOM_FILTER;
761
18.4E
    } else {
762
18.4E
        return _bloom_filter_index->algorithm() != BloomFilterAlgorithmPB::NGRAM_BLOOM_FILTER;
763
18.4E
    }
764
18.4E
}
765
766
Status ColumnReader::_load_bloom_filter_index(bool use_page_cache, bool kept_in_memory,
767
114
                                              const ColumnIteratorOptions& iter_opts) {
768
114
    if (_bloom_filter_index != nullptr) {
769
114
        return _bloom_filter_index->load(use_page_cache, kept_in_memory, iter_opts.stats);
770
114
    }
771
0
    return Status::OK();
772
114
}
773
774
Status ColumnReader::seek_at_or_before(ordinal_t ordinal, OrdinalPageIndexIterator* iter,
775
1.47M
                                       const ColumnIteratorOptions& iter_opts) {
776
1.47M
    RETURN_IF_ERROR(_load_ordinal_index(_use_index_page_cache, _opts.kept_in_memory, iter_opts));
777
1.47M
    *iter = _ordinal_index->seek_at_or_before(ordinal);
778
1.47M
    if (!iter->valid()) {
779
0
        return Status::NotFound("Failed to seek to ordinal {}, ", ordinal);
780
0
    }
781
1.47M
    return Status::OK();
782
1.47M
}
783
784
Status ColumnReader::get_ordinal_index_reader(OrdinalIndexReader*& reader,
785
0
                                              OlapReaderStatistics* index_load_stats) {
786
0
    CHECK(_ordinal_index) << fmt::format("ordinal index is null for column reader of type {}",
787
0
                                         std::to_string(int(_meta_type)));
788
0
    RETURN_IF_ERROR(
789
0
            _ordinal_index->load(_use_index_page_cache, _opts.kept_in_memory, index_load_stats));
790
0
    reader = _ordinal_index.get();
791
0
    return Status::OK();
792
0
}
793
794
366k
Status ColumnReader::new_iterator(ColumnIteratorUPtr* iterator, const TabletColumn* tablet_column) {
795
366k
    return new_iterator(iterator, tablet_column, nullptr);
796
366k
}
797
798
Status ColumnReader::new_iterator(ColumnIteratorUPtr* iterator, const TabletColumn* tablet_column,
799
23.3M
                                  const StorageReadOptions* opt) {
800
23.3M
    if (is_empty()) {
801
37.2k
        *iterator = std::make_unique<EmptyFileColumnIterator>();
802
37.2k
        return Status::OK();
803
37.2k
    }
804
23.3M
    if (is_scalar_type(_meta_type)) {
805
23.2M
        if (is_string_type(_meta_type)) {
806
13.9M
            *iterator = std::make_unique<StringFileColumnIterator>(shared_from_this());
807
13.9M
        } else {
808
9.37M
            *iterator = std::make_unique<FileColumnIterator>(shared_from_this());
809
9.37M
        }
810
23.2M
        (*iterator)->set_column_name(tablet_column ? tablet_column->name() : "");
811
23.2M
        return Status::OK();
812
23.2M
    } else {
813
74.0k
        auto type = _meta_type;
814
74.0k
        switch (type) {
815
838
        case FieldType::OLAP_FIELD_TYPE_AGG_STATE: {
816
838
            return new_agg_state_iterator(iterator);
817
0
        }
818
7.94k
        case FieldType::OLAP_FIELD_TYPE_STRUCT: {
819
7.94k
            return new_struct_iterator(iterator, tablet_column);
820
0
        }
821
62.1k
        case FieldType::OLAP_FIELD_TYPE_ARRAY: {
822
62.1k
            return new_array_iterator(iterator, tablet_column);
823
0
        }
824
31.9k
        case FieldType::OLAP_FIELD_TYPE_MAP: {
825
31.9k
            return new_map_iterator(iterator, tablet_column);
826
0
        }
827
0
        default:
828
0
            return Status::NotSupported("unsupported type to create iterator: {}",
829
0
                                        std::to_string(int(type)));
830
74.0k
        }
831
74.0k
    }
832
23.3M
}
833
834
832
Status ColumnReader::new_agg_state_iterator(ColumnIteratorUPtr* iterator) {
835
832
    *iterator = std::make_unique<FileColumnIterator>(shared_from_this());
836
832
    return Status::OK();
837
832
}
838
839
Status ColumnReader::new_array_iterator(ColumnIteratorUPtr* iterator,
840
61.8k
                                        const TabletColumn* tablet_column) {
841
61.8k
    ColumnIteratorUPtr item_iterator;
842
61.8k
    RETURN_IF_ERROR(_sub_readers[0]->new_iterator(
843
61.8k
            &item_iterator, tablet_column && tablet_column->get_subtype_count() > 0
844
61.8k
                                    ? &tablet_column->get_sub_column(0)
845
61.8k
                                    : nullptr));
846
847
61.8k
    item_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(0).name() : "");
848
849
61.8k
    ColumnIteratorUPtr offset_iterator;
850
61.8k
    RETURN_IF_ERROR(_sub_readers[1]->new_iterator(&offset_iterator, nullptr));
851
61.8k
    auto* file_iter = static_cast<FileColumnIterator*>(offset_iterator.release());
852
61.8k
    OffsetFileColumnIteratorUPtr ofcIter = std::make_unique<OffsetFileColumnIterator>(
853
61.8k
            std::unique_ptr<FileColumnIterator>(file_iter));
854
855
61.8k
    ColumnIteratorUPtr null_iterator;
856
61.8k
    if (is_nullable()) {
857
44.1k
        RETURN_IF_ERROR(_sub_readers[2]->new_iterator(&null_iterator, nullptr));
858
44.1k
    }
859
61.8k
    *iterator = std::make_unique<ArrayFileColumnIterator>(shared_from_this(), std::move(ofcIter),
860
61.8k
                                                          std::move(item_iterator),
861
61.8k
                                                          std::move(null_iterator));
862
61.8k
    return Status::OK();
863
61.8k
}
864
865
Status ColumnReader::new_map_iterator(ColumnIteratorUPtr* iterator,
866
31.8k
                                      const TabletColumn* tablet_column) {
867
31.8k
    ColumnIteratorUPtr key_iterator;
868
31.8k
    RETURN_IF_ERROR(_sub_readers[0]->new_iterator(
869
31.8k
            &key_iterator, tablet_column && tablet_column->get_subtype_count() > 1
870
31.8k
                                   ? &tablet_column->get_sub_column(0)
871
31.8k
                                   : nullptr));
872
31.8k
    key_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(0).name() : "");
873
31.8k
    ColumnIteratorUPtr val_iterator;
874
31.8k
    RETURN_IF_ERROR(_sub_readers[1]->new_iterator(
875
31.8k
            &val_iterator, tablet_column && tablet_column->get_subtype_count() > 1
876
31.8k
                                   ? &tablet_column->get_sub_column(1)
877
31.8k
                                   : nullptr));
878
31.8k
    val_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(1).name() : "");
879
31.8k
    ColumnIteratorUPtr offsets_iterator;
880
31.8k
    RETURN_IF_ERROR(_sub_readers[2]->new_iterator(&offsets_iterator, nullptr));
881
31.8k
    auto* file_iter = static_cast<FileColumnIterator*>(offsets_iterator.release());
882
31.8k
    OffsetFileColumnIteratorUPtr ofcIter = std::make_unique<OffsetFileColumnIterator>(
883
31.8k
            std::unique_ptr<FileColumnIterator>(file_iter));
884
885
31.8k
    ColumnIteratorUPtr null_iterator;
886
31.8k
    if (is_nullable()) {
887
16.1k
        RETURN_IF_ERROR(_sub_readers[3]->new_iterator(&null_iterator, nullptr));
888
16.1k
    }
889
31.8k
    *iterator = std::make_unique<MapFileColumnIterator>(
890
31.8k
            shared_from_this(), std::move(null_iterator), std::move(ofcIter),
891
31.8k
            std::move(key_iterator), std::move(val_iterator));
892
31.8k
    return Status::OK();
893
31.8k
}
894
895
Status ColumnReader::new_struct_iterator(ColumnIteratorUPtr* iterator,
896
7.93k
                                         const TabletColumn* tablet_column) {
897
7.93k
    std::vector<ColumnIteratorUPtr> sub_column_iterators;
898
7.93k
    size_t child_size = is_nullable() ? _sub_readers.size() - 1 : _sub_readers.size();
899
18.4E
    size_t tablet_column_size = tablet_column ? tablet_column->get_sub_columns().size() : 0;
900
7.93k
    sub_column_iterators.reserve(child_size);
901
902
36.5k
    for (uint64_t i = 0; i < child_size; i++) {
903
28.6k
        ColumnIteratorUPtr sub_column_iterator;
904
28.6k
        RETURN_IF_ERROR(_sub_readers[i]->new_iterator(
905
28.6k
                &sub_column_iterator, tablet_column ? &tablet_column->get_sub_column(i) : nullptr));
906
28.6k
        sub_column_iterator->set_column_name(tablet_column ? tablet_column->get_sub_column(i).name()
907
28.6k
                                                           : "");
908
28.6k
        sub_column_iterators.emplace_back(std::move(sub_column_iterator));
909
28.6k
    }
910
911
    // create default_iterator for schema-change behavior which increase column
912
9.24k
    for (size_t i = child_size; i < tablet_column_size; i++) {
913
1.30k
        TabletColumn column = tablet_column->get_sub_column(i);
914
1.30k
        ColumnIteratorUPtr it;
915
1.30k
        RETURN_IF_ERROR(Segment::new_default_iterator(column, &it));
916
1.30k
        it->set_column_name(column.name());
917
1.30k
        sub_column_iterators.emplace_back(std::move(it));
918
1.30k
    }
919
920
7.93k
    ColumnIteratorUPtr null_iterator;
921
7.93k
    if (is_nullable()) {
922
7.10k
        RETURN_IF_ERROR(_sub_readers[child_size]->new_iterator(&null_iterator, nullptr));
923
7.10k
    }
924
7.93k
    *iterator = std::make_unique<StructFileColumnIterator>(
925
7.93k
            shared_from_this(), std::move(null_iterator), std::move(sub_column_iterators));
926
7.93k
    return Status::OK();
927
7.93k
}
928
929
5.86k
void ColumnIterator::_convert_to_place_holder_column(MutableColumnPtr& dst, size_t count) {
930
5.86k
    if (_read_phase == ReadPhase::LAZY) {
931
3.95k
        return;
932
3.95k
    } else if (_read_requirement == ReadRequirement::LAZY_OUTPUT &&
933
1.91k
               _read_phase == ReadPhase::PREDICATE) {
934
        // This branch is for non-predicate columns that still have to appear in the
935
        // predicate-phase block so row filtering can keep all block columns aligned.
936
        // Columns already marked PREDICATE are read normally, and SKIP/NORMAL
937
        // columns do not participate in lazy materialization.
938
1.43k
        _has_place_holder_column = true;
939
1.43k
    }
940
941
1.91k
    dst->insert_many_defaults(count);
942
1.91k
}
943
944
3.19M
void ColumnIterator::_recovery_from_place_holder_column(MutableColumnPtr& dst) {
945
3.19M
    if (_read_phase == ReadPhase::LAZY && _has_place_holder_column) {
946
1.43k
        dst->clear();
947
1.43k
        _has_place_holder_column = false;
948
1.43k
    }
949
3.19M
}
950
951
Result<TColumnAccessPaths> ColumnIterator::_get_sub_access_paths(
952
119k
        TColumnAccessPaths sub_access_paths, bool is_predicate) {
953
    // Access paths passed to a complex iterator always start with the current
954
    // column name. Strip that component and return the remaining child-relative
955
    // paths to the caller. For example, when this iterator is for column `s`,
956
    // path `s.a.b` is converted to `a.b` and then dispatched to child `a`.
957
    //
958
    // If stripping the current column consumes the whole path, the current
959
    // iterator itself is requested rather than one of its children. Mark the
960
    // current iterator according to the path source: predicate paths must be read
961
    // in the predicate phase, while all/output paths become lazy output targets.
962
    // Empty or mismatched paths indicate an FE/BE access-path contract violation.
963
184k
    for (auto it = sub_access_paths.begin(); it != sub_access_paths.end();) {
964
65.9k
        TColumnAccessPath& name_path = *it;
965
65.9k
        if (name_path.data_access_path.path.empty()) {
966
2
            return ResultError(Status::InternalError(
967
2
                    "Invalid access path for column '{}': path is empty", _column_name));
968
2
        }
969
970
65.9k
        if (!StringCaseEqual()(name_path.data_access_path.path[0], _column_name)) {
971
3
            return ResultError(Status::InternalError(
972
3
                    R"(Invalid access path for column: expected name "{}", got "{}")", _column_name,
973
3
                    name_path.data_access_path.path[0]));
974
3
        }
975
976
65.9k
        name_path.data_access_path.path.erase(name_path.data_access_path.path.begin());
977
65.9k
        if (!name_path.data_access_path.path.empty()) {
978
10.1k
            ++it;
979
55.7k
        } else {
980
55.7k
            if (is_predicate) {
981
2.92k
                set_read_requirement(ReadRequirement::PREDICATE);
982
52.8k
            } else {
983
52.8k
                set_lazy_output_requirement();
984
52.8k
            }
985
55.7k
            it = sub_access_paths.erase(it);
986
55.7k
        }
987
65.9k
    }
988
119k
    return sub_access_paths;
989
119k
}
990
991
///====================== MapFileColumnIterator ============================////
992
MapFileColumnIterator::MapFileColumnIterator(std::shared_ptr<ColumnReader> reader,
993
                                             ColumnIteratorUPtr null_iterator,
994
                                             OffsetFileColumnIteratorUPtr offsets_iterator,
995
                                             ColumnIteratorUPtr key_iterator,
996
                                             ColumnIteratorUPtr val_iterator)
997
31.8k
        : _map_reader(reader),
998
31.8k
          _offsets_iterator(std::move(offsets_iterator)),
999
31.8k
          _key_iterator(std::move(key_iterator)),
1000
31.8k
          _val_iterator(std::move(val_iterator)) {
1001
31.8k
    if (_map_reader->is_nullable()) {
1002
16.1k
        _null_iterator = std::move(null_iterator);
1003
16.1k
    }
1004
31.8k
}
1005
1006
31.7k
Status MapFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1007
31.7k
    if (_read_requirement == ReadRequirement::SKIP) {
1008
31
        DLOG(INFO) << "Map column iterator column " << _column_name << " skip reading.";
1009
31
        return Status::OK();
1010
31
    }
1011
31.7k
    RETURN_IF_ERROR(_key_iterator->init(opts));
1012
31.7k
    RETURN_IF_ERROR(_val_iterator->init(opts));
1013
31.7k
    RETURN_IF_ERROR(_offsets_iterator->init(opts));
1014
31.7k
    if (_map_reader->is_nullable()) {
1015
16.1k
        RETURN_IF_ERROR(_null_iterator->init(opts));
1016
16.1k
    }
1017
31.7k
    return Status::OK();
1018
31.7k
}
1019
1020
19.4k
Status MapFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
1021
19.4k
    if (!need_to_read()) {
1022
0
        DLOG(INFO) << "Map column iterator column " << _column_name << " skip reading.";
1023
0
        return Status::OK();
1024
0
    }
1025
1026
19.4k
    if (read_null_map_only()) {
1027
        // In NULL_MAP_ONLY mode, only seek the null iterator; skip offset/key/val iterators
1028
11
        if (_map_reader->is_nullable() && _null_iterator) {
1029
11
            RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1030
11
        }
1031
11
        return Status::OK();
1032
11
    }
1033
1034
19.4k
    if (_map_reader->is_nullable()) {
1035
14.1k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1036
14.1k
    }
1037
19.4k
    RETURN_IF_ERROR(_offsets_iterator->seek_to_ordinal(ord));
1038
19.4k
    if (read_offset_only()) {
1039
        // In OFFSET_ONLY mode, key/value iterators are SKIP, no need to seek them
1040
466
        return Status::OK();
1041
466
    }
1042
    // here to use offset info
1043
18.9k
    ordinal_t offset = 0;
1044
18.9k
    RETURN_IF_ERROR(_offsets_iterator->_peek_one_offset(&offset));
1045
18.9k
    RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(offset));
1046
18.9k
    RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(offset));
1047
18.9k
    return Status::OK();
1048
18.9k
}
1049
1050
0
Status MapFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1051
0
    RETURN_IF_ERROR(_offsets_iterator->init_prefetcher(params));
1052
0
    if (_map_reader->is_nullable()) {
1053
0
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
1054
0
    }
1055
0
    RETURN_IF_ERROR(_key_iterator->init_prefetcher(params));
1056
0
    RETURN_IF_ERROR(_val_iterator->init_prefetcher(params));
1057
0
    return Status::OK();
1058
0
}
1059
1060
void MapFileColumnIterator::collect_prefetchers(
1061
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1062
1
        PrefetcherInitMethod init_method) {
1063
1
    if (!need_to_read()) {
1064
0
        return;
1065
0
    }
1066
1
    if (!read_null_map_only()) {
1067
1
        _offsets_iterator->collect_prefetchers(prefetchers, init_method);
1068
1
    }
1069
1
    if (_map_reader->is_nullable()) {
1070
1
        _null_iterator->collect_prefetchers(prefetchers, init_method);
1071
1
    }
1072
1
    if (read_offset_only() || read_null_map_only()) {
1073
0
        return;
1074
0
    }
1075
    // the actual data pages to read of key/value column depends on the read result of offset column,
1076
    // so we can't init prefetch blocks according to rowids, just prefetch all data blocks here.
1077
1
    if (_key_iterator->need_to_read()) {
1078
1
        _key_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
1079
1
    }
1080
1
    if (_val_iterator->need_to_read()) {
1081
1
        _val_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
1082
1
    }
1083
1
}
1084
1085
19.4k
Status MapFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1086
19.4k
    if (!need_to_read()) {
1087
0
        DLOG(INFO) << "Map column iterator column " << _column_name << " skip reading.";
1088
0
        _convert_to_place_holder_column(dst, *n);
1089
0
        return Status::OK();
1090
0
    }
1091
1092
19.4k
    _recovery_from_place_holder_column(dst);
1093
1094
19.4k
    if (read_null_map_only()) {
1095
        // NULL_MAP_ONLY mode: read null map, fill nested ColumnMap with empty defaults
1096
12
        DORIS_CHECK(is_column_nullable(*dst));
1097
12
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
1098
12
        auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1099
12
        size_t num_read = *n;
1100
12
        if (_null_iterator) {
1101
12
            bool null_signs_has_null = false;
1102
12
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1103
12
            RETURN_IF_ERROR(
1104
12
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1105
12
        } else {
1106
            // schema-change: column became nullable but old segment has no null data
1107
0
            null_map_ptr->insert_many_vals(0, num_read);
1108
0
        }
1109
12
        DCHECK(num_read == *n);
1110
        // fill nested ColumnMap with empty (zero-element) maps
1111
12
        auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1112
12
                nullable_col.get_nested_column());
1113
12
        column_map.insert_many_defaults(num_read);
1114
12
        *has_null = true;
1115
12
        return Status::OK();
1116
12
    }
1117
1118
19.4k
    auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1119
19.4k
            is_column_nullable(*dst) ? static_cast<ColumnNullable&>(*dst).get_nested_column()
1120
19.4k
                                     : *dst);
1121
19.4k
    const bool read_meta_columns = need_to_read_meta_columns();
1122
19.4k
    MutableColumnPtr column_offsets_ptr;
1123
19.4k
    if (read_meta_columns) {
1124
18.5k
        column_offsets_ptr = IColumn::mutate(std::move(column_map.get_offsets_ptr()));
1125
18.5k
    } else {
1126
        // The parent offsets were already materialized in the predicate phase, so
1127
        // they must not be appended to dst again. We still read offsets into a
1128
        // temporary column here: this sequential path may be serving a nested
1129
        // lazy read after seek_to_ordinal(), and the storage offsets are needed to
1130
        // compute how many key/value elements to read from the current source
1131
        // ordinal. The existing dst offsets only describe the filtered output
1132
        // shape and do not track the current source ordinal consumed by this
1133
        // iterator call.
1134
902
        const auto base_offset =
1135
902
                column_map.get_offsets().empty() ? 0 : column_map.get_offsets().back();
1136
902
        column_offsets_ptr = ColumnMap::COffsets::create();
1137
902
        assert_cast<ColumnOffset64&, TypeCheckOnRelease::DISABLE>(*column_offsets_ptr)
1138
902
                .insert_value(base_offset);
1139
902
    }
1140
19.4k
    Defer defer_offsets {[&] {
1141
19.4k
        if (read_meta_columns) {
1142
18.5k
            auto typed_column_offsets_ptr = ColumnMap::COffsets::cast_to_column_mutptr(
1143
18.5k
                    assert_cast<ColumnMap::COffsets*, TypeCheckOnRelease::DISABLE>(
1144
18.5k
                            column_offsets_ptr.get()));
1145
18.5k
            column_offsets_ptr = nullptr;
1146
18.5k
            column_map.get_offsets_ptr() = std::move(typed_column_offsets_ptr);
1147
18.5k
        }
1148
19.4k
    }};
1149
19.4k
    bool offsets_has_null = false;
1150
19.4k
    ssize_t start = column_offsets_ptr->size();
1151
19.4k
    RETURN_IF_ERROR(_offsets_iterator->next_batch(n, column_offsets_ptr, &offsets_has_null));
1152
19.4k
    if (*n == 0) {
1153
0
        return Status::OK();
1154
0
    }
1155
19.4k
    auto& column_offsets = static_cast<ColumnArray::ColumnOffsets&>(*column_offsets_ptr);
1156
19.4k
    RETURN_IF_ERROR(_offsets_iterator->_calculate_offsets(start, column_offsets));
1157
19.4k
    DCHECK(column_offsets.get_data().back() >= column_offsets.get_data()[start - 1]);
1158
19.4k
    size_t num_items =
1159
19.4k
            column_offsets.get_data().back() - column_offsets.get_data()[start - 1]; // -1 is valid
1160
1161
19.4k
    if (num_items > 0) {
1162
16.8k
        auto key_ptr = IColumn::mutate(std::move(column_map.get_keys_ptr()));
1163
16.8k
        auto val_ptr = IColumn::mutate(std::move(column_map.get_values_ptr()));
1164
16.8k
        Defer defer_keys {[&] { column_map.get_keys_ptr() = std::move(key_ptr); }};
1165
16.8k
        Defer defer_values {[&] { column_map.get_values_ptr() = std::move(val_ptr); }};
1166
16.8k
        if (read_offset_only()) {
1167
            // OFFSET_ONLY mode: skip reading actual key/value data, fill with defaults
1168
468
            key_ptr->insert_many_defaults(num_items);
1169
468
            val_ptr->insert_many_defaults(num_items);
1170
16.3k
        } else {
1171
16.3k
            size_t num_read = num_items;
1172
16.3k
            bool key_has_null = false;
1173
16.3k
            bool val_has_null = false;
1174
16.3k
            RETURN_IF_ERROR(_key_iterator->next_batch(&num_read, key_ptr, &key_has_null));
1175
16.3k
            RETURN_IF_ERROR(_val_iterator->next_batch(&num_read, val_ptr, &val_has_null));
1176
16.3k
            DCHECK(num_read == num_items);
1177
16.3k
        }
1178
16.8k
    }
1179
1180
19.4k
    if (is_column_nullable(*dst) && read_meta_columns) {
1181
13.2k
        size_t num_read = *n;
1182
13.2k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1183
        // in not-null to null linked-schemachange mode,
1184
        // actually we do not change dat data include meta in footer,
1185
        // so may dst from changed meta which is nullable but old data is not nullable,
1186
        // if so, we should set null_map to all null by default
1187
13.2k
        if (_null_iterator) {
1188
13.2k
            bool null_signs_has_null = false;
1189
13.2k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1190
13.2k
            RETURN_IF_ERROR(
1191
13.2k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1192
18.4E
        } else {
1193
18.4E
            null_map_ptr->insert_many_vals(0, num_read);
1194
18.4E
        }
1195
13.2k
        DCHECK(num_read == *n);
1196
13.2k
    }
1197
19.4k
    return Status::OK();
1198
19.4k
}
1199
1200
Status MapFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1201
13.4k
                                             MutableColumnPtr& dst) {
1202
13.4k
    if (!need_to_read()) {
1203
1
        DLOG(INFO) << "Map column iterator column " << _column_name << " skip reading.";
1204
1
        _convert_to_place_holder_column(dst, count);
1205
1
        return Status::OK();
1206
1
    }
1207
1208
13.4k
    _recovery_from_place_holder_column(dst);
1209
1210
13.4k
    if (read_null_map_only()) {
1211
        // NULL_MAP_ONLY mode: read null map by rowids, fill nested ColumnMap with empty defaults
1212
8
        DORIS_CHECK(is_column_nullable(*dst));
1213
8
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
1214
8
        if (_null_iterator) {
1215
8
            auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1216
8
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1217
8
            RETURN_IF_ERROR(_null_iterator->read_by_rowids(rowids, count, null_map_column));
1218
8
        } else {
1219
            // schema-change: column became nullable but old segment has no null data
1220
0
            auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1221
0
            null_map_ptr->insert_many_vals(0, count);
1222
0
        }
1223
        // fill nested ColumnMap with empty (zero-element) maps
1224
8
        auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1225
8
                nullable_col.get_nested_column());
1226
8
        column_map.insert_many_defaults(count);
1227
8
        return Status::OK();
1228
8
    }
1229
1230
13.3k
    if (count == 0) {
1231
0
        return Status::OK();
1232
0
    }
1233
1234
    // resolve ColumnMap and nullable wrapper
1235
13.3k
    auto& column_map = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1236
13.3k
            is_column_nullable(*dst) ? static_cast<ColumnNullable&>(*dst).get_nested_column()
1237
13.3k
                                     : *dst);
1238
13.3k
    const bool read_meta_columns = need_to_read_meta_columns();
1239
13.3k
    MutableColumnPtr offsets_ptr;
1240
13.3k
    if (read_meta_columns) {
1241
13.3k
        offsets_ptr = IColumn::mutate(std::move(column_map.get_offsets_ptr()));
1242
13.3k
    } else {
1243
17
        const auto base_offset =
1244
17
                column_map.get_offsets().empty() ? 0 : column_map.get_offsets().back();
1245
17
        offsets_ptr = ColumnMap::COffsets::create();
1246
17
        assert_cast<ColumnOffset64&, TypeCheckOnRelease::DISABLE>(*offsets_ptr)
1247
17
                .insert_value(base_offset);
1248
17
    }
1249
13.3k
    Defer defer_offsets {[&] {
1250
13.3k
        if (read_meta_columns) {
1251
13.3k
            auto typed_offsets_ptr = ColumnMap::COffsets::cast_to_column_mutptr(
1252
13.3k
                    assert_cast<ColumnMap::COffsets*, TypeCheckOnRelease::DISABLE>(
1253
13.3k
                            offsets_ptr.get()));
1254
13.3k
            offsets_ptr = nullptr;
1255
13.3k
            column_map.get_offsets_ptr() = std::move(typed_offsets_ptr);
1256
13.3k
        }
1257
13.3k
    }};
1258
13.3k
    auto& offsets = static_cast<ColumnArray::ColumnOffsets&>(*offsets_ptr);
1259
13.3k
    size_t base = offsets.get_data().empty() ? 0 : offsets.get_data().back();
1260
1261
    // 1. bulk read null-map if nullable
1262
13.3k
    std::vector<uint8_t> null_mask; // 0: not null, 1: null
1263
13.3k
    if (read_meta_columns) {
1264
13.3k
        if (_map_reader->is_nullable()) {
1265
            // For nullable map columns, the destination column must also be nullable.
1266
3.41k
            if (UNLIKELY(!is_column_nullable(*dst))) {
1267
0
                return Status::InternalError(
1268
0
                        "unexpected non-nullable destination column for nullable map reader");
1269
0
            }
1270
3.41k
            MutableColumnPtr null_map_ptr =
1271
3.41k
                    static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1272
3.41k
            size_t null_before = null_map_ptr->size();
1273
3.41k
            RETURN_IF_ERROR(_null_iterator->read_by_rowids(rowids, count, null_map_ptr));
1274
            // extract a light-weight view to decide element reads
1275
3.41k
            auto& null_map_col = assert_cast<ColumnUInt8&>(*null_map_ptr);
1276
3.41k
            const auto* src = null_map_col.get_data().data() + null_before;
1277
3.41k
            null_mask.assign(src, src + count);
1278
9.96k
        } else if (is_column_nullable(*dst)) {
1279
            // in not-null to null linked-schemachange mode,
1280
            // actually we do not change dat data include meta in footer,
1281
            // so may dst from changed meta which is nullable but old data is not nullable,
1282
            // if so, we should set null_map to all null by default
1283
1
            MutableColumnPtr null_map_ptr =
1284
1
                    static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1285
1
            auto& null_map = assert_cast<ColumnUInt8&>(*null_map_ptr);
1286
1
            null_map.insert_many_vals(0, count);
1287
1
        }
1288
13.3k
    } else if (_map_reader->is_nullable()) {
1289
        // In lazy mode the parent null map has already been materialized during
1290
        // predicate read and filtered together with the block. Reuse that dst
1291
        // null map to avoid re-reading the same meta column from storage.
1292
9
        if (UNLIKELY(!is_column_nullable(*dst))) {
1293
0
            return Status::InternalError(
1294
0
                    "unexpected non-nullable destination column for nullable map reader");
1295
0
        }
1296
9
        const auto& null_map_col = static_cast<const ColumnNullable&>(*dst).get_null_map_column();
1297
9
        DORIS_CHECK(null_map_col.size() == count);
1298
9
        const auto* src = null_map_col.get_data().data();
1299
9
        null_mask.assign(src, src + count);
1300
9
    }
1301
1302
    // 2. Bulk read source start ordinals for requested rows. The offsets stored
1303
    // in dst already describe the filtered output shape when read_meta_columns is
1304
    // false, but they do not contain the source key/value ordinal for each
1305
    // selected rowid. We still need the storage offsets here to seek child
1306
    // iterators to the correct source element ranges.
1307
13.3k
    MutableColumnPtr starts_col = ColumnOffset64::create();
1308
13.3k
    starts_col->reserve(count);
1309
13.3k
    RETURN_IF_ERROR(_offsets_iterator->read_by_rowids(rowids, count, starts_col));
1310
1311
    // 3. bulk read next-start ordinals for rowid+1 (within bounds)
1312
13.3k
    std::vector<rowid_t> next_rowids(count);
1313
208k
    for (size_t i = 0; i < count; ++i) {
1314
195k
        uint64_t nr = rowids[i] + 1;
1315
195k
        next_rowids[i] = nr < _map_reader->num_rows() ? static_cast<rowid_t>(nr)
1316
195k
                                                      : static_cast<rowid_t>(0); // placeholder
1317
195k
    }
1318
13.3k
    MutableColumnPtr next_starts_col = ColumnOffset64::create();
1319
13.3k
    next_starts_col->reserve(count);
1320
    // read for all; we'll fix out-of-bound cases below
1321
13.3k
    RETURN_IF_ERROR(_offsets_iterator->read_by_rowids(next_rowids.data(), count, next_starts_col));
1322
1323
    // 4. fix next_start for rows whose next_rowid is out-of-bound (rowid == num_rows-1)
1324
208k
    for (size_t i = 0; i < count; ++i) {
1325
195k
        if (rowids[i] + 1 >= _map_reader->num_rows()) {
1326
            // seek to the last row and consume one to move decoder to end-of-page,
1327
            // then peek page-tail sentinel next_array_item_ordinal as next_start
1328
12.5k
            RETURN_IF_ERROR(_offsets_iterator->seek_to_ordinal(rowids[i]));
1329
12.5k
            size_t one = 1;
1330
12.5k
            bool has_null_unused = false;
1331
12.5k
            MutableColumnPtr tmp = ColumnOffset64::create();
1332
12.5k
            RETURN_IF_ERROR(_offsets_iterator->next_batch(&one, tmp, &has_null_unused));
1333
12.5k
            ordinal_t ns = 0;
1334
12.5k
            RETURN_IF_ERROR(_offsets_iterator->_peek_one_offset(&ns));
1335
            // overwrite with sentinel
1336
12.5k
            assert_cast<ColumnOffset64&, TypeCheckOnRelease::DISABLE>(*next_starts_col)
1337
12.5k
                    .get_data()[i] = ns;
1338
12.5k
        }
1339
195k
    }
1340
1341
    // 5. compute sizes and append offsets prefix-sum
1342
13.3k
    auto& starts_data = assert_cast<ColumnOffset64&>(*starts_col).get_data();
1343
13.3k
    auto& next_starts_data = assert_cast<ColumnOffset64&>(*next_starts_col).get_data();
1344
13.3k
    std::vector<size_t> sizes(count, 0);
1345
13.3k
    size_t acc = base;
1346
13.3k
    if (read_meta_columns) {
1347
13.3k
        offsets.get_data().reserve(offsets.get_data().size() + count);
1348
13.3k
    }
1349
206k
    for (size_t i = 0; i < count; ++i) {
1350
193k
        auto sz = static_cast<size_t>(next_starts_data[i] - starts_data[i]);
1351
193k
        if (_map_reader->is_nullable() && !null_mask.empty() && null_mask[i]) {
1352
703
            sz = 0; // null rows do not consume elements
1353
703
        }
1354
193k
        sizes[i] = sz;
1355
193k
        acc += sz;
1356
193k
        if (read_meta_columns) {
1357
168k
            offsets.get_data().push_back(acc);
1358
168k
        }
1359
193k
    }
1360
1361
    // 6. read key/value elements for non-empty sizes
1362
13.3k
    auto keys_ptr = IColumn::mutate(std::move(column_map.get_keys_ptr()));
1363
13.3k
    auto vals_ptr = IColumn::mutate(std::move(column_map.get_values_ptr()));
1364
13.3k
    Defer defer_keys {[&] { column_map.get_keys_ptr() = std::move(keys_ptr); }};
1365
13.3k
    Defer defer_values {[&] { column_map.get_values_ptr() = std::move(vals_ptr); }};
1366
1367
13.3k
    size_t this_run = sizes[0];
1368
13.3k
    auto start_idx = starts_data[0];
1369
13.3k
    auto last_idx = starts_data[0] + this_run;
1370
193k
    for (size_t i = 1; i < count; ++i) {
1371
180k
        size_t sz = sizes[i];
1372
180k
        if (sz == 0) {
1373
49.1k
            continue;
1374
49.1k
        }
1375
131k
        auto start = static_cast<ordinal_t>(starts_data[i]);
1376
131k
        if (start != last_idx) {
1377
869
            size_t n = this_run;
1378
869
            bool dummy_has_null = false;
1379
1380
869
            if (this_run != 0) {
1381
869
                RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(start_idx));
1382
869
                RETURN_IF_ERROR(_key_iterator->next_batch(&n, keys_ptr, &dummy_has_null));
1383
869
                DCHECK(n == this_run);
1384
1385
869
                n = this_run;
1386
869
                RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(start_idx));
1387
869
                RETURN_IF_ERROR(_val_iterator->next_batch(&n, vals_ptr, &dummy_has_null));
1388
869
                DCHECK(n == this_run);
1389
869
            }
1390
869
            start_idx = start;
1391
869
            this_run = sz;
1392
869
            last_idx = start + sz;
1393
869
            continue;
1394
869
        }
1395
1396
130k
        this_run += sz;
1397
130k
        last_idx += sz;
1398
130k
    }
1399
1400
13.3k
    size_t n = this_run;
1401
13.3k
    bool dummy_has_null = false;
1402
13.3k
    if (this_run != 0) {
1403
5.31k
        RETURN_IF_ERROR(_key_iterator->seek_to_ordinal(start_idx));
1404
5.31k
        RETURN_IF_ERROR(_key_iterator->next_batch(&n, keys_ptr, &dummy_has_null));
1405
5.31k
        DCHECK(n == this_run);
1406
1407
5.31k
        n = this_run;
1408
5.31k
        RETURN_IF_ERROR(_val_iterator->seek_to_ordinal(start_idx));
1409
5.31k
        RETURN_IF_ERROR(_val_iterator->next_batch(&n, vals_ptr, &dummy_has_null));
1410
5.31k
        DCHECK(n == this_run);
1411
5.31k
    }
1412
13.3k
    return Status::OK();
1413
13.3k
}
1414
1415
5.69k
void MapFileColumnIterator::set_lazy_output_requirement() {
1416
5.69k
    set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
1417
5.69k
    _key_iterator->set_lazy_output_requirement();
1418
5.69k
    _val_iterator->set_lazy_output_requirement();
1419
5.69k
}
1420
1421
7.81k
void MapFileColumnIterator::remove_pruned_sub_iterators() {
1422
7.81k
    _key_iterator->remove_pruned_sub_iterators();
1423
7.81k
    _val_iterator->remove_pruned_sub_iterators();
1424
7.81k
}
1425
1426
Status MapFileColumnIterator::set_access_paths(const TColumnAccessPaths& all_access_paths,
1427
7.59k
                                               const TColumnAccessPaths& predicate_access_paths) {
1428
7.59k
    if (all_access_paths.empty() && predicate_access_paths.empty()) {
1429
1.51k
        return Status::OK();
1430
1.51k
    }
1431
1432
6.08k
    const auto requirement_before_access_path = _read_requirement;
1433
6.08k
    if (!predicate_access_paths.empty()) {
1434
252
        set_read_requirement_self(ReadRequirement::PREDICATE);
1435
252
        DLOG(INFO) << "Map column iterator set sub-column " << _column_name << " to PREDICATE";
1436
252
    }
1437
1438
6.08k
    const bool has_current_level_data_path =
1439
7.02k
            std::ranges::any_of(all_access_paths, [this](const TColumnAccessPath& path) {
1440
7.02k
                return is_current_level_data_access_path(path, _column_name);
1441
7.02k
            });
1442
6.08k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1443
6.08k
    auto sub_predicate_access_paths =
1444
6.08k
            DORIS_TRY(_get_sub_access_paths(predicate_access_paths, true));
1445
6.08k
    if (has_current_level_data_path) {
1446
3.92k
        remove_current_level_meta_access_paths(sub_all_access_paths);
1447
3.92k
    }
1448
6.08k
    const bool has_current_level_predicate_meta_path =
1449
6.08k
            std::ranges::any_of(sub_predicate_access_paths, is_current_level_meta_access_path);
1450
    // Current-level predicate metadata paths are consumed by this map iterator and must not be
1451
    // forwarded to key/value children. The FE keeps all_access_paths as a superset of predicate
1452
    // paths, so meta-only mode is still decided from sub_all_access_paths below.
1453
6.08k
    remove_current_level_meta_access_paths(sub_predicate_access_paths);
1454
1455
6.08k
    if (sub_predicate_access_paths.empty() && _read_requirement == ReadRequirement::PREDICATE &&
1456
6.08k
        !has_current_level_predicate_meta_path) {
1457
        // if no sub-column in predicate_access_paths, but current column is PREDICATE,
1458
        // then we should set key/value iterator to PREDICATE too.
1459
1
        _key_iterator->set_read_requirement(ReadRequirement::PREDICATE);
1460
1
        _val_iterator->set_read_requirement(ReadRequirement::PREDICATE);
1461
1
    }
1462
1463
6.08k
    if (sub_predicate_access_paths.empty()) {
1464
        // Check for meta-only modes (OFFSET_ONLY or NULL_MAP_ONLY). Only skip key/value
1465
        // iterators when no predicate sub-path needs them in the predicate phase.
1466
5.79k
        _check_and_set_meta_read_mode(requirement_before_access_path, sub_all_access_paths);
1467
5.79k
        if (read_offset_only()) {
1468
451
            _key_iterator->set_read_requirement(ReadRequirement::SKIP);
1469
451
            _val_iterator->set_read_requirement(ReadRequirement::SKIP);
1470
451
            DLOG(INFO) << "Map column iterator set column " << _column_name
1471
451
                       << " to OFFSET_ONLY meta read mode, key/value columns set to SKIP";
1472
451
            return Status::OK();
1473
451
        }
1474
5.34k
        if (read_null_map_only()) {
1475
20
            _key_iterator->set_read_requirement(ReadRequirement::SKIP);
1476
20
            _val_iterator->set_read_requirement(ReadRequirement::SKIP);
1477
20
            DLOG(INFO) << "Map column iterator set column " << _column_name
1478
20
                       << " to NULL_MAP_ONLY meta read mode, key/value columns set to SKIP";
1479
20
            return Status::OK();
1480
20
        }
1481
5.34k
    }
1482
1483
    // A current-level data path is consumed by _get_sub_access_paths() and leaves
1484
    // sub_all_access_paths empty after marking key/value as lazy-read targets. Predicate
1485
    // sub-paths still have to be routed to child iterators for the predicate phase.
1486
5.61k
    if (sub_all_access_paths.empty() && sub_predicate_access_paths.empty()) {
1487
3.91k
        return Status::OK();
1488
3.91k
    }
1489
1490
1.69k
    TColumnAccessPaths key_all_access_paths;
1491
1.69k
    TColumnAccessPaths val_all_access_paths;
1492
1.69k
    TColumnAccessPaths key_predicate_access_paths;
1493
1.69k
    TColumnAccessPaths val_predicate_access_paths;
1494
1495
2.60k
    for (auto paths : sub_all_access_paths) {
1496
2.60k
        if (paths.data_access_path.path[0] == ACCESS_ALL) {
1497
            // ACCESS_ALL means element_at(map, key) style access: the key column must be
1498
            // fully read so that the runtime can match the requested key, while any sub-path
1499
            // qualifiers (e.g. OFFSET) apply only to the value column.
1500
            // For key: create a path with just the column name (= full data access).
1501
1.12k
            TColumnAccessPath key_path;
1502
1.12k
            key_path.__set_type(paths.type);
1503
1.12k
            TDataAccessPath key_data_path;
1504
1.12k
            key_data_path.__set_path({_key_iterator->column_name()});
1505
1.12k
            key_path.__set_data_access_path(key_data_path);
1506
1.12k
            key_all_access_paths.emplace_back(std::move(key_path));
1507
            // For value: pass the full sub-path so qualifiers like OFFSET propagate.
1508
1.12k
            paths.data_access_path.path[0] = _val_iterator->column_name();
1509
1.12k
            val_all_access_paths.emplace_back(paths);
1510
1.47k
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_KEYS) {
1511
1.18k
            paths.data_access_path.path[0] = _key_iterator->column_name();
1512
1.18k
            key_all_access_paths.emplace_back(paths);
1513
1.18k
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_VALUES) {
1514
274
            paths.data_access_path.path[0] = _val_iterator->column_name();
1515
274
            val_all_access_paths.emplace_back(paths);
1516
274
        }
1517
2.60k
    }
1518
1.69k
    for (auto paths : sub_predicate_access_paths) {
1519
404
        if (paths.data_access_path.path[0] == ACCESS_ALL) {
1520
            // Same logic as above: key needs full data, value gets the sub-path.
1521
198
            TColumnAccessPath key_path;
1522
198
            key_path.__set_type(paths.type);
1523
198
            TDataAccessPath key_data_path;
1524
198
            key_data_path.__set_path({_key_iterator->column_name()});
1525
198
            key_path.__set_data_access_path(key_data_path);
1526
198
            key_predicate_access_paths.emplace_back(std::move(key_path));
1527
198
            paths.data_access_path.path[0] = _val_iterator->column_name();
1528
198
            val_predicate_access_paths.emplace_back(paths);
1529
206
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_KEYS) {
1530
191
            paths.data_access_path.path[0] = _key_iterator->column_name();
1531
191
            key_predicate_access_paths.emplace_back(paths);
1532
191
        } else if (paths.data_access_path.path[0] == ACCESS_MAP_VALUES) {
1533
15
            paths.data_access_path.path[0] = _val_iterator->column_name();
1534
15
            val_predicate_access_paths.emplace_back(paths);
1535
15
        }
1536
404
    }
1537
1538
1.69k
    const auto need_read_keys =
1539
1.69k
            !key_all_access_paths.empty() || !key_predicate_access_paths.empty();
1540
1.69k
    const auto need_read_values =
1541
1.69k
            !val_all_access_paths.empty() || !val_predicate_access_paths.empty();
1542
1543
1.69k
    if (need_read_keys) {
1544
1.41k
        RETURN_IF_ERROR(
1545
1.41k
                _key_iterator->set_access_paths(key_all_access_paths, key_predicate_access_paths));
1546
        // Apply LAZY_OUTPUT after child predicate paths have been handled. Read requirements are
1547
        // monotonic, so a predicate-only child already promoted to PREDICATE will not
1548
        // be downgraded, while a non-predicate child becomes a lazy materialization target.
1549
1.41k
        _key_iterator->set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
1550
1.41k
    } else {
1551
286
        _key_iterator->set_read_requirement(ReadRequirement::SKIP);
1552
286
        DLOG(INFO) << "Map column iterator set key column to SKIP";
1553
286
    }
1554
1555
1.69k
    if (need_read_values) {
1556
1.41k
        RETURN_IF_ERROR(
1557
1.41k
                _val_iterator->set_access_paths(val_all_access_paths, val_predicate_access_paths));
1558
        // Same as keys: predicate-only value paths stay PREDICATE because this
1559
        // post-processing update cannot lower a stronger child requirement.
1560
1.41k
        _val_iterator->set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
1561
1.41k
    } else {
1562
282
        _val_iterator->set_read_requirement(ReadRequirement::SKIP);
1563
282
        DLOG(INFO) << "Map column iterator set value column to SKIP";
1564
282
    }
1565
1.69k
    return Status::OK();
1566
1.69k
}
1567
1568
65.1k
void MapFileColumnIterator::set_read_phase(ReadPhase mode) {
1569
65.1k
    ColumnIterator::set_read_phase(mode);
1570
65.1k
    _key_iterator->set_read_phase(mode);
1571
65.1k
    _val_iterator->set_read_phase(mode);
1572
65.1k
}
1573
1574
970
void MapFileColumnIterator::finalize_lazy_phase(MutableColumnPtr& dst) {
1575
970
    _recovery_from_place_holder_column(dst);
1576
970
    auto& map_column = assert_cast<ColumnMap&, TypeCheckOnRelease::DISABLE>(
1577
970
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1578
970
    auto keys_ptr = IColumn::mutate(std::move(map_column.get_keys_ptr()));
1579
970
    auto vals_ptr = IColumn::mutate(std::move(map_column.get_values_ptr()));
1580
970
    _key_iterator->finalize_lazy_phase(keys_ptr);
1581
970
    _val_iterator->finalize_lazy_phase(vals_ptr);
1582
970
    map_column.get_keys_ptr() = std::move(keys_ptr);
1583
970
    map_column.get_values_ptr() = std::move(vals_ptr);
1584
970
}
1585
1586
49
void MapFileColumnIterator::set_read_requirement(ReadRequirement requirement) {
1587
49
    set_read_requirement_self(requirement);
1588
49
    _key_iterator->set_read_requirement(requirement);
1589
49
    _val_iterator->set_read_requirement(requirement);
1590
49
}
1591
1592
10.1k
bool MapFileColumnIterator::has_lazy_read_target() const {
1593
10.1k
    return _read_requirement == ReadRequirement::LAZY_OUTPUT ||
1594
10.1k
           _key_iterator->has_lazy_read_target() || _val_iterator->has_lazy_read_target();
1595
10.1k
}
1596
1597
////////////////////////////////////////////////////////////////////////////////
1598
1599
StructFileColumnIterator::StructFileColumnIterator(
1600
        std::shared_ptr<ColumnReader> reader, ColumnIteratorUPtr null_iterator,
1601
        std::vector<ColumnIteratorUPtr>&& sub_column_iterators)
1602
7.99k
        : _struct_reader(reader), _sub_column_iterators(std::move(sub_column_iterators)) {
1603
7.99k
    if (_struct_reader->is_nullable()) {
1604
7.09k
        _null_iterator = std::move(null_iterator);
1605
7.09k
    }
1606
7.99k
}
1607
1608
7.89k
Status StructFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1609
7.89k
    if (_read_requirement == ReadRequirement::SKIP) {
1610
0
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1611
0
        return Status::OK();
1612
0
    }
1613
1614
28.3k
    for (auto& column_iterator : _sub_column_iterators) {
1615
28.3k
        RETURN_IF_ERROR(column_iterator->init(opts));
1616
28.3k
    }
1617
7.89k
    if (_struct_reader->is_nullable()) {
1618
7.08k
        RETURN_IF_ERROR(_null_iterator->init(opts));
1619
7.08k
    }
1620
7.89k
    return Status::OK();
1621
7.89k
}
1622
1623
11.3k
Status StructFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1624
11.3k
    if (!need_to_read()) {
1625
2
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1626
2
        _convert_to_place_holder_column(dst, *n);
1627
2
        return Status::OK();
1628
2
    }
1629
1630
11.3k
    _recovery_from_place_holder_column(dst);
1631
1632
11.3k
    if (read_null_map_only()) {
1633
        // NULL_MAP_ONLY mode: read null map, fill nested ColumnStruct with empty defaults
1634
3
        DORIS_CHECK(is_column_nullable(*dst));
1635
3
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
1636
3
        auto null_map_ptr = nullable_col.get_null_map_column_ptr();
1637
3
        size_t num_read = *n;
1638
3
        if (_null_iterator) {
1639
3
            bool null_signs_has_null = false;
1640
3
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1641
3
            RETURN_IF_ERROR(
1642
3
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1643
3
        } else {
1644
            // schema-change: column became nullable but old segment has no null data
1645
0
            null_map_ptr->insert_many_vals(0, num_read);
1646
0
        }
1647
3
        DCHECK(num_read == *n);
1648
        // fill nested ColumnStruct with defaults to maintain consistent column sizes
1649
3
        auto& column_struct = assert_cast<ColumnStruct&, TypeCheckOnRelease::DISABLE>(
1650
3
                nullable_col.get_nested_column());
1651
3
        column_struct.insert_many_defaults(num_read);
1652
3
        *has_null = true;
1653
3
        return Status::OK();
1654
3
    }
1655
1656
11.3k
    auto& column_struct = assert_cast<ColumnStruct&, TypeCheckOnRelease::DISABLE>(
1657
11.3k
            is_column_nullable(*dst) ? static_cast<ColumnNullable&>(*dst).get_nested_column()
1658
11.3k
                                     : *dst);
1659
38.6k
    for (size_t i = 0; i < column_struct.tuple_size(); i++) {
1660
27.2k
        size_t num_read = *n;
1661
27.2k
        auto sub_column_ptr = IColumn::mutate(std::move(column_struct.get_column_ptr(i)));
1662
27.2k
        Defer defer_sub_column {
1663
27.2k
                [&] { column_struct.get_column_ptr(i) = std::move(sub_column_ptr); }};
1664
27.2k
        bool column_has_null = false;
1665
27.2k
        RETURN_IF_ERROR(
1666
27.2k
                _sub_column_iterators[i]->next_batch(&num_read, sub_column_ptr, &column_has_null));
1667
27.2k
        DCHECK(num_read == *n);
1668
27.2k
    }
1669
1670
11.3k
    if (is_column_nullable(*dst) && need_to_read_meta_columns()) {
1671
7.08k
        size_t num_read = *n;
1672
7.08k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
1673
        // in not-null to null linked-schemachange mode,
1674
        // actually we do not change dat data include meta in footer,
1675
        // so may dst from changed meta which is nullable but old data is not nullable,
1676
        // if so, we should set null_map to all null by default
1677
7.08k
        if (_null_iterator) {
1678
7.00k
            bool null_signs_has_null = false;
1679
7.00k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
1680
7.00k
            RETURN_IF_ERROR(
1681
7.00k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
1682
7.00k
        } else {
1683
89
            null_map_ptr->insert_many_vals(0, num_read);
1684
89
        }
1685
7.08k
        DCHECK(num_read == *n);
1686
7.08k
    }
1687
1688
11.3k
    return Status::OK();
1689
11.3k
}
1690
1691
11.3k
Status StructFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
1692
11.3k
    if (!need_to_read()) {
1693
2
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1694
2
        return Status::OK();
1695
2
    }
1696
1697
11.3k
    if (read_null_map_only()) {
1698
        // In NULL_MAP_ONLY mode, only seek the null iterator; skip all sub-column iterators
1699
2
        if (_struct_reader->is_nullable() && _null_iterator) {
1700
2
            RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1701
2
        }
1702
2
        return Status::OK();
1703
2
    }
1704
1705
27.2k
    for (auto& column_iterator : _sub_column_iterators) {
1706
27.2k
        RETURN_IF_ERROR(column_iterator->seek_to_ordinal(ord));
1707
27.2k
    }
1708
1709
11.3k
    if (_struct_reader->is_nullable() && need_to_read_meta_columns()) {
1710
7.00k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
1711
7.00k
    }
1712
11.3k
    return Status::OK();
1713
11.3k
}
1714
1715
0
Status StructFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1716
0
    for (auto& column_iterator : _sub_column_iterators) {
1717
0
        RETURN_IF_ERROR(column_iterator->init_prefetcher(params));
1718
0
    }
1719
0
    if (_struct_reader->is_nullable()) {
1720
0
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
1721
0
    }
1722
0
    return Status::OK();
1723
0
}
1724
1725
void StructFileColumnIterator::collect_prefetchers(
1726
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1727
2
        PrefetcherInitMethod init_method) {
1728
2
    if (!need_to_read()) {
1729
0
        return;
1730
0
    }
1731
2
    if (_struct_reader->is_nullable()) {
1732
2
        _null_iterator->collect_prefetchers(prefetchers, init_method);
1733
2
    }
1734
2
    if (read_null_map_only()) {
1735
0
        return;
1736
0
    }
1737
4
    for (auto& column_iterator : _sub_column_iterators) {
1738
4
        if (column_iterator->need_to_read()) {
1739
2
            column_iterator->collect_prefetchers(prefetchers, init_method);
1740
2
        }
1741
4
    }
1742
2
}
1743
1744
Status StructFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
1745
3.57k
                                                MutableColumnPtr& dst) {
1746
3.57k
    if (!need_to_read()) {
1747
0
        DLOG(INFO) << "Struct column iterator column " << _column_name << " skip reading.";
1748
0
        _convert_to_place_holder_column(dst, count);
1749
0
        return Status::OK();
1750
0
    }
1751
1752
3.57k
    _recovery_from_place_holder_column(dst);
1753
1754
3.57k
    if (count == 0) {
1755
0
        return Status::OK();
1756
0
    }
1757
1758
3.57k
    size_t this_run = 1;
1759
3.57k
    auto start_idx = rowids[0];
1760
3.57k
    auto last_idx = rowids[0];
1761
5.99k
    for (size_t i = 1; i < count; ++i) {
1762
2.41k
        if (last_idx == rowids[i] - 1) {
1763
318
            last_idx = rowids[i];
1764
318
            this_run++;
1765
318
            continue;
1766
318
        }
1767
2.09k
        RETURN_IF_ERROR(seek_to_ordinal(start_idx));
1768
2.09k
        size_t num_read = this_run;
1769
2.09k
        RETURN_IF_ERROR(next_batch(&num_read, dst));
1770
2.09k
        DCHECK_EQ(num_read, this_run);
1771
1772
2.09k
        start_idx = rowids[i];
1773
2.09k
        last_idx = rowids[i];
1774
2.09k
        this_run = 1;
1775
2.09k
    }
1776
1777
3.57k
    RETURN_IF_ERROR(seek_to_ordinal(start_idx));
1778
3.57k
    size_t num_read = this_run;
1779
3.57k
    RETURN_IF_ERROR(next_batch(&num_read, dst));
1780
3.57k
    DCHECK_EQ(num_read, this_run);
1781
3.57k
    return Status::OK();
1782
3.57k
}
1783
1784
6.87k
void StructFileColumnIterator::set_lazy_output_requirement() {
1785
6.87k
    set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
1786
25.7k
    for (auto& sub_iterator : _sub_column_iterators) {
1787
25.7k
        sub_iterator->set_lazy_output_requirement();
1788
25.7k
    }
1789
6.87k
}
1790
1791
7.07k
void StructFileColumnIterator::remove_pruned_sub_iterators() {
1792
34.6k
    for (auto it = _sub_column_iterators.begin(); it != _sub_column_iterators.end();) {
1793
27.5k
        auto& sub_iterator = *it;
1794
27.5k
        if (sub_iterator->read_requirement() == ReadRequirement::SKIP) {
1795
1.48k
            DLOG(INFO) << "Struct column iterator remove pruned sub-column "
1796
1.48k
                       << sub_iterator->column_name();
1797
1.48k
            it = _sub_column_iterators.erase(it);
1798
26.0k
        } else {
1799
26.0k
            sub_iterator->remove_pruned_sub_iterators();
1800
26.0k
            ++it;
1801
26.0k
        }
1802
27.5k
    }
1803
7.07k
}
1804
1805
Status StructFileColumnIterator::set_access_paths(
1806
        const TColumnAccessPaths& all_access_paths,
1807
6.57k
        const TColumnAccessPaths& predicate_access_paths) {
1808
6.57k
    if (all_access_paths.empty() && predicate_access_paths.empty()) {
1809
1.86k
        return Status::OK();
1810
1.86k
    }
1811
1812
4.70k
    const auto requirement_before_access_path = _read_requirement;
1813
4.70k
    if (!predicate_access_paths.empty()) {
1814
142
        set_read_requirement_self(ReadRequirement::PREDICATE);
1815
142
        DLOG(INFO) << "Struct column iterator set sub-column " << _column_name << " to PREDICATE";
1816
142
    }
1817
1818
4.70k
    const bool has_current_level_data_path =
1819
4.81k
            std::ranges::any_of(all_access_paths, [this](const TColumnAccessPath& path) {
1820
4.81k
                return is_current_level_data_access_path(path, _column_name);
1821
4.81k
            });
1822
4.70k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
1823
4.70k
    auto sub_predicate_access_paths =
1824
4.70k
            DORIS_TRY(_get_sub_access_paths(predicate_access_paths, true));
1825
4.70k
    if (has_current_level_data_path) {
1826
4.42k
        remove_current_level_meta_access_paths(sub_all_access_paths);
1827
4.42k
    }
1828
4.70k
    const bool has_current_level_predicate_meta_path =
1829
4.70k
            std::ranges::any_of(sub_predicate_access_paths, is_current_level_meta_access_path);
1830
    // Current-level predicate metadata paths are consumed by this struct iterator and must not be
1831
    // forwarded to child fields. The FE keeps all_access_paths as a superset of predicate paths, so
1832
    // NULL_MAP_ONLY is still decided from sub_all_access_paths below.
1833
4.70k
    remove_current_level_meta_access_paths(sub_predicate_access_paths);
1834
1835
4.70k
    if (sub_predicate_access_paths.empty()) {
1836
        // Check for NULL_MAP_ONLY mode: only read null map, skip all sub-columns.
1837
        // Do not take this early return when predicate child paths must still be read.
1838
4.57k
        _check_and_set_meta_read_mode(requirement_before_access_path, sub_all_access_paths);
1839
4.57k
        if (read_null_map_only()) {
1840
9
            for (auto& sub_iterator : _sub_column_iterators) {
1841
9
                sub_iterator->set_read_requirement(ReadRequirement::SKIP);
1842
9
            }
1843
5
            DLOG(INFO) << "Struct column iterator set column " << _column_name
1844
5
                       << " to NULL_MAP_ONLY meta read mode, all sub-columns set to SKIP";
1845
5
            return Status::OK();
1846
5
        }
1847
4.57k
    }
1848
1849
4.69k
    const auto no_sub_column_to_skip = sub_all_access_paths.empty();
1850
4.69k
    const auto no_predicate_sub_column = sub_predicate_access_paths.empty();
1851
1852
22.1k
    for (auto& sub_iterator : _sub_column_iterators) {
1853
22.1k
        const auto name = sub_iterator->column_name();
1854
22.1k
        TColumnAccessPaths sub_all_access_paths_of_this;
1855
22.1k
        if (!no_sub_column_to_skip) {
1856
2.25k
            for (const auto& paths : sub_all_access_paths) {
1857
2.25k
                if (paths.data_access_path.path[0] == name) {
1858
378
                    sub_all_access_paths_of_this.emplace_back(paths);
1859
378
                }
1860
2.25k
            }
1861
1.87k
        }
1862
1863
22.1k
        TColumnAccessPaths sub_predicate_access_paths_of_this;
1864
22.1k
        if (!no_predicate_sub_column) {
1865
1.12k
            for (const auto& paths : sub_predicate_access_paths) {
1866
1.12k
                if (StringCaseEqual()(paths.data_access_path.path[0], name)) {
1867
130
                    sub_predicate_access_paths_of_this.emplace_back(paths);
1868
130
                }
1869
1.12k
            }
1870
1.12k
        }
1871
1872
        // Predicate-only child paths still need to be routed to the child iterator
1873
        // even when the child is not requested by ordinary projection access paths.
1874
22.1k
        const bool need_to_read = no_sub_column_to_skip || !sub_all_access_paths_of_this.empty() ||
1875
22.1k
                                  !sub_predicate_access_paths_of_this.empty();
1876
22.1k
        if (!need_to_read) {
1877
1.50k
            set_read_requirement_self(ReadRequirement::SKIP);
1878
1.50k
            sub_iterator->set_read_requirement(ReadRequirement::SKIP);
1879
1.50k
            DLOG(INFO) << "Struct column iterator set sub-column " << name << " to SKIP";
1880
1.50k
            continue;
1881
1.50k
        }
1882
1883
20.6k
        if (no_predicate_sub_column && _read_requirement == ReadRequirement::PREDICATE &&
1884
20.6k
            !has_current_level_predicate_meta_path) {
1885
            // if no sub-column in predicate_access_paths, but current column is PREDICATE,
1886
            // then we should set sub iterator to PREDICATE too.
1887
6
            sub_iterator->set_read_requirement(ReadRequirement::PREDICATE);
1888
6
        }
1889
1890
20.6k
        RETURN_IF_ERROR(sub_iterator->set_access_paths(sub_all_access_paths_of_this,
1891
20.6k
                                                       sub_predicate_access_paths_of_this));
1892
        // Set LAZY_OUTPUT after routing child predicate paths. If the child was needed only for
1893
        // predicate evaluation, set_access_paths() has already promoted it to
1894
        // PREDICATE and this monotonic update will not downgrade it. Otherwise, this
1895
        // marks the child as a lazy materialization target.
1896
20.6k
        set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
1897
20.6k
        sub_iterator->set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
1898
20.6k
    }
1899
4.69k
    return Status::OK();
1900
4.69k
}
1901
1902
28.1k
void StructFileColumnIterator::set_read_phase(ReadPhase mode) {
1903
28.1k
    ColumnIterator::set_read_phase(mode);
1904
79.2k
    for (auto& sub_iterator : _sub_column_iterators) {
1905
79.2k
        sub_iterator->set_read_phase(mode);
1906
79.2k
    }
1907
28.1k
}
1908
1909
1.91k
void StructFileColumnIterator::finalize_lazy_phase(MutableColumnPtr& dst) {
1910
1.91k
    _recovery_from_place_holder_column(dst);
1911
1.91k
    auto& column_struct = assert_cast<ColumnStruct&, TypeCheckOnRelease::DISABLE>(
1912
1.91k
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
1913
1914
5.29k
    for (size_t i = 0; i < _sub_column_iterators.size(); ++i) {
1915
3.37k
        auto& sub_column = column_struct.get_column_ptr(i);
1916
3.37k
        MutableColumnPtr mutable_sub_column = IColumn::mutate(std::move(sub_column));
1917
3.37k
        _sub_column_iterators[i]->finalize_lazy_phase(mutable_sub_column);
1918
3.37k
        sub_column = std::move(mutable_sub_column);
1919
3.37k
    }
1920
1.91k
}
1921
1922
20
void StructFileColumnIterator::set_read_requirement(ReadRequirement requirement) {
1923
20
    set_read_requirement_self(requirement);
1924
40
    for (const auto& sub_column_iterator : _sub_column_iterators) {
1925
40
        sub_column_iterator->set_read_requirement(requirement);
1926
40
    }
1927
20
}
1928
1929
18.9k
bool StructFileColumnIterator::has_lazy_read_target() const {
1930
18.9k
    if (_read_requirement == ReadRequirement::LAZY_OUTPUT) {
1931
2.46k
        return true;
1932
2.46k
    }
1933
16.4k
    return std::any_of(_sub_column_iterators.begin(), _sub_column_iterators.end(),
1934
19.3k
                       [](const auto& sub_column_iterator) {
1935
19.3k
                           return sub_column_iterator->has_lazy_read_target();
1936
19.3k
                       });
1937
18.9k
}
1938
1939
////////////////////////////////////////////////////////////////////////////////
1940
93.3k
Status OffsetFileColumnIterator::init(const ColumnIteratorOptions& opts) {
1941
93.3k
    RETURN_IF_ERROR(_offset_iterator->init(opts));
1942
    // allocate peek tmp column once
1943
93.3k
    _peek_tmp_col = ColumnOffset64::create();
1944
93.3k
    return Status::OK();
1945
93.3k
}
1946
1947
133k
Status OffsetFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
1948
133k
    RETURN_IF_ERROR(_offset_iterator->next_batch(n, dst, has_null));
1949
133k
    return Status::OK();
1950
133k
}
1951
1952
252k
Status OffsetFileColumnIterator::_peek_one_offset(ordinal_t* offset) {
1953
252k
    if (_offset_iterator->get_current_page()->has_remaining()) {
1954
169k
        PageDecoder* offset_page_decoder = _offset_iterator->get_current_page()->data_decoder.get();
1955
169k
        size_t n = 1;
1956
169k
        _peek_tmp_col->clear();
1957
169k
        RETURN_IF_ERROR(offset_page_decoder->peek_next_batch(&n, _peek_tmp_col)); // not null
1958
169k
        DCHECK(_peek_tmp_col->size() == 1);
1959
169k
        *offset =
1960
169k
                assert_cast<const ColumnOffset64*, TypeCheckOnRelease::DISABLE>(_peek_tmp_col.get())
1961
169k
                        ->get_element(0);
1962
169k
    } else {
1963
82.5k
        *offset = _offset_iterator->get_current_page()->next_array_item_ordinal;
1964
82.5k
    }
1965
252k
    return Status::OK();
1966
252k
}
1967
1968
0
Status OffsetFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
1969
0
    return _offset_iterator->init_prefetcher(params);
1970
0
}
1971
1972
void OffsetFileColumnIterator::collect_prefetchers(
1973
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
1974
2
        PrefetcherInitMethod init_method) {
1975
2
    _offset_iterator->collect_prefetchers(prefetchers, init_method);
1976
2
}
1977
1978
/**
1979
 *  first_storage_offset read from page should smaller than next_storage_offset which here call _peek_one_offset from page,
1980
    and first_column_offset is keep in memory data which is different dimension with (first_storage_offset and next_storage_offset)
1981
     eg. step1. read page: first_storage_offset = 16382
1982
         step2. read page below with _peek_one_offset(&last_offset): last_offset = 16387
1983
         step3. first_offset = 126 which is calculate in column offsets
1984
         for loop column offsets element in size
1985
            we can calculate from first_storage_offset to next_storage_offset one by one to fill with offsets_data in memory column offsets
1986
 * @param start
1987
 * @param column_offsets
1988
 * @return
1989
 */
1990
Status OffsetFileColumnIterator::_calculate_offsets(ssize_t start,
1991
120k
                                                    ColumnArray::ColumnOffsets& column_offsets) {
1992
120k
    ordinal_t next_storage_offset = 0;
1993
120k
    RETURN_IF_ERROR(_peek_one_offset(&next_storage_offset));
1994
1995
    // calculate real offsets
1996
120k
    auto& offsets_data = column_offsets.get_data();
1997
120k
    ordinal_t first_column_offset = offsets_data[start - 1]; // -1 is valid
1998
120k
    ordinal_t first_storage_offset = offsets_data[start];
1999
120k
    DCHECK(next_storage_offset >= first_storage_offset);
2000
4.10M
    for (ssize_t i = start; i < offsets_data.size() - 1; ++i) {
2001
3.98M
        offsets_data[i] = first_column_offset + (offsets_data[i + 1] - first_storage_offset);
2002
3.98M
    }
2003
    // last offset
2004
120k
    offsets_data[offsets_data.size() - 1] =
2005
120k
            first_column_offset + (next_storage_offset - first_storage_offset);
2006
120k
    return Status::OK();
2007
120k
}
2008
2009
////////////////////////////////////////////////////////////////////////////////
2010
ArrayFileColumnIterator::ArrayFileColumnIterator(std::shared_ptr<ColumnReader> reader,
2011
                                                 OffsetFileColumnIteratorUPtr offset_reader,
2012
                                                 ColumnIteratorUPtr item_iterator,
2013
                                                 ColumnIteratorUPtr null_iterator)
2014
62.0k
        : _array_reader(reader),
2015
62.0k
          _offset_iterator(std::move(offset_reader)),
2016
62.0k
          _item_iterator(std::move(item_iterator)) {
2017
62.0k
    if (_array_reader->is_nullable()) {
2018
44.2k
        _null_iterator = std::move(null_iterator);
2019
44.2k
    }
2020
62.0k
}
2021
2022
61.7k
Status ArrayFileColumnIterator::init(const ColumnIteratorOptions& opts) {
2023
61.7k
    if (_read_requirement == ReadRequirement::SKIP) {
2024
56
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip reading.";
2025
56
        return Status::OK();
2026
56
    }
2027
2028
61.7k
    RETURN_IF_ERROR(_offset_iterator->init(opts));
2029
61.7k
    RETURN_IF_ERROR(_item_iterator->init(opts));
2030
61.7k
    if (_array_reader->is_nullable()) {
2031
44.0k
        RETURN_IF_ERROR(_null_iterator->init(opts));
2032
44.0k
    }
2033
61.7k
    return Status::OK();
2034
61.7k
}
2035
2036
101k
Status ArrayFileColumnIterator::_seek_by_offsets(ordinal_t ord) {
2037
101k
    if (read_offset_only()) {
2038
        // In OFFSET_ONLY mode, item iterator is SKIP, no need to seek it
2039
1.13k
        return Status::OK();
2040
1.13k
    }
2041
    // using offsets info
2042
100k
    ordinal_t offset = 0;
2043
100k
    RETURN_IF_ERROR(_offset_iterator->_peek_one_offset(&offset));
2044
100k
    RETURN_IF_ERROR(_item_iterator->seek_to_ordinal(offset));
2045
100k
    return Status::OK();
2046
100k
}
2047
2048
102k
Status ArrayFileColumnIterator::seek_to_ordinal(ordinal_t ord) {
2049
102k
    if (!need_to_read()) {
2050
1.28k
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip reading.";
2051
1.28k
        return Status::OK();
2052
1.28k
    }
2053
2054
101k
    if (read_null_map_only()) {
2055
        // In NULL_MAP_ONLY mode, only seek the null iterator; skip offset and item iterators
2056
4
        if (_array_reader->is_nullable() && _null_iterator) {
2057
4
            RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
2058
4
        }
2059
4
        return Status::OK();
2060
4
    }
2061
2062
101k
    RETURN_IF_ERROR(_offset_iterator->seek_to_ordinal(ord));
2063
101k
    if (_array_reader->is_nullable()) {
2064
82.8k
        RETURN_IF_ERROR(_null_iterator->seek_to_ordinal(ord));
2065
82.8k
    }
2066
101k
    return _seek_by_offsets(ord);
2067
101k
}
2068
2069
102k
Status ArrayFileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2070
102k
    if (!need_to_read()) {
2071
1.29k
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip reading, read phase"
2072
1.29k
                   << static_cast<int>(_read_phase)
2073
1.29k
                   << ", read requirement: " << static_cast<int>(_read_requirement);
2074
1.29k
        _convert_to_place_holder_column(dst, *n);
2075
1.29k
        return Status::OK();
2076
1.29k
    }
2077
2078
101k
    _recovery_from_place_holder_column(dst);
2079
2080
101k
    if (read_null_map_only()) {
2081
        // NULL_MAP_ONLY mode: read null map, fill nested ColumnArray with empty defaults
2082
5
        DORIS_CHECK(is_column_nullable(*dst));
2083
5
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
2084
5
        auto null_map_ptr = nullable_col.get_null_map_column_ptr();
2085
5
        size_t num_read = *n;
2086
5
        if (_null_iterator) {
2087
5
            bool null_signs_has_null = false;
2088
5
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
2089
5
            RETURN_IF_ERROR(
2090
5
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
2091
5
        } else {
2092
            // schema-change: column became nullable but old segment has no null data
2093
0
            null_map_ptr->insert_many_vals(0, num_read);
2094
0
        }
2095
5
        DCHECK(num_read == *n);
2096
        // fill nested ColumnArray with empty (zero-length) arrays
2097
5
        auto& column_array = assert_cast<ColumnArray&, TypeCheckOnRelease::DISABLE>(
2098
5
                nullable_col.get_nested_column());
2099
5
        column_array.insert_many_defaults(num_read);
2100
5
        *has_null = true;
2101
5
        return Status::OK();
2102
5
    }
2103
2104
101k
    auto& column_array = assert_cast<ColumnArray&, TypeCheckOnRelease::DISABLE>(
2105
101k
            is_column_nullable(*dst) ? static_cast<ColumnNullable&>(*dst).get_nested_column()
2106
101k
                                     : *dst);
2107
2108
101k
    bool offsets_has_null = false;
2109
101k
    const bool read_meta_columns = need_to_read_meta_columns();
2110
101k
    MutableColumnPtr column_offsets_ptr;
2111
101k
    if (read_meta_columns) {
2112
100k
        column_offsets_ptr = IColumn::mutate(std::move(column_array.get_offsets_ptr()));
2113
100k
    } else {
2114
961
        const auto base_offset =
2115
961
                column_array.get_offsets().empty() ? 0 : column_array.get_offsets().back();
2116
961
        column_offsets_ptr = ColumnArray::ColumnOffsets::create();
2117
961
        assert_cast<ColumnOffset64&, TypeCheckOnRelease::DISABLE>(*column_offsets_ptr)
2118
961
                .insert_value(base_offset);
2119
961
    }
2120
101k
    Defer defer_offsets {[&] {
2121
101k
        if (read_meta_columns) {
2122
100k
            auto typed_column_offsets_ptr = ColumnArray::ColumnOffsets::cast_to_column_mutptr(
2123
100k
                    assert_cast<ColumnArray::ColumnOffsets*, TypeCheckOnRelease::DISABLE>(
2124
100k
                            column_offsets_ptr.get()));
2125
100k
            column_offsets_ptr = nullptr;
2126
100k
            column_array.get_offsets_ptr() = std::move(typed_column_offsets_ptr);
2127
100k
        }
2128
101k
    }};
2129
101k
    ssize_t start = column_offsets_ptr->size();
2130
101k
    RETURN_IF_ERROR(_offset_iterator->next_batch(n, column_offsets_ptr, &offsets_has_null));
2131
101k
    if (*n == 0) {
2132
0
        return Status::OK();
2133
0
    }
2134
101k
    auto& column_offsets = static_cast<ColumnArray::ColumnOffsets&>(*column_offsets_ptr);
2135
101k
    RETURN_IF_ERROR(_offset_iterator->_calculate_offsets(start, column_offsets));
2136
101k
    size_t num_items =
2137
101k
            column_offsets.get_data().back() - column_offsets.get_data()[start - 1]; // -1 is valid
2138
101k
    if (num_items > 0) {
2139
76.4k
        auto column_items_ptr = IColumn::mutate(std::move(column_array.get_data_ptr()));
2140
76.4k
        Defer defer_items {[&] { column_array.get_data_ptr() = std::move(column_items_ptr); }};
2141
76.4k
        if (read_offset_only()) {
2142
            // OFFSET_ONLY mode: skip reading actual item data, fill with defaults
2143
1.02k
            column_items_ptr->insert_many_defaults(num_items);
2144
75.4k
        } else {
2145
75.4k
            size_t num_read = num_items;
2146
75.4k
            bool items_has_null = false;
2147
75.4k
            RETURN_IF_ERROR(
2148
75.4k
                    _item_iterator->next_batch(&num_read, column_items_ptr, &items_has_null));
2149
75.4k
            DCHECK(num_read == num_items);
2150
75.4k
        }
2151
76.4k
    }
2152
2153
101k
    if (is_column_nullable(*dst) && read_meta_columns) {
2154
81.9k
        auto null_map_ptr = static_cast<ColumnNullable&>(*dst).get_null_map_column_ptr();
2155
81.9k
        size_t num_read = *n;
2156
        // in not-null to null linked-schemachange mode,
2157
        // actually we do not change dat data include meta in footer,
2158
        // so may dst from changed meta which is nullable but old data is not nullable,
2159
        // if so, we should set null_map to all null by default
2160
81.9k
        if (_null_iterator) {
2161
81.9k
            bool null_signs_has_null = false;
2162
81.9k
            MutableColumnPtr null_map_column = std::move(null_map_ptr);
2163
81.9k
            RETURN_IF_ERROR(
2164
81.9k
                    _null_iterator->next_batch(&num_read, null_map_column, &null_signs_has_null));
2165
18.4E
        } else {
2166
18.4E
            null_map_ptr->insert_many_vals(0, num_read);
2167
18.4E
        }
2168
81.9k
        DCHECK(num_read == *n);
2169
81.9k
    }
2170
2171
101k
    return Status::OK();
2172
101k
}
2173
2174
0
Status ArrayFileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
2175
0
    RETURN_IF_ERROR(_offset_iterator->init_prefetcher(params));
2176
0
    RETURN_IF_ERROR(_item_iterator->init_prefetcher(params));
2177
0
    if (_array_reader->is_nullable()) {
2178
0
        RETURN_IF_ERROR(_null_iterator->init_prefetcher(params));
2179
0
    }
2180
0
    return Status::OK();
2181
0
}
2182
2183
void ArrayFileColumnIterator::collect_prefetchers(
2184
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
2185
1
        PrefetcherInitMethod init_method) {
2186
1
    if (!need_to_read()) {
2187
0
        return;
2188
0
    }
2189
1
    if (!read_null_map_only()) {
2190
1
        _offset_iterator->collect_prefetchers(prefetchers, init_method);
2191
1
    }
2192
1
    if (_array_reader->is_nullable()) {
2193
1
        _null_iterator->collect_prefetchers(prefetchers, init_method);
2194
1
    }
2195
1
    if (read_offset_only() || read_null_map_only()) {
2196
0
        return;
2197
0
    }
2198
    // the actual data pages to read of item column depends on the read result of offset column,
2199
    // so we can't init prefetch blocks according to rowids, just prefetch all data blocks here.
2200
1
    if (_item_iterator->need_to_read()) {
2201
1
        _item_iterator->collect_prefetchers(prefetchers, PrefetcherInitMethod::ALL_DATA_BLOCKS);
2202
1
    }
2203
1
}
2204
2205
Status ArrayFileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
2206
30.7k
                                               MutableColumnPtr& dst) {
2207
30.7k
    if (!need_to_read()) {
2208
0
        DLOG(INFO) << "Array column iterator column " << _column_name << " skip reading.";
2209
0
        _convert_to_place_holder_column(dst, count);
2210
0
        return Status::OK();
2211
0
    }
2212
2213
30.7k
    _recovery_from_place_holder_column(dst);
2214
2215
103k
    for (size_t i = 0; i < count; ++i) {
2216
        // TODO(cambyszju): now read array one by one, need optimize later
2217
72.5k
        RETURN_IF_ERROR(seek_to_ordinal(rowids[i]));
2218
72.5k
        size_t num_read = 1;
2219
72.5k
        RETURN_IF_ERROR(next_batch(&num_read, dst));
2220
72.5k
    }
2221
30.7k
    return Status::OK();
2222
30.7k
}
2223
2224
45.7k
void ArrayFileColumnIterator::set_lazy_output_requirement() {
2225
45.7k
    set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
2226
45.7k
    _item_iterator->set_lazy_output_requirement();
2227
45.7k
}
2228
2229
50.2k
void ArrayFileColumnIterator::remove_pruned_sub_iterators() {
2230
50.2k
    _item_iterator->remove_pruned_sub_iterators();
2231
50.2k
}
2232
2233
197k
void ArrayFileColumnIterator::set_read_phase(ReadPhase mode) {
2234
197k
    ColumnIterator::set_read_phase(mode);
2235
197k
    _item_iterator->set_read_phase(mode);
2236
197k
}
2237
2238
998
void ArrayFileColumnIterator::finalize_lazy_phase(MutableColumnPtr& dst) {
2239
998
    _recovery_from_place_holder_column(dst);
2240
998
    auto& column_array = assert_cast<ColumnArray&, TypeCheckOnRelease::DISABLE>(
2241
998
            dst->is_nullable() ? static_cast<ColumnNullable&>(*dst).get_nested_column() : *dst);
2242
998
    auto item_column_ptr = IColumn::mutate(std::move(column_array.get_data_ptr()));
2243
998
    _item_iterator->finalize_lazy_phase(item_column_ptr);
2244
998
    column_array.get_data_ptr() = std::move(item_column_ptr);
2245
998
}
2246
2247
2.98k
void ArrayFileColumnIterator::set_read_requirement(ReadRequirement requirement) {
2248
2.98k
    set_read_requirement_self(requirement);
2249
2.98k
    _item_iterator->set_read_requirement(requirement);
2250
2.98k
}
2251
2252
12.8k
bool ArrayFileColumnIterator::has_lazy_read_target() const {
2253
12.8k
    return _read_requirement == ReadRequirement::LAZY_OUTPUT ||
2254
12.8k
           _item_iterator->has_lazy_read_target();
2255
12.8k
}
2256
2257
Status ArrayFileColumnIterator::set_access_paths(const TColumnAccessPaths& all_access_paths,
2258
50.0k
                                                 const TColumnAccessPaths& predicate_access_paths) {
2259
50.0k
    if (all_access_paths.empty() && predicate_access_paths.empty()) {
2260
1.75k
        return Status::OK();
2261
1.75k
    }
2262
2263
48.3k
    const auto requirement_before_access_path = _read_requirement;
2264
48.3k
    if (!predicate_access_paths.empty()) {
2265
3.39k
        set_read_requirement_self(ReadRequirement::PREDICATE);
2266
3.39k
        DLOG(INFO) << "Array column iterator set sub-column " << _column_name << " to PREDICATE";
2267
3.39k
    }
2268
2269
48.3k
    const bool has_current_level_data_path =
2270
48.3k
            std::ranges::any_of(all_access_paths, [this](const TColumnAccessPath& path) {
2271
48.2k
                return is_current_level_data_access_path(path, _column_name);
2272
48.2k
            });
2273
48.3k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
2274
48.3k
    auto sub_predicate_access_paths =
2275
48.3k
            DORIS_TRY(_get_sub_access_paths(predicate_access_paths, true));
2276
48.3k
    if (has_current_level_data_path) {
2277
        // A current-level data path already reads the array offsets while materializing the array.
2278
        // Do not let a redundant current-level OFFSET/NULL path switch this iterator into a
2279
        // meta-only mode that would skip item data.
2280
43.1k
        remove_current_level_meta_access_paths(sub_all_access_paths);
2281
43.1k
    }
2282
48.3k
    const bool has_current_level_predicate_meta_path =
2283
48.3k
            std::ranges::any_of(sub_predicate_access_paths, is_current_level_meta_access_path);
2284
    // Current-level predicate metadata paths are consumed by this array iterator and must not be
2285
    // forwarded to the item iterator. The FE keeps all_access_paths as a superset of predicate
2286
    // paths, so meta-only mode is still decided from sub_all_access_paths below.
2287
48.3k
    auto removed =
2288
48.3k
            std::ranges::remove_if(sub_predicate_access_paths, is_current_level_meta_access_path);
2289
48.3k
    sub_predicate_access_paths.erase(removed.begin(), removed.end());
2290
2291
48.3k
    if (sub_predicate_access_paths.empty()) {
2292
        // Check for meta-only modes (OFFSET_ONLY or NULL_MAP_ONLY). Only skip the item
2293
        // iterator when no predicate sub-path needs it in the predicate phase.
2294
48.1k
        _check_and_set_meta_read_mode(requirement_before_access_path, sub_all_access_paths);
2295
48.1k
        if (read_offset_only()) {
2296
1.08k
            _item_iterator->set_read_requirement(ReadRequirement::SKIP);
2297
1.08k
            DLOG(INFO) << "Array column iterator set column " << _column_name
2298
1.08k
                       << " to OFFSET_ONLY meta read mode, item column set to SKIP";
2299
1.08k
            return Status::OK();
2300
1.08k
        }
2301
47.0k
        if (read_null_map_only()) {
2302
14
            _item_iterator->set_read_requirement(ReadRequirement::SKIP);
2303
14
            DLOG(INFO) << "Array column iterator set column " << _column_name
2304
14
                       << " to NULL_MAP_ONLY meta read mode, item column set to SKIP";
2305
14
            return Status::OK();
2306
14
        }
2307
47.0k
    }
2308
    // OFFSET/NULL at the current array level is consumed by this iterator. After deciding that
2309
    // the array is not in a meta-only mode, do not forward those paths to the item iterator.
2310
47.2k
    remove_current_level_meta_access_paths(sub_all_access_paths);
2311
2312
47.2k
    const auto no_sub_column_to_skip = sub_all_access_paths.empty();
2313
47.2k
    const auto no_predicate_sub_column = sub_predicate_access_paths.empty();
2314
2315
47.2k
    if (!no_sub_column_to_skip) {
2316
3.99k
        for (auto& path : sub_all_access_paths) {
2317
3.99k
            if (path.data_access_path.path[0] == ACCESS_ALL) {
2318
3.94k
                path.data_access_path.path[0] = _item_iterator->column_name();
2319
3.94k
            }
2320
3.99k
        }
2321
3.92k
    }
2322
2323
47.2k
    if (no_predicate_sub_column) {
2324
        // Current-level predicate meta paths (OFFSET/NULL) are consumed by the array itself and
2325
        // removed before forwarding paths to the item iterator. If they are the only predicate
2326
        // paths, the item iterator may still be needed later for lazy materialization, but it must
2327
        // not be promoted to PREDICATE. Only propagate the predicate requirement when the
2328
        // parent predicate really applies to the item/whole value instead of array metadata only.
2329
46.7k
        if (_read_requirement == ReadRequirement::PREDICATE &&
2330
46.7k
            !has_current_level_predicate_meta_path) {
2331
2.91k
            _item_iterator->set_read_requirement(ReadRequirement::PREDICATE);
2332
2.91k
        }
2333
46.7k
    } else {
2334
502
        for (auto& path : sub_predicate_access_paths) {
2335
410
            if (path.data_access_path.path[0] == ACCESS_ALL) {
2336
410
                path.data_access_path.path[0] = _item_iterator->column_name();
2337
410
            }
2338
410
        }
2339
502
    }
2340
2341
47.2k
    if (!no_sub_column_to_skip || !no_predicate_sub_column) {
2342
3.93k
        RETURN_IF_ERROR(
2343
3.93k
                _item_iterator->set_access_paths(sub_all_access_paths, sub_predicate_access_paths));
2344
        // Predicate-only item paths stay PREDICATE because this update runs after
2345
        // child set_access_paths() and read requirements are monotonic. Non-predicate item paths are
2346
        // marked as lazy materialization targets.
2347
3.93k
        _item_iterator->set_read_requirement_self(ReadRequirement::LAZY_OUTPUT);
2348
3.93k
    }
2349
47.2k
    return Status::OK();
2350
47.2k
}
2351
2352
////////////////////////////////////////////////////////////////////////////////
2353
// StringFileColumnIterator implementation
2354
////////////////////////////////////////////////////////////////////////////////
2355
2356
StringFileColumnIterator::StringFileColumnIterator(std::shared_ptr<ColumnReader> reader)
2357
13.9M
        : FileColumnIterator(std::move(reader)) {}
2358
2359
13.9M
Status StringFileColumnIterator::init(const ColumnIteratorOptions& opts) {
2360
13.9M
    if (read_offset_only()) {
2361
        // Propagate only_read_offsets to the FileColumnIterator's options
2362
338
        auto modified_opts = opts;
2363
338
        modified_opts.only_read_offsets = true;
2364
338
        return FileColumnIterator::init(modified_opts);
2365
338
    }
2366
13.9M
    return FileColumnIterator::init(opts);
2367
13.9M
}
2368
2369
Status StringFileColumnIterator::set_access_paths(
2370
        const TColumnAccessPaths& all_access_paths,
2371
5.59k
        const TColumnAccessPaths& predicate_access_paths) {
2372
5.59k
    if (all_access_paths.empty() && predicate_access_paths.empty()) {
2373
3.81k
        return Status::OK();
2374
3.81k
    }
2375
2376
1.78k
    const auto requirement_before_access_path = _read_requirement;
2377
1.78k
    if (!predicate_access_paths.empty()) {
2378
351
        set_read_requirement(ReadRequirement::PREDICATE);
2379
351
    }
2380
2381
1.78k
    const bool has_current_level_data_path =
2382
1.78k
            std::ranges::any_of(all_access_paths, [this](const TColumnAccessPath& path) {
2383
1.76k
                return is_current_level_data_access_path(path, _column_name);
2384
1.76k
            });
2385
    // Strip the column name from path[0] before checking for meta-only modes.
2386
    // Raw paths look like ["col_name", "OFFSET"] or ["col_name", "NULL"].
2387
1.78k
    auto sub_all_access_paths = DORIS_TRY(_get_sub_access_paths(all_access_paths));
2388
1.78k
    if (has_current_level_data_path) {
2389
1.18k
        remove_current_level_meta_access_paths(sub_all_access_paths);
2390
1.18k
    }
2391
1.78k
    _check_and_set_meta_read_mode(requirement_before_access_path, sub_all_access_paths);
2392
    // OFFSET_ONLY mode is fundamentally incompatible with CHAR columns:
2393
    // CHAR is stored padded to its declared length (see
2394
    // OlapColumnDataConvertorChar::clone_and_padding), so the per-row length
2395
    // recorded in dict word info / page headers is always the padded length
2396
    // (e.g. 25 for CHAR(25)) — never the logical length expected by length().
2397
    // Recovering the logical length requires scanning the chars buffer with
2398
    // strnlen() (shrink_padding_chars), which OFFSET_ONLY by definition skips.
2399
    // There is no partial-benefit path: any optimization that still produces
2400
    // the correct length() result must read the chars buffer in full.
2401
    //
2402
    // FE (NestedColumnPruning) already filters CHAR slots out of the
2403
    // OFFSET-only access plan, so reaching this branch means an FE/BE
2404
    // contract violation. Fail loudly instead of silently falling back.
2405
1.78k
    if (read_offset_only() && get_reader() != nullptr &&
2406
1.78k
        get_reader()->get_meta_type() == FieldType::OLAP_FIELD_TYPE_CHAR) {
2407
0
        return Status::InternalError(
2408
0
                "OFFSET_ONLY access path is not supported on CHAR column '{}': CHAR is stored "
2409
0
                "padded so the per-row length information available without reading the chars "
2410
0
                "buffer is always the padded length, not the logical length. The FE planner "
2411
0
                "must not emit an OFFSET access path for CHAR columns.",
2412
0
                _column_name);
2413
0
    }
2414
1.78k
    if (read_offset_only()) {
2415
337
        DLOG(INFO) << "String column iterator set column " << _column_name
2416
337
                   << " to OFFSET_ONLY meta read mode";
2417
1.44k
    } else if (read_null_map_only()) {
2418
221
        DLOG(INFO) << "String column iterator set column " << _column_name
2419
221
                   << " to NULL_MAP_ONLY meta read mode";
2420
221
    }
2421
2422
1.78k
    return Status::OK();
2423
1.78k
}
2424
2425
////////////////////////////////////////////////////////////////////////////////
2426
2427
23.2M
FileColumnIterator::FileColumnIterator(std::shared_ptr<ColumnReader> reader) : _reader(reader) {}
2428
2429
void ColumnIterator::_check_and_set_meta_read_mode(ReadRequirement requirement_before_access_path,
2430
59.3k
                                                   const TColumnAccessPaths& sub_all_access_paths) {
2431
59.3k
    _meta_read_mode = MetaReadMode::DEFAULT;
2432
59.3k
    if (requirement_before_access_path != ReadRequirement::NORMAL &&
2433
59.3k
        requirement_before_access_path != ReadRequirement::SKIP) {
2434
        // A stronger requirement means a parent/full-data path already required this iterator
2435
        // to materialize data. In that case a later predicate NULL/OFFSET path is only
2436
        // an additional predicate requirement and must not downgrade the read to
2437
        // meta-only.
2438
42
        return;
2439
42
    }
2440
2441
59.3k
    bool has_offset_path = false;
2442
59.3k
    bool has_null_path = false;
2443
59.3k
    for (const auto& path : sub_all_access_paths) {
2444
7.08k
        if (!is_current_level_meta_access_path(path)) {
2445
5.11k
            _meta_read_mode = MetaReadMode::DEFAULT;
2446
5.11k
            return;
2447
5.11k
        }
2448
1.96k
        const auto& component = path.data_access_path.path[0];
2449
1.96k
        if (StringCaseEqual()(component, ACCESS_OFFSET)) {
2450
1.91k
            has_offset_path = true;
2451
1.91k
        } else {
2452
52
            has_null_path = true;
2453
52
        }
2454
1.96k
    }
2455
54.1k
    if (has_offset_path) {
2456
        // OFFSET_ONLY skips actual child/string data, but nullable complex iterators still
2457
        // materialize the current-level null map. So OFFSET covers OFFSET+NULL metadata.
2458
1.91k
        _meta_read_mode = MetaReadMode::OFFSET_ONLY;
2459
52.2k
    } else if (has_null_path) {
2460
261
        _meta_read_mode = MetaReadMode::NULL_MAP_ONLY;
2461
52.0k
    } else {
2462
52.0k
        _meta_read_mode = MetaReadMode::DEFAULT;
2463
52.0k
    }
2464
54.1k
}
2465
2466
23.1M
Status FileColumnIterator::init(const ColumnIteratorOptions& opts) {
2467
23.1M
    if (_read_requirement == ReadRequirement::SKIP) {
2468
2.39k
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2469
2.39k
        return Status::OK();
2470
2.39k
    }
2471
2472
23.1M
    _opts = opts;
2473
23.1M
    if (!_opts.use_page_cache) {
2474
22.2M
        _reader->disable_index_meta_cache();
2475
22.2M
    }
2476
23.1M
    RETURN_IF_ERROR(get_block_compression_codec(_reader->get_compression(), &_compress_codec));
2477
23.1M
    if (config::enable_low_cardinality_optimize &&
2478
23.2M
        opts.io_ctx.reader_type == ReaderType::READER_QUERY &&
2479
23.1M
        _reader->encoding_info()->encoding() == DICT_ENCODING) {
2480
13.7M
        auto dict_encoding_type = _reader->get_dict_encoding_type();
2481
        // Only if the column is a predicate column, then we need check the all dict encoding flag
2482
        // because we could rewrite the predciate to accelarate query speed. But if it is not a
2483
        // predicate column, then it is useless. And it has a bad impact on cold read(first time read)
2484
        // because it will load the column's ordinal index and zonemap index and maybe other indices.
2485
        // it has bad impact on primary key query. For example, select * from table where pk = 1, and
2486
        // the table has 2000 columns.
2487
13.7M
        if (dict_encoding_type == ColumnReader::UNKNOWN_DICT_ENCODING && opts.is_predicate_column) {
2488
5.76k
            RETURN_IF_ERROR(seek_to_ordinal(_reader->num_rows() - 1));
2489
5.76k
            _is_all_dict_encoding = _page.is_dict_encoding;
2490
5.76k
            _reader->set_dict_encoding_type(_is_all_dict_encoding
2491
5.76k
                                                    ? ColumnReader::ALL_DICT_ENCODING
2492
5.76k
                                                    : ColumnReader::PARTIAL_DICT_ENCODING);
2493
13.7M
        } else {
2494
13.7M
            _is_all_dict_encoding = dict_encoding_type == ColumnReader::ALL_DICT_ENCODING;
2495
13.7M
        }
2496
13.7M
    }
2497
23.1M
    return Status::OK();
2498
23.1M
}
2499
2500
23.3M
FileColumnIterator::~FileColumnIterator() = default;
2501
2502
0
void FileColumnIterator::_trigger_prefetch_if_eligible(ordinal_t ord) {
2503
0
    std::vector<BlockRange> ranges;
2504
0
    if (_prefetcher->need_prefetch(cast_set<uint32_t>(ord), &ranges)) {
2505
0
        for (const auto& range : ranges) {
2506
0
            _cached_remote_file_reader->prefetch_range(range.offset, range.size, &_opts.io_ctx);
2507
0
        }
2508
0
    }
2509
0
}
2510
2511
3.05M
Status FileColumnIterator::seek_to_ordinal(ordinal_t ord) {
2512
3.05M
    if (!need_to_read()) {
2513
4.56k
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2514
4.56k
        return Status::OK();
2515
4.56k
    }
2516
2517
18.4E
    LOG_IF(INFO, config::enable_segment_prefetch_verbose_log) << fmt::format(
2518
18.4E
            "[verbose] FileColumnIterator::seek_to_ordinal seek to ordinal {}, enable_prefetch={}",
2519
18.4E
            ord, _enable_prefetch);
2520
3.04M
    if (_enable_prefetch) {
2521
0
        _trigger_prefetch_if_eligible(ord);
2522
0
    }
2523
2524
    // if current page contains this row, we don't need to seek
2525
3.04M
    if (!_page || !_page.contains(ord) || !_page_iter.valid()) {
2526
1.47M
        RETURN_IF_ERROR(_reader->seek_at_or_before(ord, &_page_iter, _opts));
2527
1.47M
        RETURN_IF_ERROR(_read_data_page(_page_iter));
2528
1.47M
    }
2529
3.04M
    RETURN_IF_ERROR(_seek_to_pos_in_page(&_page, ord - _page.first_ordinal));
2530
3.04M
    _current_ordinal = ord;
2531
3.04M
    return Status::OK();
2532
3.04M
}
2533
2534
0
Status FileColumnIterator::seek_to_page_start() {
2535
0
    return seek_to_ordinal(_page.first_ordinal);
2536
0
}
2537
2538
3.09M
Status FileColumnIterator::_seek_to_pos_in_page(ParsedPage* page, ordinal_t offset_in_page) const {
2539
3.09M
    if (page->offset_in_page == offset_in_page) {
2540
        // fast path, do nothing
2541
1.72M
        return Status::OK();
2542
1.72M
    }
2543
2544
1.37M
    ordinal_t pos_in_data = offset_in_page;
2545
1.37M
    if (_page.has_null) {
2546
114k
        ordinal_t offset_in_data = 0;
2547
114k
        ordinal_t skips = offset_in_page;
2548
2549
114k
        if (offset_in_page > page->offset_in_page) {
2550
            // forward, reuse null bitmap
2551
75.7k
            skips = offset_in_page - page->offset_in_page;
2552
75.7k
            offset_in_data = page->data_decoder->current_index();
2553
75.7k
        } else {
2554
            // rewind null bitmap, and
2555
39.1k
            page->null_decoder = RleDecoder<bool>((const uint8_t*)page->null_bitmap.data,
2556
39.1k
                                                  cast_set<int>(page->null_bitmap.size), 1);
2557
39.1k
        }
2558
2559
114k
        auto skip_nulls = page->null_decoder.Skip(skips);
2560
114k
        pos_in_data = offset_in_data + skips - skip_nulls;
2561
114k
    }
2562
2563
1.37M
    RETURN_IF_ERROR(page->data_decoder->seek_to_position_in_page(pos_in_data));
2564
1.37M
    page->offset_in_page = offset_in_page;
2565
1.37M
    return Status::OK();
2566
1.37M
}
2567
2568
10.8k
Status FileColumnIterator::next_batch_of_zone_map(size_t* n, MutableColumnPtr& dst) {
2569
10.8k
    return _reader->next_batch_of_zone_map(n, dst);
2570
10.8k
}
2571
2572
2.27M
Status FileColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
2573
2.27M
    if (!need_to_read()) {
2574
4.57k
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2575
4.57k
        _convert_to_place_holder_column(dst, *n);
2576
4.57k
        return Status::OK();
2577
4.57k
    }
2578
2579
2.27M
    _recovery_from_place_holder_column(dst);
2580
2581
2.27M
    if (read_null_map_only()) {
2582
2.96k
        DLOG(INFO) << "File column iterator column " << _column_name
2583
2.96k
                   << " in NULL_MAP_ONLY mode, reading only null map.";
2584
2.96k
        DORIS_CHECK(is_column_nullable(*dst));
2585
2.96k
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
2586
2.96k
        auto& null_map_data = nullable_col.get_null_map_data();
2587
2588
2.96k
        size_t remaining = *n;
2589
2.96k
        *has_null = false;
2590
5.96k
        while (remaining > 0) {
2591
3.00k
            if (!_page.has_remaining()) {
2592
48
                bool eos = false;
2593
48
                RETURN_IF_ERROR(_load_next_page(&eos));
2594
48
                if (eos) {
2595
0
                    break;
2596
0
                }
2597
48
            }
2598
2599
3.00k
            size_t nrows_in_page = std::min(remaining, _page.remaining());
2600
3.00k
            size_t nrows_to_read = nrows_in_page;
2601
3.00k
            if (_page.has_null) {
2602
217k
                while (nrows_to_read > 0) {
2603
214k
                    bool is_null = false;
2604
214k
                    size_t this_run = _page.null_decoder.GetNextRun(&is_null, nrows_to_read);
2605
214k
                    const size_t cur_size = null_map_data.size();
2606
214k
                    null_map_data.resize(cur_size + this_run);
2607
214k
                    memset(null_map_data.data() + cur_size, is_null ? 1 : 0, this_run);
2608
214k
                    if (is_null) {
2609
107k
                        *has_null = true;
2610
107k
                    }
2611
214k
                    nrows_to_read -= this_run;
2612
214k
                    _page.offset_in_page += this_run;
2613
214k
                    _current_ordinal += this_run;
2614
214k
                }
2615
2.93k
            } else {
2616
76
                const size_t cur_size = null_map_data.size();
2617
76
                null_map_data.resize(cur_size + nrows_to_read);
2618
76
                memset(null_map_data.data() + cur_size, 0, nrows_to_read);
2619
76
                _page.offset_in_page += nrows_to_read;
2620
76
                _current_ordinal += nrows_to_read;
2621
76
            }
2622
3.00k
            remaining -= nrows_in_page;
2623
3.00k
        }
2624
2.96k
        *n -= remaining;
2625
2.96k
        nullable_col.get_nested_column().insert_many_defaults(*n);
2626
2.96k
        return Status::OK();
2627
2.96k
    }
2628
2629
2.27M
    size_t curr_size = dst->byte_size();
2630
2.27M
    dst->reserve(*n);
2631
2.27M
    size_t remaining = *n;
2632
2.27M
    *has_null = false;
2633
4.59M
    while (remaining > 0) {
2634
2.32M
        if (!_page.has_remaining()) {
2635
51.6k
            bool eos = false;
2636
51.6k
            RETURN_IF_ERROR(_load_next_page(&eos));
2637
51.6k
            if (eos) {
2638
0
                break;
2639
0
            }
2640
51.6k
        }
2641
2642
        // number of rows to be read from this page
2643
2.32M
        size_t nrows_in_page = std::min(remaining, _page.remaining());
2644
2.32M
        size_t nrows_to_read = nrows_in_page;
2645
2.32M
        if (_page.has_null) {
2646
928k
            while (nrows_to_read > 0) {
2647
731k
                bool is_null = false;
2648
731k
                size_t this_run = _page.null_decoder.GetNextRun(&is_null, nrows_to_read);
2649
                // we use num_rows only for CHECK
2650
731k
                size_t num_rows = this_run;
2651
731k
                if (!is_null) {
2652
392k
                    RETURN_IF_ERROR(_page.data_decoder->next_batch(&num_rows, dst));
2653
392k
                    DCHECK_EQ(this_run, num_rows);
2654
392k
                } else {
2655
338k
                    *has_null = true;
2656
338k
                    auto* null_col = check_and_get_column<ColumnNullable>(dst.get());
2657
338k
                    if (null_col != nullptr) {
2658
338k
                        null_col->insert_many_defaults(this_run);
2659
18.4E
                    } else {
2660
18.4E
                        return Status::InternalError("unexpected column type in column reader");
2661
18.4E
                    }
2662
338k
                }
2663
2664
731k
                nrows_to_read -= this_run;
2665
731k
                _page.offset_in_page += this_run;
2666
731k
                _current_ordinal += this_run;
2667
731k
            }
2668
2.12M
        } else {
2669
2.12M
            RETURN_IF_ERROR(_page.data_decoder->next_batch(&nrows_to_read, dst));
2670
2.12M
            DCHECK_EQ(nrows_to_read, nrows_in_page);
2671
2672
2.12M
            _page.offset_in_page += nrows_to_read;
2673
2.12M
            _current_ordinal += nrows_to_read;
2674
2.12M
        }
2675
2.32M
        remaining -= nrows_in_page;
2676
2.32M
    }
2677
2.27M
    *n -= remaining;
2678
2.27M
    _opts.stats->bytes_read += (dst->byte_size() - curr_size) + BitmapSize(*n);
2679
2680
#ifdef BE_TEST
2681
    _reader->check_data_by_zone_map_for_test(dst);
2682
#endif
2683
2.27M
    return Status::OK();
2684
2.27M
}
2685
2686
Status FileColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
2687
728k
                                          MutableColumnPtr& dst) {
2688
728k
    if (!need_to_read()) {
2689
0
        DLOG(INFO) << "File column iterator column " << _column_name << " skip reading.";
2690
0
        _convert_to_place_holder_column(dst, count);
2691
0
        return Status::OK();
2692
0
    }
2693
2694
728k
    _recovery_from_place_holder_column(dst);
2695
2696
728k
    if (read_null_map_only()) {
2697
22
        DLOG(INFO) << "File column iterator column " << _column_name
2698
22
                   << " in NULL_MAP_ONLY mode, reading only null map by rowids.";
2699
2700
22
        DORIS_CHECK(is_column_nullable(*dst));
2701
22
        auto& nullable_col = assert_cast<ColumnNullable&>(*dst);
2702
22
        auto& null_map_data = nullable_col.get_null_map_data();
2703
22
        const size_t base_size = null_map_data.size();
2704
22
        null_map_data.resize(base_size + count);
2705
2706
22
        size_t remaining = count;
2707
22
        size_t total_read_count = 0;
2708
22
        size_t nrows_to_read = 0;
2709
45
        while (remaining > 0) {
2710
23
            RETURN_IF_ERROR(seek_to_ordinal(rowids[total_read_count]));
2711
2712
23
            nrows_to_read = std::min(remaining, _page.remaining());
2713
2714
23
            if (_page.has_null) {
2715
5
                size_t already_read = 0;
2716
10
                while ((nrows_to_read - already_read) > 0) {
2717
5
                    bool is_null = false;
2718
5
                    size_t this_run = std::min(nrows_to_read - already_read, _page.remaining());
2719
5
                    if (UNLIKELY(this_run == 0)) {
2720
0
                        break;
2721
0
                    }
2722
5
                    this_run = _page.null_decoder.GetNextRun(&is_null, this_run);
2723
2724
5
                    size_t offset = total_read_count + already_read;
2725
5
                    size_t this_read_count = 0;
2726
5
                    rowid_t current_ordinal_in_page =
2727
5
                            cast_set<uint32_t>(_page.offset_in_page + _page.first_ordinal);
2728
10
                    for (size_t i = 0; i < this_run; ++i) {
2729
5
                        if (rowids[offset + i] - current_ordinal_in_page >= this_run) {
2730
0
                            break;
2731
0
                        }
2732
5
                        this_read_count++;
2733
5
                    }
2734
2735
5
                    if (this_read_count > 0) {
2736
5
                        memset(null_map_data.data() + base_size + offset, is_null ? 1 : 0,
2737
5
                               this_read_count);
2738
5
                    }
2739
2740
5
                    already_read += this_read_count;
2741
5
                    _page.offset_in_page += this_run;
2742
5
                }
2743
2744
5
                nrows_to_read = already_read;
2745
5
                total_read_count += nrows_to_read;
2746
5
                remaining -= nrows_to_read;
2747
18
            } else {
2748
18
                rowid_t current_ordinal_in_page =
2749
18
                        cast_set<uint32_t>(_page.offset_in_page + _page.first_ordinal);
2750
18
                size_t rows_in_current_page = 0;
2751
36
                for (size_t i = 0; i < nrows_to_read; ++i) {
2752
19
                    if (rowids[total_read_count + i] - current_ordinal_in_page >= nrows_to_read) {
2753
1
                        break;
2754
1
                    }
2755
18
                    ++rows_in_current_page;
2756
18
                }
2757
18
                DCHECK_GT(rows_in_current_page, 0);
2758
18
                memset(null_map_data.data() + base_size + total_read_count, 0,
2759
18
                       rows_in_current_page);
2760
18
                _page.offset_in_page += rows_in_current_page;
2761
18
                total_read_count += rows_in_current_page;
2762
18
                remaining -= rows_in_current_page;
2763
18
            }
2764
23
        }
2765
2766
22
        null_map_data.resize(base_size + total_read_count);
2767
22
        nullable_col.get_nested_column().insert_many_defaults(total_read_count);
2768
22
        return Status::OK();
2769
22
    }
2770
2771
728k
    size_t remaining = count;
2772
728k
    size_t total_read_count = 0;
2773
728k
    size_t nrows_to_read = 0;
2774
1.48M
    while (remaining > 0) {
2775
757k
        RETURN_IF_ERROR(seek_to_ordinal(rowids[total_read_count]));
2776
2777
        // number of rows to be read from this page
2778
757k
        nrows_to_read = std::min(remaining, _page.remaining());
2779
2780
757k
        if (_page.has_null) {
2781
66.4k
            size_t already_read = 0;
2782
4.39M
            while ((nrows_to_read - already_read) > 0) {
2783
4.32M
                bool is_null = false;
2784
4.32M
                size_t this_run = std::min(nrows_to_read - already_read, _page.remaining());
2785
4.32M
                if (UNLIKELY(this_run == 0)) {
2786
190
                    break;
2787
190
                }
2788
4.32M
                this_run = _page.null_decoder.GetNextRun(&is_null, this_run);
2789
4.32M
                size_t offset = total_read_count + already_read;
2790
4.32M
                size_t this_read_count = 0;
2791
4.32M
                rowid_t current_ordinal_in_page =
2792
4.32M
                        cast_set<uint32_t>(_page.offset_in_page + _page.first_ordinal);
2793
20.8M
                for (size_t i = 0; i < this_run; ++i) {
2794
19.6M
                    if (rowids[offset + i] - current_ordinal_in_page >= this_run) {
2795
3.08M
                        break;
2796
3.08M
                    }
2797
16.5M
                    this_read_count++;
2798
16.5M
                }
2799
2800
4.32M
                auto origin_index = _page.data_decoder->current_index();
2801
4.32M
                if (this_read_count > 0) {
2802
1.25M
                    if (is_null) {
2803
655k
                        auto* null_col = check_and_get_column<ColumnNullable>(dst.get());
2804
655k
                        if (UNLIKELY(null_col == nullptr)) {
2805
0
                            return Status::InternalError("unexpected column type in column reader");
2806
0
                        }
2807
2808
655k
                        null_col->insert_many_defaults(this_read_count);
2809
655k
                    } else {
2810
601k
                        size_t read_count = this_read_count;
2811
2812
                        // ordinal in nullable columns' data buffer maybe be not continuously(the data doesn't contain null value),
2813
                        // so we need use `page_start_off_in_decoder` to calculate the actual offset in `data_decoder`
2814
601k
                        size_t page_start_off_in_decoder =
2815
601k
                                _page.first_ordinal + _page.offset_in_page - origin_index;
2816
601k
                        RETURN_IF_ERROR(_page.data_decoder->read_by_rowids(
2817
601k
                                &rowids[offset], page_start_off_in_decoder, &read_count, dst));
2818
601k
                        DCHECK_EQ(read_count, this_read_count);
2819
601k
                    }
2820
1.25M
                }
2821
2822
4.32M
                if (!is_null) {
2823
3.65M
                    RETURN_IF_ERROR(
2824
3.65M
                            _page.data_decoder->seek_to_position_in_page(origin_index + this_run));
2825
3.65M
                }
2826
2827
4.32M
                already_read += this_read_count;
2828
4.32M
                _page.offset_in_page += this_run;
2829
4.32M
                DCHECK(_page.offset_in_page <= _page.num_rows);
2830
4.32M
            }
2831
2832
66.4k
            nrows_to_read = already_read;
2833
66.4k
            total_read_count += nrows_to_read;
2834
66.4k
            remaining -= nrows_to_read;
2835
691k
        } else {
2836
691k
            RETURN_IF_ERROR(_page.data_decoder->read_by_rowids(
2837
691k
                    &rowids[total_read_count], _page.first_ordinal, &nrows_to_read, dst));
2838
691k
            total_read_count += nrows_to_read;
2839
691k
            remaining -= nrows_to_read;
2840
691k
        }
2841
757k
    }
2842
728k
    return Status::OK();
2843
728k
}
2844
2845
51.6k
Status FileColumnIterator::_load_next_page(bool* eos) {
2846
51.6k
    _page_iter.next();
2847
51.6k
    if (!_page_iter.valid()) {
2848
0
        *eos = true;
2849
0
        return Status::OK();
2850
0
    }
2851
2852
51.6k
    RETURN_IF_ERROR(_read_data_page(_page_iter));
2853
51.6k
    RETURN_IF_ERROR(_seek_to_pos_in_page(&_page, 0));
2854
51.6k
    *eos = false;
2855
51.6k
    return Status::OK();
2856
51.6k
}
2857
2858
1.52M
Status FileColumnIterator::_read_data_page(const OrdinalPageIndexIterator& iter) {
2859
1.52M
    PageHandle handle;
2860
1.52M
    Slice page_body;
2861
1.52M
    PageFooterPB footer;
2862
1.52M
    _opts.type = DATA_PAGE;
2863
1.52M
    PageDecoderOptions decoder_opts;
2864
1.52M
    decoder_opts.only_read_offsets = _opts.only_read_offsets;
2865
1.52M
    RETURN_IF_ERROR(
2866
1.52M
            _reader->read_page(_opts, iter.page(), &handle, &page_body, &footer, _compress_codec));
2867
    // parse data page
2868
1.52M
    auto st = ParsedPage::create(std::move(handle), page_body, footer.data_page_footer(),
2869
1.52M
                                 _reader->encoding_info(), iter.page(), iter.page_index(), &_page,
2870
1.52M
                                 decoder_opts);
2871
1.52M
    if (!st.ok()) {
2872
0
        LOG(WARNING) << "failed to create ParsedPage, file=" << _opts.file_reader->path().native()
2873
0
                     << ", page_offset=" << iter.page().offset << ", page_size=" << iter.page().size
2874
0
                     << ", page_index=" << iter.page_index() << ", error=" << st;
2875
0
        return st;
2876
0
    }
2877
2878
    // dictionary page is read when the first data page that uses it is read,
2879
    // this is to optimize the memory usage: when there is no query on one column, we could
2880
    // release the memory of dictionary page.
2881
    // note that concurrent iterators for the same column won't repeatedly read dictionary page
2882
    // because of page cache.
2883
1.52M
    if (_reader->encoding_info()->encoding() == DICT_ENCODING) {
2884
390k
        auto dict_page_decoder = reinterpret_cast<BinaryDictPageDecoder*>(_page.data_decoder.get());
2885
390k
        if (dict_page_decoder->is_dict_encoding()) {
2886
373k
            if (_dict_decoder == nullptr) {
2887
364k
                RETURN_IF_ERROR(_read_dict_data());
2888
364k
                CHECK_NOTNULL(_dict_decoder);
2889
364k
            }
2890
2891
373k
            dict_page_decoder->set_dict_decoder(cast_set<uint32_t>(_dict_decoder->count()),
2892
373k
                                                _dict_word_info.get());
2893
373k
        }
2894
390k
    }
2895
1.52M
    return Status::OK();
2896
1.52M
}
2897
2898
370k
Status FileColumnIterator::_read_dict_data() {
2899
370k
    CHECK_EQ(_reader->encoding_info()->encoding(), DICT_ENCODING);
2900
    // read dictionary page
2901
370k
    Slice dict_data;
2902
370k
    PageFooterPB dict_footer;
2903
370k
    _opts.type = INDEX_PAGE;
2904
2905
370k
    RETURN_IF_ERROR(_reader->read_page(_opts, _reader->get_dict_page_pointer(), &_dict_page_handle,
2906
370k
                                       &dict_data, &dict_footer, _compress_codec));
2907
370k
    const EncodingInfo* encoding_info;
2908
    // The dict pool stores strings of the outer column's type. Using the
2909
    // outer type (CHAR vs VARCHAR/STRING) lets the EncodingInfo pick a
2910
    // CHAR-strip pre-decoder so the cached dict page is already unpadded.
2911
370k
    RETURN_IF_ERROR(EncodingInfo::get(_reader->get_meta_type(),
2912
370k
                                      dict_footer.dict_page_footer().encoding(), &encoding_info));
2913
370k
    RETURN_IF_ERROR(encoding_info->create_page_decoder(dict_data, {}, _dict_decoder));
2914
370k
    RETURN_IF_ERROR(_dict_decoder->init());
2915
2916
370k
    _dict_word_info.reset(new StringRef[_dict_decoder->count()]);
2917
370k
    RETURN_IF_ERROR(_dict_decoder->get_dict_word_info(_dict_word_info.get()));
2918
370k
    return Status::OK();
2919
370k
}
2920
2921
Status FileColumnIterator::get_row_ranges_by_zone_map(
2922
        const AndBlockColumnPredicate* col_predicates,
2923
        const std::vector<std::shared_ptr<const ColumnPredicate>>* delete_predicates,
2924
100k
        RowRanges* row_ranges) {
2925
100k
    if (_reader->has_zone_map()) {
2926
100k
        RETURN_IF_ERROR(_reader->get_row_ranges_by_zone_map(col_predicates, delete_predicates,
2927
100k
                                                            row_ranges, _opts));
2928
100k
    }
2929
100k
    return Status::OK();
2930
100k
}
2931
2932
Status FileColumnIterator::get_row_ranges_by_bloom_filter(
2933
101k
        const AndBlockColumnPredicate* col_predicates, RowRanges* row_ranges) {
2934
101k
    if ((col_predicates->can_do_bloom_filter(false) && _reader->has_bloom_filter_index(false)) ||
2935
101k
        (col_predicates->can_do_bloom_filter(true) && _reader->has_bloom_filter_index(true))) {
2936
114
        RETURN_IF_ERROR(_reader->get_row_ranges_by_bloom_filter(col_predicates, row_ranges, _opts));
2937
114
    }
2938
101k
    return Status::OK();
2939
101k
}
2940
2941
Status FileColumnIterator::get_row_ranges_by_dict(const AndBlockColumnPredicate* col_predicates,
2942
103k
                                                  RowRanges* row_ranges) {
2943
103k
    if (!_is_all_dict_encoding) {
2944
92.5k
        return Status::OK();
2945
92.5k
    }
2946
2947
10.5k
    if (!_dict_decoder) {
2948
5.79k
        RETURN_IF_ERROR(_read_dict_data());
2949
5.79k
        CHECK_NOTNULL(_dict_decoder);
2950
5.79k
    }
2951
2952
10.5k
    if (!col_predicates->evaluate_and(_dict_word_info.get(), _dict_decoder->count())) {
2953
1.04k
        row_ranges->clear();
2954
1.04k
    }
2955
10.5k
    return Status::OK();
2956
10.5k
}
2957
2958
0
Status FileColumnIterator::init_prefetcher(const SegmentPrefetchParams& params) {
2959
0
    if (_cached_remote_file_reader =
2960
0
                std::dynamic_pointer_cast<io::CachedRemoteFileReader>(_reader->_file_reader);
2961
0
        !_cached_remote_file_reader) {
2962
0
        return Status::OK();
2963
0
    }
2964
0
    _enable_prefetch = true;
2965
0
    _prefetcher = std::make_unique<SegmentPrefetcher>(params.config);
2966
0
    RETURN_IF_ERROR(_prefetcher->init(_reader, params.read_options));
2967
0
    return Status::OK();
2968
0
}
2969
2970
void FileColumnIterator::collect_prefetchers(
2971
        std::map<PrefetcherInitMethod, std::vector<SegmentPrefetcher*>>& prefetchers,
2972
0
        PrefetcherInitMethod init_method) {
2973
0
    if (_prefetcher) {
2974
0
        prefetchers[init_method].emplace_back(_prefetcher.get());
2975
0
    }
2976
0
}
2977
2978
23.8k
Status DefaultValueColumnIterator::init(const ColumnIteratorOptions& opts) {
2979
23.8k
    _opts = opts;
2980
    // be consistent with segment v1
2981
    // if _has_default_value, we should create default column iterator for this column, and
2982
    // "NULL" is a special default value which means the default value is null.
2983
23.8k
    if (_has_default_value) {
2984
1.64k
        if (_default_value == "NULL") {
2985
723
            _default_value_field = Field::create_field<TYPE_NULL>(Null {});
2986
926
        } else {
2987
926
            if (_type == FieldType::OLAP_FIELD_TYPE_ARRAY) {
2988
8
                if (_default_value != "[]") {
2989
0
                    return Status::NotSupported("Array default {} is unsupported", _default_value);
2990
8
                } else {
2991
8
                    _default_value_field = Field::create_field<TYPE_ARRAY>(Array {});
2992
8
                    return Status::OK();
2993
8
                }
2994
918
            } else if (_type == FieldType::OLAP_FIELD_TYPE_STRUCT) {
2995
0
                return Status::NotSupported("STRUCT default type is unsupported");
2996
918
            } else if (_type == FieldType::OLAP_FIELD_TYPE_MAP) {
2997
0
                return Status::NotSupported("MAP default type is unsupported");
2998
0
            }
2999
918
            const auto t = _type;
3000
918
            const auto serde = DataTypeFactory::instance()
3001
918
                                       .create_data_type(t, _precision, _scale, _len)
3002
918
                                       ->get_serde();
3003
918
            RETURN_IF_ERROR(serde->from_fe_string(_default_value, _default_value_field));
3004
918
        }
3005
22.2k
    } else if (_is_nullable) {
3006
22.2k
        _default_value_field = Field::create_field<TYPE_NULL>(Null {});
3007
18.4E
    } else {
3008
18.4E
        return Status::InternalError(
3009
18.4E
                "invalid default value column for no default value and not nullable");
3010
18.4E
    }
3011
23.8k
    return Status::OK();
3012
23.8k
}
3013
3014
2.51k
Status DefaultValueColumnIterator::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
3015
2.51k
    *has_null = _default_value_field.is_null();
3016
2.51k
    _insert_many_default(dst, *n);
3017
2.51k
    return Status::OK();
3018
2.51k
}
3019
3020
Status DefaultValueColumnIterator::read_by_rowids(const rowid_t* rowids, const size_t count,
3021
6.97k
                                                  MutableColumnPtr& dst) {
3022
6.97k
    _insert_many_default(dst, count);
3023
6.97k
    return Status::OK();
3024
6.97k
}
3025
3026
9.49k
void DefaultValueColumnIterator::_insert_many_default(MutableColumnPtr& dst, size_t n) {
3027
9.49k
    if (_default_value_field.is_null()) {
3028
9.02k
        dst->insert_many_defaults(n);
3029
9.02k
    } else {
3030
467
        dst = dst->convert_to_predicate_column_if_dictionary();
3031
467
        dst->insert_duplicate_fields(_default_value_field, n);
3032
467
    }
3033
9.49k
}
3034
3035
5.25k
Status RowIdColumnIteratorV2::next_batch(size_t* n, MutableColumnPtr& dst, bool* has_null) {
3036
5.25k
    auto* string_column = assert_cast<ColumnString*, TypeCheckOnRelease::DISABLE>(dst.get());
3037
3038
12.1M
    for (uint32_t i = 0; i < *n; ++i) {
3039
12.1M
        uint32_t row_id = _current_rowid + i;
3040
12.1M
        GlobalRowLoacationV2 location(_version, _backend_id, _file_id, row_id);
3041
12.1M
        string_column->insert_data(reinterpret_cast<const char*>(&location),
3042
12.1M
                                   sizeof(GlobalRowLoacationV2));
3043
12.1M
    }
3044
5.25k
    _current_rowid += *n;
3045
5.25k
    return Status::OK();
3046
5.25k
}
3047
3048
Status RowIdColumnIteratorV2::read_by_rowids(const rowid_t* rowids, const size_t count,
3049
21.5k
                                             MutableColumnPtr& dst) {
3050
21.5k
    auto* string_column = assert_cast<ColumnString*>(dst.get());
3051
3052
20.6M
    for (size_t i = 0; i < count; ++i) {
3053
20.6M
        uint32_t row_id = rowids[i];
3054
20.6M
        GlobalRowLoacationV2 location(_version, _backend_id, _file_id, row_id);
3055
20.6M
        string_column->insert_data(reinterpret_cast<const char*>(&location),
3056
20.6M
                                   sizeof(GlobalRowLoacationV2));
3057
20.6M
    }
3058
21.5k
    return Status::OK();
3059
21.5k
}
3060
3061
} // namespace doris::segment_v2