Coverage Report

Created: 2026-07-08 03:15

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 <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 <memory>
26
#include <semaphore>
27
#include <utility>
28
#include <vector>
29
30
#include "common/status.h"
31
#include "core/block/block.h"
32
#include "core/data_type/data_type.h"
33
#include "storage/id_manager.h"
34
#include "storage/tablet_info.h" // DorisNodesInfo
35
36
namespace doris {
37
38
class DorisNodesInfo;
39
class RuntimeState;
40
class TupleDescriptor;
41
namespace io {
42
enum class FileCacheMissPolicy : uint8_t;
43
}
44
45
struct FileMapping;
46
struct SegKey;
47
struct SegItem;
48
struct HashOfSegKey;
49
struct IteratorKey;
50
struct IteratorItem;
51
struct HashOfIteratorKey;
52
53
2.16k
inline void fetch_callback(bthread::CountdownEvent* counter) {
54
2.16k
    Defer __defer([&] { counter->signal(); });
55
2.16k
}
56
57
template <typename T>
58
class ColumnStr;
59
using ColumnString = ColumnStr<UInt32>;
60
class MutableBlock;
61
62
// fetch rows by global rowid
63
// tablet_id/rowset_name/segment_id/ordinal_id
64
65
struct FetchOption {
66
    TupleDescriptor* desc = nullptr;
67
    RuntimeState* runtime_state = nullptr;
68
    TFetchOption t_fetch_opt;
69
};
70
71
class RowIDFetcher {
72
public:
73
0
    RowIDFetcher(FetchOption fetch_opt) : _fetch_option(std::move(fetch_opt)) {}
74
    Status init();
75
    Status fetch(const ColumnPtr& row_ids, Block* block);
76
77
private:
78
    PMultiGetRequest _init_fetch_request(const ColumnString& row_ids) const;
79
    Status _merge_rpc_results(const PMultiGetRequest& request,
80
                              const std::vector<PMultiGetResponse>& rsps,
81
                              const std::vector<brpc::Controller>& cntls, Block* output_block,
82
                              std::vector<PRowLocation>* rows_id) const;
83
84
    std::vector<std::shared_ptr<PBackendService_Stub>> _stubs;
85
    FetchOption _fetch_option;
86
};
87
88
struct RowStoreReadStruct {
89
924
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
90
    std::string& row_store_buffer;
91
    DataTypeSerDeSPtrs serdes;
92
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
93
    std::vector<std::string> default_values;
94
};
95
96
class RowIdStorageReader {
97
public:
98
    //external profile info key.
99
    static const std::string ScannersRunningTimeProfile;
100
    static const std::string InitReaderAvgTimeProfile;
101
    static const std::string GetBlockAvgTimeProfile;
102
    static const std::string FileReadLinesProfile;
103
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount;
104
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes;
105
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount;
106
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes;
107
    static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount;
108
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes;
109
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime;
110
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime;
111
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime;
112
    static const std::string TopNLazyMaterializationSecondPhaseRowsRead;
113
    static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead;
114
115
    static Status read_by_rowids(const PMultiGetRequest& request, PMultiGetResponse* response);
116
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
117
118
private:
119
    struct ExternalFetchStatistics;
120
121
    static Status read_doris_format_row(
122
            const std::shared_ptr<IdFileMap>& id_file_map,
123
            const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id,
124
            std::vector<SlotDescriptor>& slots, const TabletSchema& full_read_schema,
125
            RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats,
126
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
127
            int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map,
128
            std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map,
129
            io::FileCacheMissPolicy file_cache_miss_policy, Block& result_block);
130
131
    static Status read_batch_doris_format_row(
132
            const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map,
133
            std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, Block& result_block,
134
            OlapReaderStatistics& stats, int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms,
135
            int64_t* acquire_segments_ms, int64_t* lookup_row_data_ms,
136
            io::FileCacheMissPolicy file_cache_miss_policy);
137
138
    static Status read_batch_external_row(
139
            const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc,
140
            std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots,
141
            std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id,
142
            Block& result_block, PRuntimeProfileTree* pprofile, int64_t* init_reader_avg_ms,
143
            int64_t* get_block_avg_ms, size_t* scan_range_cnt);
144
145
    static Status read_external_row_from_file_mapping(
146
            size_t idx, const std::multimap<segment_v2::rowid_t, size_t>& row_ids,
147
            const std::shared_ptr<FileMapping>& file_mapping,
148
            const std::vector<SlotDescriptor>& slots, const TUniqueId& query_id,
149
            const std::shared_ptr<RuntimeState>& runtime_state, std::vector<Block>& scan_blocks,
150
            std::vector<std::pair<size_t, size_t>>& row_id_block_idx,
151
            std::vector<ExternalFetchStatistics>& fetch_statistics,
152
            const TFileScanRangeParams& rpc_scan_params,
153
            const std::unordered_map<std::string, int>& colname_to_slot_id,
154
            std::atomic<int>& producer_count, size_t scan_rows_count,
155
            std::counting_semaphore<>& semaphore, std::condition_variable& cv, std::mutex& mtx,
156
            TupleDescriptor& tuple_desc);
157
158
    struct ExternalFetchStatistics {
159
        int64_t init_reader_ms = 0;
160
        int64_t get_block_ms = 0;
161
        std::string file_read_bytes;
162
        std::string file_read_times;
163
    };
164
};
165
166
template <typename Func>
167
20.1k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
20.1k
    MonotonicStopWatch watch;
169
20.1k
    watch.start();
170
20.1k
    auto res = fn();
171
20.1k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
20.1k
    return res;
173
20.1k
}
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_1EEDTclfp_EET_Pl
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_2EEDTclfp_EET_Pl
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_4EEDTclfp_EET_Pl
Unexecuted instantiation: rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader14read_by_rowidsERKNS_16PMultiGetRequestEPNS_17PMultiGetResponseEE3$_5EEDTclfp_EET_Pl
rowid_fetcher.cpp:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader23read_batch_external_rowEmRKNS_17PRequestBlockDescESt10shared_ptrINS_9IdFileMapEERSt6vectorINS_14SlotDescriptorESaIS9_EES5_INS_11FileMappingEERKNS_9TUniqueIdERNS_5BlockEPNS_19PRuntimeProfileTreeEPlSM_PmE3$_0EEDTclfp_EET_SM_
Line
Count
Source
167
1.04k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
1.04k
    MonotonicStopWatch watch;
