Coverage Report

Created: 2026-08-28 02:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/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 <brpc/controller.h>
21
#include <bthread/countdown_event.h>
22
#include <gen_cpp/DataSinks_types.h>
23
#include <gen_cpp/internal_service.pb.h>
24
25
#include <map>
26
#include <memory>
27
#include <semaphore>
28
#include <string>
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_info.h" // DorisNodesInfo
37
38
namespace doris {
39
40
class DorisNodesInfo;
41
class RuntimeProfile;
42
class RuntimeState;
43
class TupleDescriptor;
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
0
inline void fetch_callback(bthread::CountdownEvent* counter) {
57
0
    Defer __defer([&] { counter->signal(); });
58
0
}
59
60
template <typename T>
61
class ColumnStr;
62
using ColumnString = ColumnStr<UInt32>;
63
class MutableBlock;
64
65
// fetch rows by global rowid
66
// tablet_id/rowset_name/segment_id/ordinal_id
67
68
struct FetchOption {
69
    TupleDescriptor* desc = nullptr;
70
    RuntimeState* runtime_state = nullptr;
71
    TFetchOption t_fetch_opt;
72
};
73
74
class RowIDFetcher {
75
public:
76
0
    RowIDFetcher(FetchOption fetch_opt) : _fetch_option(std::move(fetch_opt)) {}
77
    Status init();
78
    Status fetch(const ColumnPtr& row_ids, Block* block);
79
80
private:
81
    PMultiGetRequest _init_fetch_request(const ColumnString& row_ids) const;
82
    Status _merge_rpc_results(const PMultiGetRequest& request,
83
                              const std::vector<PMultiGetResponse>& rsps,
84
                              const std::vector<brpc::Controller>& cntls, Block* output_block,
85
                              std::vector<PRowLocation>* rows_id) const;
86
87
    std::vector<std::shared_ptr<PBackendService_Stub>> _stubs;
88
    FetchOption _fetch_option;
89
};
90
91
struct RowStoreReadStruct {
92
0
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
93
    std::string& row_store_buffer;
94
    DataTypeSerDeSPtrs serdes;
95
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
96
    std::vector<std::string> default_values;
97
};
98
99
class RowIdStorageReader {
100
public:
101
    //external profile info key.
102
    static const std::string ScannersRunningTimeProfile;
103
    static const std::string InitReaderAvgTimeProfile;
104
    static const std::string GetBlockAvgTimeProfile;
105
    static const std::string FileReadLinesProfile;
106
    static const std::string LanceDatasetOpenTimeProfile;
107
    static const std::string LanceRowIdTakeReadTimeProfile;
108
    static const std::string LanceArrowToDorisBlockTimeProfile;
109
    static const std::string LanceRowIdFetchTotalTimeProfile;
110
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount;
111
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes;
112
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount;
113
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes;
114
    static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount;
115
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes;
116
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime;
117
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime;
118
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime;
119
    static const std::string TopNLazyMaterializationSecondPhaseRowsRead;
120
    static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead;
121
122
    static Status read_by_rowids(const PMultiGetRequest& request, PMultiGetResponse* response);
123
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
124
125
private:
126
    struct ExternalFetchStatistics;
127
128
    static Status read_doris_format_row(
129
            const std::shared_ptr<IdFileMap>& id_file_map,
130
            const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id,
131
            std::vector<SlotDescriptor>& slots, const TabletSchema& full_read_schema,
132
            RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats,
133
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
134
            int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map,
135
            std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map,
136
            io::FileCacheMissPolicy file_cache_miss_policy, Block& result_block);
137
138
    static Status read_batch_doris_format_row(
139
            const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map,
140
            std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, Block& result_block,
141
            OlapReaderStatistics& stats, int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms,
142
            int64_t* acquire_segments_ms, int64_t* lookup_row_data_ms,
143
            io::FileCacheMissPolicy file_cache_miss_policy);
144
145
    static Status read_batch_external_row(
146
            const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc,
147
            std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots,
148
            std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id,
149
            Block& result_block, PRuntimeProfileTree* pprofile, int64_t* init_reader_avg_ms,
150
            int64_t* get_block_avg_ms, size_t* scan_range_cnt);
151
152
    static Status read_lance_rows_by_row_ids(const TFileRangeDesc& scan_range_desc,
153
                                             const std::vector<uint64_t>& row_ids,
154
                                             const std::vector<SlotDescriptor>& slots,
155
                                             RuntimeState* runtime_state,
156
                                             RuntimeProfile* runtime_profile,
157
                                             const TFileScanRangeParams& scan_params, Block* block,
158
                                             ExternalFetchStatistics* fetch_statistics);
159
160
    static Status read_external_row_from_file_mapping(
161
            size_t idx, const std::multimap<uint64_t, size_t>& row_ids,
162
            const std::shared_ptr<FileMapping>& file_mapping,
163
            const std::vector<SlotDescriptor>& slots, const TUniqueId& query_id,
164
            const std::shared_ptr<RuntimeState>& runtime_state, std::vector<Block>& scan_blocks,
165
            std::vector<std::pair<size_t, size_t>>& row_id_block_idx,
166
            std::vector<ExternalFetchStatistics>& fetch_statistics,
167
            const TFileScanRangeParams& rpc_scan_params,
168
            const std::unordered_map<std::string, int>& colname_to_slot_id,
169
            TupleDescriptor& tuple_desc);
170
171
    struct ExternalFetchStatistics {
172
        int64_t init_reader_ms = 0;
173
        int64_t get_block_ms = 0;
174
        std::map<std::string, int64_t> lance_fetch_times_ns;
175
        std::string file_read_bytes;
176
        std::string file_read_times;
177
    };
178
};
179
180
template <typename Func>
181
68
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
182
68
    MonotonicStopWatch watch;
183
68
    watch.start();
184
68
    auto res = fn();
185
68
    *cost += watch.elapsed_time() / 1000 / 1000;
186
68
    return res;
187
68
}
rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_1EEDTclfp_EET_Pl
Line
Count
Source
181
6
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
182
6
    MonotonicStopWatch watch;
