Coverage Report

Created: 2026-10-17 09:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exec/rowid_fetcher.h
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
#pragma once
19
20
#include <gen_cpp/internal_service.pb.h>
21
22
#include <condition_variable>
23
#include <functional>
24
#include <memory>
25
#include <mutex>
26
#include <semaphore>
27
#include <unordered_map>
28
#include <unordered_set>
29
#include <utility>
30
#include <vector>
31
32
#include "common/status.h"
33
#include "core/block/block.h"
34
#include "core/data_type/data_type.h"
35
#include "storage/id_manager.h"
36
#include "storage/tablet/tablet_schema.h"
37
38
namespace doris {
39
40
class RuntimeState;
41
class TQueryOptions;
42
class TupleDescriptor;
43
class ScannerScheduler;
44
namespace io {
45
enum class FileCacheMissPolicy : uint8_t;
46
}
47
48
struct FileMapping;
49
struct SegKey;
50
struct SegItem;
51
struct HashOfSegKey;
52
struct IteratorKey;
53
struct IteratorItem;
54
struct HashOfIteratorKey;
55
56
class MutableBlock;
57
58
struct RowStoreReadStruct {
59
944
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
60
    std::string& row_store_buffer;
61
    DataTypeSerDeSPtrs serdes;
62
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
63
    std::vector<std::string> default_values;
64
    // Slots the JSONB decode fills; empty means every slot. VERSION/COMMIT_TSO are left out, see
65
    // row_store_value_may_be_stale().
66
    std::unordered_set<int> include_col_uids;
67
    // False when every slot is such a hidden column, so the JSONB serves nothing.
68
    bool decode_row_store = true;
69
};
70
71
class RowIdStorageReader {
72
public:
73
    //external profile info key.
74
    static const std::string ScannersRunningTimeProfile;
75
    static const std::string InitReaderAvgTimeProfile;
76
    static const std::string GetBlockAvgTimeProfile;
77
    static const std::string FileReadLinesProfile;
78
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount;
79
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes;
80
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount;
81
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes;
82
    static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount;
83
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes;
84
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime;
85
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime;
86
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime;
87
    static const std::string TopNLazyMaterializationSecondPhaseRowsRead;
88
    static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead;
89
90
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
91
92
private:
93
    static bool should_use_file_scanner_v2(const TQueryOptions& query_options,
94
                                           const TFileScanRangeParams& scan_params,
95
                                           const TFileRangeDesc& range);
96
    struct ExternalFetchStatistics;
97
98
    static Status read_doris_format_row(
99
            const std::shared_ptr<IdFileMap>& id_file_map,
100
            const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id,
101
            std::vector<SlotDescriptor>& slots, const std::vector<TabletColumn>& fetch_columns,
102
            RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats,
103
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
104
            int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map,
105
            std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map,
106
            io::FileCacheMissPolicy file_cache_miss_policy, Block& result_block);
107
108
    static Status read_batch_doris_format_row(
109
            const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map,
110
            std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, Block& result_block,
111
            OlapReaderStatistics& stats, int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms,
112
            int64_t* acquire_segments_ms, int64_t* lookup_row_data_ms,
113
            io::FileCacheMissPolicy file_cache_miss_policy);
114
115
    static Status read_batch_external_row(
116
            const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc,
117
            std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots,
118
            std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id,
119
            Block& result_block, PRuntimeProfileTree* pprofile, int64_t* init_reader_avg_ms,
120
            int64_t* get_block_avg_ms, size_t* scan_range_cnt);
121
122
    static Status read_external_row_from_file_mapping(
123
            size_t idx, const std::multimap<segment_v2::rowid_t, size_t>& row_ids,
124
            const std::shared_ptr<FileMapping>& file_mapping,
125
            const std::vector<SlotDescriptor>& scan_slots, const TUniqueId& query_id,
126
            const std::shared_ptr<RuntimeState>& runtime_state, std::vector<Block>& scan_blocks,
127
            std::vector<std::pair<size_t, size_t>>& row_id_block_idx,
128
            std::vector<ExternalFetchStatistics>& fetch_statistics,
129
            const TFileScanRangeParams& rpc_scan_params,
130
            const std::unordered_map<std::string, int>& colname_to_slot_id,
131
            std::counting_semaphore<>& semaphore, TupleDescriptor& tuple_desc);
132
133
    static TFileRangeDesc build_external_fetch_range(const TFileRangeDesc& source_range);
134
135
    static TFileScanRangeParams build_external_scan_params(
136
            const TFileScanRangeParams& source_params, const TFileRangeDesc& range,
137
            const std::vector<SlotDescriptor>& scan_slots,
138
            const std::vector<uint32_t>& scan_column_idxs);
139
140
    static std::string source_column_key(const SlotDescriptor& slot, uint32_t column_idx);
141
142
    friend class RowIdStorageReaderTest;
143
144
    static Status submit_external_scan_tasks(ScannerScheduler* scheduler,
145
                                             std::counting_semaphore<>& semaphore,
146
                                             size_t task_count,
147
                                             const std::function<std::string(size_t)>& make_task_id,
148
                                             const std::function<Status(size_t)>& run_task);
149
150
    struct ExternalFetchStatistics {
151
        int64_t init_reader_ms = 0;
152
        int64_t get_block_ms = 0;
153
        std::string file_read_bytes;
154
        std::string file_read_times;
155
    };
156
};
157
158
template <typename Func>
159
15.7k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
15.7k
    MonotonicStopWatch watch;
161
15.7k
    watch.start();
162
15.7k
    auto res = fn();
163
15.7k
    *cost += watch.elapsed_time() / 1000 / 1000;
164
15.7k
    return res;
165
15.7k
}
unity_8_cxx.cxx:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader23read_batch_external_rowEmRKNS_17PRequestBlockDescESt10shared_ptrINS_9IdFileMapEERSt6vectorINS_14SlotDescriptorESaIS9_EES5_INS_11FileMappingEERKNS_9TUniqueIdERNS_5BlockEPNS_19PRuntimeProfileTreeEPlSM_PmE3$_0EEDTclfp_EET_SM_
Line
Count
Source
159
16
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
16
    MonotonicStopWatch watch;
