Coverage Report

Created: 2026-10-15 14:47

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 <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/tablet_schema.h"
35
36
namespace doris {
37
38
class RuntimeState;
39
class TQueryOptions;
40
class TupleDescriptor;
41
class ScannerScheduler;
42
namespace io {
43
enum class FileCacheMissPolicy : uint8_t;
44
}
45
46
struct FileMapping;
47
struct SegKey;
48
struct SegItem;
49
struct HashOfSegKey;
50
struct IteratorKey;
51
struct IteratorItem;
52
struct HashOfIteratorKey;
53
54
class MutableBlock;
55
56
struct RowStoreReadStruct {
57
944
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
58
    std::string& row_store_buffer;
59
    DataTypeSerDeSPtrs serdes;
60
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
61
    std::vector<std::string> default_values;
62
};
63
64
class RowIdStorageReader {
65
public:
66
    //external profile info key.
67
    static const std::string ScannersRunningTimeProfile;
68
    static const std::string InitReaderAvgTimeProfile;
69
    static const std::string GetBlockAvgTimeProfile;
70
    static const std::string FileReadLinesProfile;
71
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount;
72
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes;
73
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount;
74
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes;
75
    static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount;
76
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes;
77
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime;
78
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime;
79
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime;
80
    static const std::string TopNLazyMaterializationSecondPhaseRowsRead;
81
    static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead;
82
83
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
84
85
    // Runs read_by_rowids() for the multiget_data_v2 RPC and serializes the outcome into the
86
    // response status. The remote scan scheduler runs the RPC callback on a plain ThreadPool
87
    // worker, which has no exception boundary of its own, so a doris::Exception thrown while
88
    // reading (for example by a slot of the request whose PTypeNode this BE does not know) is
89
    // converted into an error status here instead of terminating the process.
90
    static void read_by_rowids_for_rpc(const PMultiGetRequestV2& request,
91
                                       PMultiGetResponseV2* response);
92
93
private:
94
    static bool should_use_file_scanner_v2(const TQueryOptions& query_options,
95
                                           const TFileScanRangeParams& scan_params,
96
                                           const TFileRangeDesc& range);
97
    struct ExternalFetchStatistics;
98
99
    static Status read_doris_format_row(
100
            const std::shared_ptr<IdFileMap>& id_file_map,
101
            const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id,
102
            std::vector<SlotDescriptor>& slots, const std::vector<TabletColumn>& fetch_columns,
103
            RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats,
104
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
105
            int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map,
106
            std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map,
107
            io::FileCacheMissPolicy file_cache_miss_policy, Block& result_block);
108
109
    static Status read_batch_doris_format_row(
110
            const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map,
111
            std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, Block& result_block,
112
            OlapReaderStatistics& stats, int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms,
113
            int64_t* acquire_segments_ms, int64_t* lookup_row_data_ms,
114
            io::FileCacheMissPolicy file_cache_miss_policy);
115
116
    static Status read_batch_external_row(
117
            const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc,
118
            std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots,
119
            std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id,
120
            Block& result_block, PRuntimeProfileTree* pprofile, int64_t* init_reader_avg_ms,
121
            int64_t* get_block_avg_ms, size_t* scan_range_cnt);
122
123
    static Status read_external_row_from_file_mapping(
124
            size_t idx, const std::multimap<segment_v2::rowid_t, size_t>& row_ids,
125
            const std::shared_ptr<FileMapping>& file_mapping,
126
            const std::vector<SlotDescriptor>& scan_slots, const TUniqueId& query_id,
127
            const std::shared_ptr<RuntimeState>& runtime_state, std::vector<Block>& scan_blocks,
128
            std::vector<std::pair<size_t, size_t>>& row_id_block_idx,
129
            std::vector<ExternalFetchStatistics>& fetch_statistics,
130
            const TFileScanRangeParams& rpc_scan_params,
131
            const std::unordered_map<std::string, int>& colname_to_slot_id,
132
            std::counting_semaphore<>& semaphore, TupleDescriptor& tuple_desc);
133
134
    static TFileRangeDesc build_external_fetch_range(const TFileRangeDesc& source_range);
135
136
    static TFileScanRangeParams build_external_scan_params(
137
            const TFileScanRangeParams& source_params, const TFileRangeDesc& range,
138
            const std::vector<SlotDescriptor>& scan_slots,
139
            const std::vector<uint32_t>& scan_column_idxs);
140
141
    static std::string source_column_key(const SlotDescriptor& slot, uint32_t column_idx);
142
143
    friend class RowIdStorageReaderTest;
144
145
    static Status submit_external_scan_tasks(ScannerScheduler* scheduler,
146
                                             std::counting_semaphore<>& semaphore,
147
                                             size_t task_count,
148
                                             const std::function<std::string(size_t)>& make_task_id,
149
                                             const std::function<Status(size_t)>& run_task);
150
151
    struct ExternalFetchStatistics {
152
        int64_t init_reader_ms = 0;
153
        int64_t get_block_ms = 0;
154
        std::string file_read_bytes;
155
        std::string file_read_times;
156
    };
157
};
158
159
template <typename Func>
160
15.7k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
15.7k
    MonotonicStopWatch watch;
162
15.7k
    watch.start();
163
15.7k
    auto res = fn();
164
15.7k
    *cost += watch.elapsed_time() / 1000 / 1000;
165
15.7k
    return res;
166
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
160
16
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
16
    MonotonicStopWatch watch;
162
16
    watch.start();
163
16
    auto res = fn();
164
16
    *cost += watch.elapsed_time() / 1000 / 1000;
165
16
    return res;
166
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
160
3.73k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
3.73k
    MonotonicStopWatch watch;
162
3.73k
    watch.start();
163
3.73k
    auto res = fn();
164
3.73k
    *cost += watch.elapsed_time() / 1000 / 1000;
165
3.73k
    return res;
166
3.73k
}
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
160
3.73k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
3.73k
    MonotonicStopWatch watch;
162
3.73k
    watch.start();
163
3.73k
    auto res = fn();
164
3.73k
    *cost += watch.elapsed_time() / 1000 / 1000;
165
3.73k
    return res;
166
3.73k
}
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
160
3.73k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
3.73k
    MonotonicStopWatch watch;
162
3.73k
    watch.start();
163
3.73k
    auto res = fn();
164
3.73k
    *cost += watch.elapsed_time() / 1000 / 1000;
165
3.73k
    return res;
166
3.73k
}
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
160
4.44k
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
4.44k
    MonotonicStopWatch watch;
162
4.44k
    watch.start();
163
4.44k
    auto res = fn();
164
4.44k
    *cost += watch.elapsed_time() / 1000 / 1000;
165
4.44k
    return res;
166
4.44k
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_0EEDTclfp_EET_SG_
Line
Count
Source
160
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
25
    MonotonicStopWatch watch;
162
25
    watch.start();
163
25
    auto res = fn();
164
25
    *cost += watch.elapsed_time() / 1000 / 1000;
165
25
    return res;
166
25
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_1EEDTclfp_EET_SG_
Line
Count
Source
160
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
161
25
    MonotonicStopWatch watch;
162
25
    watch.start();
163
25
    auto res = fn();
164
25
    *cost += watch.elapsed_time() / 1000 / 1000;
165
25
    return res;
166
25
}
167
} // namespace doris