183
6
    watch.start();
184
6
    auto res = fn();
185
6
    *cost += watch.elapsed_time() / 1000 / 1000;
186
6
    return res;
187
6
}
rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_2EEDTclfp_EET_Pl
Line
Count
Source
181
6
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
182
6
    MonotonicStopWatch watch;
183
6
    watch.start();
184
6
    auto res = fn();
185
6
    *cost += watch.elapsed_time() / 1000 / 1000;
186
6
    return res;
187
6
}
rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_4EEDTclfp_EET_Pl
Line
Count
Source
181
6
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
182
6
    MonotonicStopWatch watch;
183
6
    watch.start();
184
6
    auto res = fn();
185
6
    *cost += watch.elapsed_time() / 1000 / 1000;
186
6
    return res;
187
6
}
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_5EEDTclfp_EET_Pl
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader26read_lance_rows_by_row_idsERKNS_14TFileRangeDescERKSt6vectorImSaImEERKS5_INS_14SlotDescriptorESaISA_EEPNS_12RuntimeStateEPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsEPNS_5BlockEPNS1_23ExternalFetchStatisticsEE3$_0EEDTclfp_EET_Pl
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader26read_lance_rows_by_row_idsERKNS_14TFileRangeDescERKSt6vectorImSaImEERKS5_INS_14SlotDescriptorESaISA_EEPNS_12RuntimeStateEPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsEPNS_5BlockEPNS1_23ExternalFetchStatisticsEE3$_1EEDTclfp_EET_Pl
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader23read_batch_external_rowEmRKNS_17PRequestBlockDescESt10shared_ptrINS_9IdFileMapEERSt6vectorINS_14SlotDescriptorESaIS9_EES5_INS_11FileMappingEERKNS_9TUniqueIdERNS_5BlockEPNS_19PRuntimeProfileTreeEPlSM_PmE3$_0EEDTclfp_EET_SM_
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_1EEDTclfp_EET_SR_
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_2EEDTclfp_EET_SR_
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_3EEDTclfp_EET_SR_
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader21read_doris_format_rowERKSt10shared_ptrINS_9IdFileMapEERKS2_INS_11FileMappingEERKSt6vectorIjSaIjEERSB_INS_14SlotDescriptorESaISG_EERKNS_12TabletSchemaERNS_18RowStoreReadStructERNS_20OlapReaderStatisticsEPlSR_SR_SR_RSt13unordered_mapINS_6SegKeyENS_7SegItemENS_12HashOfSegKeyESt8equal_toIST_ESaISt4pairIKST_SU_EEERSS_INS_11IteratorKeyENS_12IteratorItemENS_17HashOfIteratorKeyESW_IS14_ESaISY_IKS14_S15_EEENS_2io19FileCacheMissPolicyERNS_5BlockEE3$_4EEDTclfp_EET_SR_
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_0EEDTclfp_EET_SG_
Line
Count
Source
181
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
182
25
    MonotonicStopWatch watch;
183
25
    watch.start();
184
25
    auto res = fn();
185
25
    *cost += watch.elapsed_time() / 1000 / 1000;
186
25
    return res;
187
25
}
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_1EEDTclfp_EET_SG_
Line
Count
Source
181
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
182
25
    MonotonicStopWatch watch;
183
25
    watch.start();
184
25
    auto res = fn();
185
25
    *cost += watch.elapsed_time() / 1000 / 1000;
186
25
    return res;
187
25
}
188
} // namespace doris