161
16
    watch.start();
162
16
    auto res = fn();
163
16
    *cost += watch.elapsed_time() / 1000 / 1000;
164
16
    return res;
165
16
}
unity_8_cxx.cxx:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKSB_INS_12TabletColumnESaISK_EERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlST_ST_ST_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toISV_ESaISt4pairIKSV_SW_EEERSU_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESY_IS16_ESaIS10_IKS16_S17_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_1EEDTclfp_EET_ST_
Line
Count
Source
159
3.74k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
3.74k
    MonotonicStopWatch watch;
161
3.74k
    watch.start();
162
3.74k
    auto res = fn();
163
3.74k
    *cost += watch.elapsed_time() / 1000 / 1000;
164
3.74k
    return res;
165
3.74k
}
unity_8_cxx.cxx:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKSB_INS_12TabletColumnESaISK_EERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlST_ST_ST_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toISV_ESaISt4pairIKSV_SW_EEERSU_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESY_IS16_ESaIS10_IKS16_S17_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_2EEDTclfp_EET_ST_
Line
Count
Source
159
3.74k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
3.74k
    MonotonicStopWatch watch;
161
3.74k
    watch.start();
162
3.74k
    auto res = fn();
163
3.74k
    *cost += watch.elapsed_time() / 1000 / 1000;
164
3.74k
    return res;
165
3.74k
}
unity_8_cxx.cxx:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKSB_INS_12TabletColumnESaISK_EERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlST_ST_ST_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toISV_ESaISt4pairIKSV_SW_EEERSU_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESY_IS16_ESaIS10_IKS16_S17_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_3EEDTclfp_EET_ST_
Line
Count
Source
159
3.74k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
3.74k
    MonotonicStopWatch watch;
161
3.74k
    watch.start();
162
3.74k
    auto res = fn();
163
3.74k
    *cost += watch.elapsed_time() / 1000 / 1000;
164
3.74k
    return res;
165
3.74k
}
unity_8_cxx.cxx:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKSB_INS_12TabletColumnESaISK_EERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlST_ST_ST_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toISV_ESaISt4pairIKSV_SW_EEERSU_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESY_IS16_ESaIS10_IKS16_S17_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_4EEDTclfp_EET_ST_
Line
Count
Source
159
4.45k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
4.45k
    MonotonicStopWatch watch;
161
4.45k
    watch.start();
162
4.45k
    auto res = fn();
163
4.45k
    *cost += watch.elapsed_time() / 1000 / 1000;
164
4.45k
    return res;
165
4.45k
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_0EEDTclfp_EET_SG_
Line
Count
Source
159
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
25
    MonotonicStopWatch watch;
161
25
    watch.start();
162
25
    auto res = fn();
163
25
    *cost += watch.elapsed_time() / 1000 / 1000;
164
25
    return res;
165
25
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_1EEDTclfp_EET_SG_
Line
Count
Source
159
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
160
25
    MonotonicStopWatch watch;
161
25
    watch.start();
162
25
    auto res = fn();
163
25
    *cost += watch.elapsed_time() / 1000 / 1000;
164
25
    return res;
165
25
}
166
} // namespace doris