be/src/storage/iterator/block_reader.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 <parallel_hashmap/phmap.h> |
21 | | #include <stddef.h> |
22 | | #include <sys/types.h> |
23 | | |
24 | | #include <cstdint> |
25 | | #include <utility> |
26 | | #include <vector> |
27 | | |
28 | | #include "common/config.h" |
29 | | #include "common/status.h" |
30 | | #include "core/block/block.h" |
31 | | #include "core/column/column.h" |
32 | | #include "core/data_type/data_type.h" |
33 | | #include "exprs/aggregate/aggregate_function.h" |
34 | | #include "storage/iterator/vcollect_iterator.h" |
35 | | #include "storage/rowset/rowset_reader.h" |
36 | | #include "storage/tablet/tablet_reader.h" |
37 | | #include "storage/utils.h" |
38 | | |
39 | | namespace doris { |
40 | | class ColumnPredicate; |
41 | | class RuntimeProfile; |
42 | | |
43 | | class BlockReader final : public TabletReader { |
44 | | public: |
45 | | ~BlockReader() override; |
46 | | |
47 | | // Initialize BlockReader with tablet, data version and fetch range. |
48 | | Status init(const ReaderParams& read_params) override; |
49 | | |
50 | | Status next_block_with_aggregation(Block* block, bool* eof) override; |
51 | | |
52 | 578 | std::vector<RowLocation> current_block_row_locations() { return _block_row_locations; } |
53 | | |
54 | 0 | void update_profile(RuntimeProfile* profile) override { |
55 | 0 | return _vcollect_iter.update_profile(profile); |
56 | 0 | } |
57 | | |
58 | | // Returns the configured preferred output block byte budget; 0 when adaptive is disabled. |
59 | 296k | size_t preferred_block_size_bytes() const override { |
60 | 296k | return config::enable_adaptive_batch_size ? _reader_context.preferred_block_size_bytes : 0; |
61 | 296k | } |
62 | | |
63 | | private: |
64 | | // Directly read row from rowset and pass to upper caller. No need to do aggregation. |
65 | | // This is usually used for DUPLICATE KEY tables |
66 | | Status _direct_next_block(Block* block, bool* eof); |
67 | | // For normal AGGREGATE KEY tables, read data by a merge heap. |
68 | | Status _agg_key_next_block(Block* block, bool* eof); |
69 | | // For UNIQUE KEY tables, read data by a merge heap. |
70 | | // The difference from _agg_key_next_block is that it will read the data from high version to low version, |
71 | | // to minimize the comparison time in merge heap. |
72 | | Status _unique_key_next_block(Block* block, bool* eof); |
73 | | |
74 | | Status _min_delta_next_block(Block* block, bool* eof); |
75 | | |
76 | | Status _detail_change_next_block(Block* block, bool* eof); |
77 | | |
78 | | int64_t _read_binlog_op(const IColumn& col, size_t row) const; |
79 | | |
80 | | Status _write_binlog_op(IColumn& col, int64_t op) const; |
81 | | |
82 | | uint32_t _resolve_source_column_ordinal(uint32_t ordinal, bool use_before) const; |
83 | | |
84 | | void _init_pending_row_columns(const Block& block); |
85 | | |
86 | | bool _emit_pending_row(MutableColumns& target_columns, size_t& output_row_count); |
87 | | |
88 | | Status _replace_key_next_block(Block* block, bool* eof); |
89 | | |
90 | | Status _init_collect_iter(const ReaderParams& read_params); |
91 | | |
92 | | Status _init_agg_state(const ReaderParams& read_params); |
93 | | |
94 | | Status _insert_data_normal(MutableColumns& columns); |
95 | | |
96 | | void _compare_sequence_map_and_replace(MutableColumns& columns); |
97 | | |
98 | | // Check if the accumulated output columns have reached the preferred byte budget, |
99 | | // used to limit the output block size for adaptive batch sizing. |
100 | | bool _reached_byte_budget(const MutableColumns& columns) const; |
101 | | |
102 | | void _append_agg_data(MutableColumns& columns); |
103 | | |
104 | | void _update_agg_data(MutableColumns& columns); |
105 | | |
106 | | size_t _copy_agg_data(); |
107 | | |
108 | | void _update_agg_value(MutableColumns& columns, int begin, int end, bool is_close = true); |
109 | | |
110 | | Status _append_change_row(MutableColumns& target_columns, const Block& src_block, |
111 | | size_t row_pos, int64_t output_op, bool use_before); |
112 | | |
113 | | // return false if keys of rowsets are mono ascending and disjoint |
114 | | bool _rowsets_not_mono_asc_disjoint(const ReaderParams& read_params); |
115 | | |
116 | | VCollectIterator _vcollect_iter; |
117 | | IteratorRowRef _next_row {{}, -1, false}; |
118 | | |
119 | | std::vector<AggregateFunctionPtr> _agg_functions; |
120 | | std::vector<AggregateDataPtr> _agg_places; |
121 | | |
122 | | // Read-schema ordinals of the non-key columns of AGG tables, folded |
123 | | // through the aggregate machinery. |
124 | | std::vector<uint32_t> _agg_columns_idx; |
125 | | |
126 | | std::vector<int> _agg_data_counters; |
127 | | int _last_agg_data_counter = 0; |
128 | | |
129 | | // Buffer of consecutive rows that share the same primary key, used by |
130 | | // _min_delta_next_block to fold INSERT/UPDATE/DELETE into a single net change. |
131 | | // Rows are appended as the merge iterator advances and cleared after each key group. |
132 | | MutableColumns _stored_data_columns; |
133 | | std::vector<IteratorRowRef> _stored_row_ref; |
134 | | |
135 | | std::vector<bool> _stored_has_null_tag; |
136 | | std::vector<bool> _stored_has_variable_length_tag; |
137 | | |
138 | | // One-row carry-over buffer holding the AFTER row of an UPDATE pair when the BEFORE row |
139 | | // was already emitted on the boundary of batch_max_rows(). Flushed by _emit_pending_row() |
140 | | // at the start of the next call to *_next_block. |
141 | | MutableColumns _pending_row_columns; |
142 | | bool _has_pending_row = false; |
143 | | |
144 | | phmap::flat_hash_map<const Block*, std::vector<std::pair<int, int>>> _temp_ref_map; |
145 | | |
146 | | bool _eof = false; |
147 | | |
148 | | Status (BlockReader::*_next_block_func)(Block* block, bool* eof) = nullptr; |
149 | | |
150 | | std::vector<RowLocation> _block_row_locations; |
151 | | |
152 | | ColumnPtr _delete_filter_column; |
153 | | |
154 | | bool _is_rowsets_overlapping = true; |
155 | | |
156 | | Arena _arena; |
157 | | }; |
158 | | |
159 | | } // namespace doris |