169
1.04k
    watch.start();
170
1.04k
    auto res = fn();
171
1.04k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
1.04k
    return res;
173
1.04k
}
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_
Line
Count
Source
167
3.77k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
3.77k
    MonotonicStopWatch watch;
169
3.77k
    watch.start();
170
3.77k
    auto res = fn();
171
3.77k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
3.77k
    return res;
173
3.77k
}
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_
Line
Count
Source
167
3.77k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
3.77k
    MonotonicStopWatch watch;
169
3.77k
    watch.start();
170
3.77k
    auto res = fn();
171
3.77k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
3.77k
    return res;
173
3.77k
}
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_
Line
Count
Source
167
3.77k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
3.77k
    MonotonicStopWatch watch;
169
3.77k
    watch.start();
170
3.77k
    auto res = fn();
171
3.77k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
3.77k
    return res;
173
3.77k
}
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_
Line
Count
Source
167
4.44k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
4.44k
    MonotonicStopWatch watch;
169
4.44k
    watch.start();
170
4.44k
    auto res = fn();
171
4.44k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
4.44k
    return res;
173
4.44k
}
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_0EEDTclfp_EET_SG_
Line
Count
Source
167
1.64k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
1.64k
    MonotonicStopWatch watch;
169
1.64k
    watch.start();
170
1.64k
    auto res = fn();
171
1.64k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
1.64k
    return res;
173
1.64k
}
file_scanner.cpp:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_1EEDTclfp_EET_SG_
Line
Count
Source
167
1.65k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
168
1.65k
    MonotonicStopWatch watch;
169
1.65k
    watch.start();
170
1.65k
    auto res = fn();
171
1.65k
    *cost += watch.elapsed_time() / 1000 / 1000;
172
1.65k
    return res;
173
1.65k
}
174
} // namespace doris