Coverage Report

Created: 2026-10-28 12:14

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 <map>
25
#include <memory>
26
#include <mutex>
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/tablet_schema.h"
37
38
namespace doris {
39
40
class RuntimeProfile;
41
class RuntimeState;
42
class TQueryOptions;
43
class TupleDescriptor;
44
class ScannerScheduler;
45
namespace io {
46
enum class FileCacheMissPolicy : uint8_t;
47
}
48
49
struct FileMapping;
50
struct SegKey;
51
struct SegItem;
52
struct HashOfSegKey;
53
struct IteratorKey;
54
struct IteratorItem;
55
struct HashOfIteratorKey;
56
57
class MutableBlock;
58
59
struct RowStoreReadStruct {
60
1
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
61
    std::string& row_store_buffer;
62
    DataTypeSerDeSPtrs serdes;
63
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
64
    std::vector<std::string> default_values;
65
};
66
67
class RowIdStorageReader {
68
public:
69
    //external profile info key.
70
    static const std::string ScannersRunningTimeProfile;
71
    static const std::string InitReaderAvgTimeProfile;
72
    static const std::string GetBlockAvgTimeProfile;
73
    static const std::string FileReadLinesProfile;
74
    static const std::string LanceDatasetOpenTimeProfile;
75
    static const std::string LanceRowIdTakeReadTimeProfile;
76
    static const std::string LanceArrowToDorisBlockTimeProfile;
77
    static const std::string LanceRowIdFetchTotalTimeProfile;
78
    static const std::map<std::string, TUnit::type> LanceFetchCountersProfile;
79
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount;
80
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes;
81
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount;
82
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes;
83
    static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount;
84
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes;
85
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime;
86
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime;
87
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime;
88
    static const std::string TopNLazyMaterializationSecondPhaseRowsRead;
89
    static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead;
90
91
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
92
93
    // Runs read_by_rowids() for the multiget_data_v2 RPC and serializes the outcome into the
94
    // response status. The remote scan scheduler runs the RPC callback on a plain ThreadPool
95
    // worker, which has no exception boundary of its own, so a doris::Exception thrown while
96
    // reading (for example by a slot of the request whose PTypeNode this BE does not know) is
97
    // converted into an error status here instead of terminating the process.
98
    static void read_by_rowids_for_rpc(const PMultiGetRequestV2& request,
99
                                       PMultiGetResponseV2* response);
100
101
private:
102
    static bool should_use_file_scanner_v2(const TQueryOptions& query_options,
103
                                           const TFileScanRangeParams& scan_params,
104
                                           const TFileRangeDesc& range);
105
    struct ExternalFetchStatistics;
106
107
    static Status read_doris_format_row(
108
            const std::shared_ptr<IdFileMap>& id_file_map,
109
            const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id,
110
            std::vector<SlotDescriptor>& slots, const std::vector<TabletColumn>& fetch_columns,
111
            RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats,
112
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
113
            int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map,
114
            std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map,
115
            io::FileCacheMissPolicy file_cache_miss_policy, Block& result_block);
116
117
    static Status read_batch_doris_format_row(
118
            const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map,
119
            std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, Block& result_block,
120
            OlapReaderStatistics& stats, int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms,
121
            int64_t* acquire_segments_ms, int64_t* lookup_row_data_ms,
122
            io::FileCacheMissPolicy file_cache_miss_policy);
123
124
    static Status read_batch_external_row(
125
            const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc,
126
            std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots,
127
            std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id,
128
            Block& result_block, PRuntimeProfileTree* pprofile, int64_t* init_reader_avg_ms,
129
            int64_t* get_block_avg_ms, size_t* scan_range_cnt);
130
131
    static Status read_lance_rows_by_row_ids(const TFileRangeDesc& scan_range_desc,
132
                                             const std::vector<uint64_t>& row_ids,
133
                                             const std::vector<SlotDescriptor>& slots,
134
                                             RuntimeState* runtime_state,
135
                                             RuntimeProfile* runtime_profile,
136
                                             const TFileScanRangeParams& scan_params, Block* block,
137
                                             ExternalFetchStatistics* fetch_statistics);
138
139
    static Status read_external_row_from_file_mapping(
140
            size_t idx, const std::multimap<uint64_t, size_t>& row_ids,
141
            const std::shared_ptr<FileMapping>& file_mapping,
142
            const std::vector<SlotDescriptor>& scan_slots, const TUniqueId& query_id,
143
            const std::shared_ptr<RuntimeState>& runtime_state, std::vector<Block>& scan_blocks,
144
            std::vector<std::pair<size_t, size_t>>& row_id_block_idx,
145
            std::vector<ExternalFetchStatistics>& fetch_statistics,
146
            const TFileScanRangeParams& rpc_scan_params,
147
            const std::unordered_map<std::string, int>& colname_to_slot_id,
148
            std::counting_semaphore<>& semaphore, TupleDescriptor& tuple_desc);
149
150
    static TFileRangeDesc build_external_fetch_range(const TFileRangeDesc& source_range);
151
152
    static TFileScanRangeParams build_external_scan_params(
153
            const TFileScanRangeParams& source_params, const TFileRangeDesc& range,
154
            const std::vector<SlotDescriptor>& scan_slots,
155
            const std::vector<uint32_t>& scan_column_idxs);
156
157
    static std::string source_column_key(const SlotDescriptor& slot, uint32_t column_idx);
158
159
    friend class RowIdStorageReaderTest;
160
161
    static Status submit_external_scan_tasks(ScannerScheduler* scheduler,
162
                                             std::counting_semaphore<>& semaphore,
163
                                             size_t task_count,
164
                                             const std::function<std::string(size_t)>& make_task_id,
165
                                             const std::function<Status(size_t)>& run_task);
166
167
    // Reports InitReaderAvgTime and GetBlockAvgTime of one request block: the mean reader-init
168
    // and block-read times over its scan ranges, e.g. 20ms and 200ms for two ranges that took
169
    // 10/100 ms and 30/300 ms. Both outputs are overwritten rather than accumulated, because an
170
    // RPC that fetches two lazily materialized tables reads its two request blocks into the same
171
    // caller variables.
172
    static void add_external_fetch_avg_time_profile(
173
            const std::vector<ExternalFetchStatistics>& fetch_statistics,
174
            RuntimeProfile* runtime_profile, int64_t* init_reader_avg_ms,
175
            int64_t* get_block_avg_ms);
176
177
    struct ExternalFetchStatistics {
178
        int64_t init_reader_ms = 0;
179
        int64_t get_block_ms = 0;
180
        std::map<std::string, int64_t> lance_fetch_times_ns;
181
        std::map<std::string, int64_t> lance_fetch_counters;
182
        std::string file_read_bytes;
183
        std::string file_read_times;
184
    };
185
};
186
187
template <typename Func>
188
52
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
189
52
    MonotonicStopWatch watch;
190
52
    watch.start();
191
52
    auto res = fn();
192
52
    *cost += watch.elapsed_time() / 1000 / 1000;
193
52
    return res;
194
52
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_0EEDTclfp_EET_SG_
Line
Count
Source
188
26
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
189
26
    MonotonicStopWatch watch;
190
26
    watch.start();
191
26
    auto res = fn();
192
26
    *cost += watch.elapsed_time() / 1000 / 1000;
193
26
    return res;
194
26
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_1EEDTclfp_EET_SG_
Line
Count
Source
188
26
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
189
26
    MonotonicStopWatch watch;
190
26
    watch.start();
191
26
    auto res = fn();
192
26
    *cost += watch.elapsed_time() / 1000 / 1000;
193
26
    return res;
194
26
}
Unexecuted instantiation: unity_8_cxx.cxx:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader26read_lance_rows_by_row_idsERKNS_14TFileRangeDescERKSt6vectorImSaImEERKS5_INS_14SlotDescriptorESaISA_EEPNS_12RuntimeStateEPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsEPNS_5BlockEPNS1_23ExternalFetchStatisticsEE3$_0EEDTclfp_EET_Pl
Unexecuted instantiation: unity_8_cxx.cxx:_ZN5doris15scope_timer_runIZNS_18RowIdStorageReader26read_lance_rows_by_row_idsERKNS_14TFileRangeDescERKSt6vectorImSaImEERKS5_INS_14SlotDescriptorESaISA_EEPNS_12RuntimeStateEPNS_14RuntimeProfileERKNS_20TFileScanRangeParamsEPNS_5BlockEPNS1_23ExternalFetchStatisticsEE3$_1EEDTclfp_EET_Pl
Unexecuted instantiation: 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_
Unexecuted instantiation: 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_
Unexecuted instantiation: 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_
Unexecuted instantiation: 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_
Unexecuted instantiation: 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_
195
} // namespace doris