Coverage Report

Created: 2026-09-14 17:05

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
35
namespace doris {
36
37
class RuntimeState;
38
class TQueryOptions;
39
class TupleDescriptor;
40
class ScannerScheduler;
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
class MutableBlock;
54
55
struct RowStoreReadStruct {
56
0
    RowStoreReadStruct(std::string& buffer) : row_store_buffer(buffer) {};
57
    std::string& row_store_buffer;
58
    DataTypeSerDeSPtrs serdes;
59
    std::unordered_map<uint32_t, uint32_t> col_uid_to_idx;
60
    std::vector<std::string> default_values;
61
};
62
63
class RowIdStorageReader {
64
public:
65
    //external profile info key.
66
    static const std::string ScannersRunningTimeProfile;
67
    static const std::string InitReaderAvgTimeProfile;
68
    static const std::string GetBlockAvgTimeProfile;
69
    static const std::string FileReadLinesProfile;
70
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOCount;
71
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOBytes;
72
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOCount;
73
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOBytes;
74
    static const std::string TopNLazyMaterializationSecondPhaseSkipCacheIOCount;
75
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheBytes;
76
    static const std::string TopNLazyMaterializationSecondPhaseLocalIOTime;
77
    static const std::string TopNLazyMaterializationSecondPhaseRemoteIOTime;
78
    static const std::string TopNLazyMaterializationSecondPhaseWriteCacheIOTime;
79
    static const std::string TopNLazyMaterializationSecondPhaseRowsRead;
80
    static const std::string TopNLazyMaterializationSecondPhaseSegmentsRead;
81
82
    static Status read_by_rowids(const PMultiGetRequestV2& request, PMultiGetResponseV2* response);
83
84
private:
85
    static bool should_use_file_scanner_v2(const TQueryOptions& query_options,
86
                                           const TFileScanRangeParams& scan_params,
87
                                           const TFileRangeDesc& range);
88
    struct ExternalFetchStatistics;
89
90
    static Status read_doris_format_row(
91
            const std::shared_ptr<IdFileMap>& id_file_map,
92
            const std::shared_ptr<FileMapping>& file_mapping, const std::vector<uint32_t>& row_id,
93
            std::vector<SlotDescriptor>& slots, const TabletSchema& full_read_schema,
94
            RowStoreReadStruct& row_store_read_struct, OlapReaderStatistics& stats,
95
            int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms, int64_t* acquire_segments_ms,
96
            int64_t* lookup_row_data_ms, std::unordered_map<SegKey, SegItem, HashOfSegKey>& seg_map,
97
            std::unordered_map<IteratorKey, IteratorItem, HashOfIteratorKey>& iterator_map,
98
            io::FileCacheMissPolicy file_cache_miss_policy, Block& result_block);
99
100
    static Status read_batch_doris_format_row(
101
            const PRequestBlockDesc& request_block_desc, std::shared_ptr<IdFileMap> id_file_map,
102
            std::vector<SlotDescriptor>& slots, const TUniqueId& query_id, Block& result_block,
103
            OlapReaderStatistics& stats, int64_t* acquire_tablet_ms, int64_t* acquire_rowsets_ms,
104
            int64_t* acquire_segments_ms, int64_t* lookup_row_data_ms,
105
            io::FileCacheMissPolicy file_cache_miss_policy);
106
107
    static Status read_batch_external_row(
108
            const uint64_t workload_group_id, const PRequestBlockDesc& request_block_desc,
109
            std::shared_ptr<IdFileMap> id_file_map, std::vector<SlotDescriptor>& slots,
110
            std::shared_ptr<FileMapping> first_file_mapping, const TUniqueId& query_id,
111
            Block& result_block, PRuntimeProfileTree* pprofile, int64_t* init_reader_avg_ms,
112
            int64_t* get_block_avg_ms, size_t* scan_range_cnt);
113
114
    static Status read_external_row_from_file_mapping(
115
            size_t idx, const std::multimap<segment_v2::rowid_t, size_t>& row_ids,
116
            const std::shared_ptr<FileMapping>& file_mapping,
117
            const std::vector<SlotDescriptor>& scan_slots, const TUniqueId& query_id,
118
            const std::shared_ptr<RuntimeState>& runtime_state, std::vector<Block>& scan_blocks,
119
            std::vector<std::pair<size_t, size_t>>& row_id_block_idx,
120
            std::vector<ExternalFetchStatistics>& fetch_statistics,
121
            const TFileScanRangeParams& rpc_scan_params,
122
            const std::unordered_map<std::string, int>& colname_to_slot_id,
123
            std::counting_semaphore<>& semaphore, TupleDescriptor& tuple_desc);
124
125
    static TFileRangeDesc build_external_fetch_range(const TFileRangeDesc& source_range);
126
127
    static TFileScanRangeParams build_external_scan_params(
128
            const TFileScanRangeParams& source_params, const TFileRangeDesc& range,
129
            const std::vector<SlotDescriptor>& scan_slots,
130
            const std::vector<uint32_t>& scan_column_idxs);
131
132
    static std::string source_column_key(const SlotDescriptor& slot, uint32_t column_idx);
133
134
    friend class RowIdStorageReaderTest;
135
136
    static Status submit_external_scan_tasks(ScannerScheduler* scheduler,
137
                                             std::counting_semaphore<>& semaphore,
138
                                             size_t task_count,
139
                                             const std::function<std::string(size_t)>& make_task_id,
140
                                             const std::function<Status(size_t)>& run_task);
141
142
    struct ExternalFetchStatistics {
143
        int64_t init_reader_ms = 0;
144
        int64_t get_block_ms = 0;
145
        std::string file_read_bytes;
146
        std::string file_read_times;
147
    };
148
};
149
150
template <typename Func>
151
50
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
152
50
    MonotonicStopWatch watch;
153
50
    watch.start();
154
50
    auto res = fn();
155
50
    *cost += watch.elapsed_time() / 1000 / 1000;
156
50
    return res;
157
50
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_0EEDTclfp_EET_SG_
Line
Count
Source
151
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
152
25
    MonotonicStopWatch watch;
153
25
    watch.start();
154
25
    auto res = fn();
155
25
    *cost += watch.elapsed_time() / 1000 / 1000;
156
25
    return res;
157
25
}
unity_9_cxx.cxx:_ZN5doris15scope_timer_runIZNS_11FileScanner21read_lines_from_rangeERKNS_14TFileRangeDescERKNSt7__cxx114listIlSaIlEEEPNS_5BlockERKNS_23ExternalFileMappingInfoEPlSG_E3$_1EEDTclfp_EET_SG_
Line
Count
Source
151
25
auto scope_timer_run(Func fn, int64_t* cost) -> decltype(fn()) {
152
25
    MonotonicStopWatch watch;
153
25
    watch.start();
154
25
    auto res = fn();
155
25
    *cost += watch.elapsed_time() / 1000 / 1000;
156
25
    return res;
157
25
}
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_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: unity_8_cxx.cxx:_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: unity_8_cxx.cxx:_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: unity_8_cxx.cxx:_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_
158
} // namespace doris