be/src/exec/scan/olap_scanner.cpp
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 | | #include "exec/scan/olap_scanner.h" |
19 | | |
20 | | #include <gen_cpp/Descriptors_types.h> |
21 | | #include <gen_cpp/PlanNodes_types.h> |
22 | | #include <gen_cpp/Types_types.h> |
23 | | #include <glog/logging.h> |
24 | | #include <stdlib.h> |
25 | | #include <thrift/protocol/TDebugProtocol.h> |
26 | | |
27 | | #include <algorithm> |
28 | | #include <atomic> |
29 | | #include <iterator> |
30 | | #include <ostream> |
31 | | #include <set> |
32 | | |
33 | | #include "cloud/cloud_storage_engine.h" |
34 | | #include "cloud/cloud_tablet_hotspot.h" |
35 | | #include "cloud/config.h" |
36 | | #include "common/config.h" |
37 | | #include "common/consts.h" |
38 | | #include "common/logging.h" |
39 | | #include "common/metrics/doris_metrics.h" |
40 | | #include "core/block/block.h" |
41 | | #include "exec/common/variant_util.h" |
42 | | #include "exec/operator/olap_scan_operator.h" |
43 | | #include "exec/scan/scan_node.h" |
44 | | #include "exprs/function_filter.h" |
45 | | #include "exprs/vexpr.h" |
46 | | #include "exprs/vexpr_context.h" |
47 | | #include "io/cache/block_file_cache_profile.h" |
48 | | #include "io/io_common.h" |
49 | | #include "runtime/descriptors.h" |
50 | | #include "runtime/exec_env.h" |
51 | | #include "runtime/runtime_profile.h" |
52 | | #include "runtime/runtime_state.h" |
53 | | #include "service/backend_options.h" |
54 | | #include "storage/id_manager.h" |
55 | | #include "storage/index/inverted/inverted_index_profile.h" |
56 | | #include "storage/iterator/block_reader.h" |
57 | | #include "storage/olap_common.h" |
58 | | #include "storage/olap_tuple.h" |
59 | | #include "storage/olap_utils.h" |
60 | | #include "storage/storage_engine.h" |
61 | | #include "storage/tablet/tablet_schema.h" |
62 | | #include "util/json/path_in_data.h" |
63 | | |
64 | | namespace doris { |
65 | | #include "common/compile_check_avoid_begin.h" |
66 | | |
67 | | using ReadSource = TabletReadSource; |
68 | | |
69 | | OlapScanner::OlapScanner(ScanLocalStateBase* parent, OlapScanner::Params&& params) |
70 | 1.17M | : Scanner(params.state, parent, params.limit, params.profile), |
71 | 1.17M | _key_ranges(std::move(params.key_ranges)), |
72 | 1.17M | _tablet_reader_params({.tablet = std::move(params.tablet), |
73 | 1.17M | .tablet_schema {}, |
74 | 1.17M | .aggregation = params.aggregation, |
75 | 1.17M | .version = {0, params.version}, |
76 | 1.17M | .start_key {}, |
77 | 1.17M | .end_key {}, |
78 | 1.17M | .predicates {}, |
79 | 1.17M | .function_filters {}, |
80 | 1.17M | .delete_predicates {}, |
81 | 1.17M | .target_cast_type_for_variants {}, |
82 | 1.17M | .all_access_paths {}, |
83 | 1.17M | .predicate_access_paths {}, |
84 | 1.17M | .rs_splits {}, |
85 | 1.17M | .return_columns {}, |
86 | 1.17M | .output_columns {}, |
87 | 1.17M | .remaining_conjunct_roots {}, |
88 | 1.17M | .common_expr_ctxs_push_down {}, |
89 | 1.17M | .topn_filter_source_node_ids {}, |
90 | 1.17M | .key_group_cluster_key_idxes {}, |
91 | 1.17M | .virtual_column_exprs {}, |
92 | 1.17M | .vir_cid_to_idx_in_block {}, |
93 | 1.17M | .vir_col_idx_to_type {}, |
94 | 1.17M | .score_runtime {}, |
95 | 1.17M | .collection_statistics {}, |
96 | 1.17M | .ann_topn_runtime {}, |
97 | 1.17M | .condition_cache_digest = parent->get_condition_cache_digest()}) { |
98 | 1.17M | _tablet_reader_params.set_read_source(std::move(params.read_source), |
99 | 1.17M | _state->skip_delete_bitmap()); |
100 | 1.17M | _has_prepared = false; |
101 | 1.17M | _vector_search_params = params.state->get_vector_search_params(); |
102 | 1.17M | } |
103 | | |
104 | | static std::string read_columns_to_string(TabletSchemaSPtr tablet_schema, |
105 | 2.78k | const std::vector<uint32_t>& read_columns) { |
106 | | // avoid too long for one line, |
107 | | // it is hard to display in `show profile` stmt if one line is too long. |
108 | 2.78k | const int col_per_line = 10; |
109 | 2.78k | int i = 0; |
110 | 2.78k | std::string read_columns_string; |
111 | 2.78k | read_columns_string += "["; |
112 | 13.5k | for (auto it = read_columns.cbegin(); it != read_columns.cend(); it++) { |
113 | 10.7k | if (it != read_columns.cbegin()) { |
114 | 8.01k | read_columns_string += ", "; |
115 | 8.01k | } |
116 | 10.7k | read_columns_string += tablet_schema->columns().at(*it)->name(); |
117 | 10.7k | if (i >= col_per_line) { |
118 | 13 | read_columns_string += "\n"; |
119 | 13 | i = 0; |
120 | 10.7k | } else { |
121 | 10.7k | ++i; |
122 | 10.7k | } |
123 | 10.7k | } |
124 | 2.78k | read_columns_string += "]"; |
125 | 2.78k | return read_columns_string; |
126 | 2.78k | } |
127 | | |
128 | 1.17M | Status OlapScanner::_prepare_impl() { |
129 | 1.17M | auto* local_state = static_cast<OlapScanLocalState*>(_local_state); |
130 | 1.17M | auto& tablet = _tablet_reader_params.tablet; |
131 | 1.17M | auto& tablet_schema = _tablet_reader_params.tablet_schema; |
132 | 1.17M | DBUG_EXECUTE_IF("CloudTablet.capture_rs_readers.return.e-230", { |
133 | 1.17M | LOG_WARNING("CloudTablet.capture_rs_readers.return e-230 init") |
134 | 1.17M | .tag("tablet_id", tablet->tablet_id()); |
135 | 1.17M | return Status::Error<false>(-230, "injected error"); |
136 | 1.17M | }); |
137 | | |
138 | 1.17M | for (auto& ctx : local_state->_common_expr_ctxs_push_down) { |
139 | 21.7k | VExprContextSPtr context; |
140 | 21.7k | RETURN_IF_ERROR(ctx->clone(_state, context)); |
141 | 21.7k | _common_expr_ctxs_push_down.emplace_back(context); |
142 | 21.7k | context->prepare_ann_range_search(_vector_search_params); |
143 | 21.7k | } |
144 | | |
145 | 1.17M | for (auto pair : local_state->_slot_id_to_virtual_column_expr) { |
146 | | // Scanner will be executed in a different thread, so we need to clone the context. |
147 | 412 | VExprContextSPtr context; |
148 | 412 | RETURN_IF_ERROR(pair.second->clone(_state, context)); |
149 | 412 | _slot_id_to_virtual_column_expr[pair.first] = context; |
150 | 412 | } |
151 | | |
152 | 1.17M | _slot_id_to_index_in_block = local_state->_slot_id_to_index_in_block; |
153 | 1.17M | _slot_id_to_col_type = local_state->_slot_id_to_col_type; |
154 | 1.17M | _score_runtime = local_state->_score_runtime; |
155 | | // All scanners share the same ann_topn_runtime. |
156 | 1.17M | _ann_topn_runtime = local_state->_ann_topn_runtime; |
157 | | |
158 | | // set limit to reduce end of rowset and segment mem use |
159 | 1.17M | _tablet_reader = std::make_unique<BlockReader>(); |
160 | | // batch size is passed down to segment iterator, use _state->batch_size() |
161 | | // instead of _parent->limit(), because if _parent->limit() is a very small |
162 | | // value (e.g. select a from t where a .. and b ... limit 1), |
163 | | // it will be very slow when reading data in segment iterator |
164 | 1.17M | _tablet_reader->set_batch_size(_state->batch_size()); |
165 | | // Adaptive batch size: pass byte-budget settings to the storage reader. |
166 | | // The reader still uses batch_size() as the row ceiling. |
167 | 1.17M | _tablet_reader->set_preferred_block_size_bytes(_state->preferred_block_size_bytes()); |
168 | 1.17M | { |
169 | 1.17M | TOlapScanNode& olap_scan_node = local_state->olap_scan_node(); |
170 | | |
171 | | // Each scanner builds its own TabletSchema to avoid concurrent modification. |
172 | 1.17M | tablet_schema = std::make_shared<TabletSchema>(); |
173 | 1.17M | tablet_schema->copy_from(*tablet->tablet_schema()); |
174 | 1.17M | if (olap_scan_node.__isset.columns_desc && !olap_scan_node.columns_desc.empty() && |
175 | 1.17M | olap_scan_node.columns_desc[0].col_unique_id >= 0) { |
176 | 1.17M | tablet_schema->clear_columns(); |
177 | 18.9M | for (const auto& column_desc : olap_scan_node.columns_desc) { |
178 | 18.9M | tablet_schema->append_column(TabletColumn(column_desc)); |
179 | 18.9M | } |
180 | 1.17M | if (olap_scan_node.__isset.schema_version) { |
181 | 1.17M | tablet_schema->set_schema_version(olap_scan_node.schema_version); |
182 | 1.17M | } |
183 | 1.17M | } |
184 | 1.17M | if (olap_scan_node.__isset.indexes_desc) { |
185 | 1.17M | tablet_schema->update_indexes_from_thrift(olap_scan_node.indexes_desc); |
186 | 1.17M | } |
187 | | |
188 | 1.17M | if (_tablet_reader_params.rs_splits.empty()) { |
189 | | // Non-pipeline mode, Tablet : Scanner = 1 : 1 |
190 | | // acquire tablet rowset readers at the beginning of the scan node |
191 | | // to prevent this case: when there are lots of olap scanners to run for example 10000 |
192 | | // the rowsets maybe compacted when the last olap scanner starts |
193 | 0 | ReadSource read_source; |
194 | |
|
195 | 0 | if (config::is_cloud_mode()) { |
196 | | // FIXME(plat1ko): Avoid pointer cast |
197 | 0 | ExecEnv::GetInstance()->storage_engine().to_cloud().tablet_hotspot().count(*tablet); |
198 | 0 | } |
199 | |
|
200 | 0 | auto maybe_read_source = tablet->capture_read_source( |
201 | 0 | _tablet_reader_params.version, |
202 | 0 | { |
203 | 0 | .skip_missing_versions = _state->skip_missing_version(), |
204 | 0 | .enable_fetch_rowsets_from_peers = |
205 | 0 | config::enable_fetch_rowsets_from_peer_replicas, |
206 | 0 | .enable_prefer_cached_rowset = |
207 | 0 | config::is_cloud_mode() ? _state->enable_prefer_cached_rowset() |
208 | 0 | : false, |
209 | 0 | .query_freshness_tolerance_ms = |
210 | 0 | config::is_cloud_mode() ? _state->query_freshness_tolerance_ms() |
211 | 0 | : -1, |
212 | 0 | }); |
213 | 0 | if (!maybe_read_source) { |
214 | 0 | LOG(WARNING) << "fail to init reader. res=" << maybe_read_source.error(); |
215 | 0 | return maybe_read_source.error(); |
216 | 0 | } |
217 | | |
218 | 0 | read_source = std::move(maybe_read_source.value()); |
219 | |
|
220 | 0 | if (config::enable_mow_verbose_log && tablet->enable_unique_key_merge_on_write()) { |
221 | 0 | LOG_INFO("finish capture_rs_readers for tablet={}, query_id={}", |
222 | 0 | tablet->tablet_id(), print_id(_state->query_id())); |
223 | 0 | } |
224 | |
|
225 | 0 | if (!_state->skip_delete_predicate()) { |
226 | 0 | read_source.fill_delete_predicates(); |
227 | 0 | } |
228 | 0 | _tablet_reader_params.set_read_source(std::move(read_source)); |
229 | 0 | } |
230 | | |
231 | | // Initialize tablet_reader_params |
232 | 1.17M | RETURN_IF_ERROR(_init_tablet_reader_params( |
233 | 1.17M | local_state->_parent->cast<OlapScanOperatorX>()._slot_id_to_slot_desc, _key_ranges, |
234 | 1.17M | local_state->_slot_id_to_predicates, local_state->_push_down_functions)); |
235 | 1.17M | } |
236 | | |
237 | | // add read columns in profile |
238 | 1.17M | if (_state->enable_profile()) { |
239 | 2.78k | _profile->add_info_string("ReadColumns", |
240 | 2.78k | read_columns_to_string(tablet_schema, _return_columns)); |
241 | 2.78k | } |
242 | | |
243 | 1.17M | if (_tablet_reader_params.score_runtime) { |
244 | 14 | SCOPED_TIMER(local_state->_statistics_collect_timer); |
245 | 14 | _tablet_reader_params.collection_statistics = std::make_shared<CollectionStatistics>(); |
246 | | |
247 | 14 | io::IOContext io_ctx { |
248 | 14 | .reader_type = ReaderType::READER_QUERY, |
249 | 14 | .expiration_time = tablet->ttl_seconds(), |
250 | 14 | .query_id = &_state->query_id(), |
251 | 14 | .file_cache_stats = &_tablet_reader->mutable_stats()->file_cache_stats, |
252 | 14 | .is_inverted_index = true, |
253 | 14 | }; |
254 | | |
255 | 14 | RETURN_IF_ERROR(_tablet_reader_params.collection_statistics->collect( |
256 | 14 | _state, _tablet_reader_params.rs_splits, _tablet_reader_params.tablet_schema, |
257 | 14 | _tablet_reader_params.common_expr_ctxs_push_down, &io_ctx)); |
258 | 14 | } |
259 | | |
260 | 1.17M | _has_prepared = true; |
261 | 1.17M | return Status::OK(); |
262 | 1.17M | } |
263 | | |
264 | 1.17M | Status OlapScanner::_open_impl(RuntimeState* state) { |
265 | 1.17M | RETURN_IF_ERROR(Scanner::_open_impl(state)); |
266 | 1.17M | SCOPED_TIMER(_local_state->cast<OlapScanLocalState>()._reader_init_timer); |
267 | | |
268 | 1.17M | auto res = _tablet_reader->init(_tablet_reader_params); |
269 | 1.17M | if (!res.ok()) { |
270 | 43 | res.append("failed to initialize storage reader. tablet=" + |
271 | 43 | std::to_string(_tablet_reader_params.tablet->tablet_id()) + |
272 | 43 | ", backend=" + BackendOptions::get_localhost()); |
273 | 43 | return res; |
274 | 43 | } |
275 | | |
276 | | // Do not hold rs_splits any more to release memory. |
277 | 1.17M | _tablet_reader_params.rs_splits.clear(); |
278 | | |
279 | 1.17M | return Status::OK(); |
280 | 1.17M | } |
281 | | |
282 | | // it will be called under tablet read lock because capture rs readers need |
283 | | Status OlapScanner::_init_tablet_reader_params( |
284 | | const phmap::flat_hash_map<int, SlotDescriptor*>& slot_id_to_slot_desc, |
285 | | const std::vector<OlapScanRange*>& key_ranges, |
286 | | const phmap::flat_hash_map<int, std::vector<std::shared_ptr<ColumnPredicate>>>& |
287 | | slot_to_predicates, |
288 | 1.17M | const std::vector<FunctionFilter>& function_filters) { |
289 | | // if the table with rowset [0-x] or [0-1] [2-y], and [0-1] is empty |
290 | 1.17M | const bool single_version = _tablet_reader_params.has_single_version(); |
291 | | |
292 | 1.17M | auto* olap_local_state = static_cast<OlapScanLocalState*>(_local_state); |
293 | 1.17M | bool read_mor_as_dup = olap_local_state->olap_scan_node().__isset.read_mor_as_dup && |
294 | 1.17M | olap_local_state->olap_scan_node().read_mor_as_dup; |
295 | 1.17M | if (_state->skip_storage_engine_merge() || read_mor_as_dup) { |
296 | 42 | _tablet_reader_params.direct_mode = true; |
297 | 42 | _tablet_reader_params.aggregation = true; |
298 | 1.17M | } else { |
299 | 1.17M | auto push_down_agg_type = _local_state->get_push_down_agg_type(); |
300 | 1.17M | _tablet_reader_params.direct_mode = _tablet_reader_params.aggregation || single_version || |
301 | 1.17M | (push_down_agg_type != TPushAggOp::NONE && |
302 | 11.1k | push_down_agg_type != TPushAggOp::COUNT_ON_INDEX); |
303 | 1.17M | } |
304 | | |
305 | 1.17M | RETURN_IF_ERROR(_init_variant_columns()); |
306 | 1.17M | RETURN_IF_ERROR(_init_return_columns()); |
307 | | |
308 | 1.17M | _tablet_reader_params.reader_type = ReaderType::READER_QUERY; |
309 | 1.17M | _tablet_reader_params.push_down_agg_type_opt = _local_state->get_push_down_agg_type(); |
310 | | |
311 | | // TODO: If a new runtime filter arrives after `_conjuncts` move to `_common_expr_ctxs_push_down`, |
312 | 1.17M | if (_common_expr_ctxs_push_down.empty()) { |
313 | 1.15M | for (auto& conjunct : _conjuncts) { |
314 | 3.72k | _tablet_reader_params.remaining_conjunct_roots.emplace_back(conjunct->root()); |
315 | 3.72k | } |
316 | 1.15M | } else { |
317 | 21.6k | for (auto& ctx : _common_expr_ctxs_push_down) { |
318 | 21.6k | _tablet_reader_params.remaining_conjunct_roots.emplace_back(ctx->root()); |
319 | 21.6k | } |
320 | 18.4k | } |
321 | | |
322 | 1.17M | _tablet_reader_params.common_expr_ctxs_push_down = _common_expr_ctxs_push_down; |
323 | 1.17M | _tablet_reader_params.virtual_column_exprs = _virtual_column_exprs; |
324 | 1.17M | _tablet_reader_params.vir_cid_to_idx_in_block = _vir_cid_to_idx_in_block; |
325 | 1.17M | _tablet_reader_params.vir_col_idx_to_type = _vir_col_idx_to_type; |
326 | 1.17M | _tablet_reader_params.score_runtime = _score_runtime; |
327 | 1.17M | _tablet_reader_params.output_columns = ((OlapScanLocalState*)_local_state)->_output_column_ids; |
328 | 1.17M | _tablet_reader_params.ann_topn_runtime = _ann_topn_runtime; |
329 | 1.17M | for (const auto& ele : ((OlapScanLocalState*)_local_state)->_cast_types_for_variants) { |
330 | 1.67k | _tablet_reader_params.target_cast_type_for_variants[ele.first] = ele.second; |
331 | 1.67k | }; |
332 | 1.17M | auto& tablet_schema = _tablet_reader_params.tablet_schema; |
333 | 9.77M | for (auto& predicates : slot_to_predicates) { |
334 | 9.77M | const int sid = predicates.first; |
335 | 9.77M | DCHECK(slot_id_to_slot_desc.contains(sid)); |
336 | 9.77M | int32_t index = |
337 | 9.77M | tablet_schema->field_index(slot_id_to_slot_desc.find(sid)->second->col_name()); |
338 | 9.77M | if (index < 0) { |
339 | 0 | throw Exception( |
340 | 0 | Status::InternalError("Column {} not found in tablet schema", |
341 | 0 | slot_id_to_slot_desc.find(sid)->second->col_name())); |
342 | 0 | } |
343 | 9.77M | for (auto& predicate : predicates.second) { |
344 | 958k | _tablet_reader_params.predicates.push_back(predicate->clone(index)); |
345 | 958k | } |
346 | 9.77M | } |
347 | | |
348 | 1.17M | std::copy(function_filters.cbegin(), function_filters.cend(), |
349 | 1.17M | std::inserter(_tablet_reader_params.function_filters, |
350 | 1.17M | _tablet_reader_params.function_filters.begin())); |
351 | | |
352 | | // Merge the columns in delete predicate that not in latest schema in to current tablet schema |
353 | 1.17M | for (auto& del_pred : _tablet_reader_params.delete_predicates) { |
354 | 7.30k | tablet_schema->merge_dropped_columns(*del_pred->tablet_schema()); |
355 | 7.30k | } |
356 | | |
357 | | // Push key ranges to the tablet reader. |
358 | | // Skip the "full scan" placeholder (has_lower_bound == false) — when no key |
359 | | // predicates exist, start_key/end_key remain empty and the reader does a full scan. |
360 | 1.84M | for (auto* key_range : key_ranges) { |
361 | 1.84M | if (!key_range->has_lower_bound) { |
362 | 151k | continue; |
363 | 151k | } |
364 | | |
365 | 1.68M | _tablet_reader_params.start_key_include = key_range->begin_include; |
366 | 1.68M | _tablet_reader_params.end_key_include = key_range->end_include; |
367 | | |
368 | 1.68M | _tablet_reader_params.start_key.push_back(key_range->begin_scan_range); |
369 | 1.68M | _tablet_reader_params.end_key.push_back(key_range->end_scan_range); |
370 | 1.68M | } |
371 | | |
372 | 1.17M | _tablet_reader_params.profile = _local_state->custom_profile(); |
373 | 1.17M | _tablet_reader_params.runtime_state = _state; |
374 | | |
375 | 1.17M | _tablet_reader_params.origin_return_columns = &_return_columns; |
376 | 1.17M | _tablet_reader_params.tablet_columns_convert_to_null_set = &_tablet_columns_convert_to_null_set; |
377 | | |
378 | 1.17M | if (_tablet_reader_params.direct_mode) { |
379 | 1.16M | _tablet_reader_params.return_columns = _return_columns; |
380 | 1.16M | } else { |
381 | | // we need to fetch all key columns to do the right aggregation on storage engine side. |
382 | 43.2k | for (size_t i = 0; i < tablet_schema->num_key_columns(); ++i) { |
383 | 30.1k | _tablet_reader_params.return_columns.push_back(i); |
384 | 30.1k | } |
385 | 53.8k | for (auto index : _return_columns) { |
386 | 53.8k | if (tablet_schema->column(index).is_key()) { |
387 | 21.0k | continue; |
388 | 21.0k | } |
389 | 32.7k | _tablet_reader_params.return_columns.push_back(index); |
390 | 32.7k | } |
391 | | // expand the sequence column |
392 | 13.1k | if (tablet_schema->has_sequence_col() || tablet_schema->has_seq_map()) { |
393 | 39 | bool has_replace_col = false; |
394 | 88 | for (auto col : _return_columns) { |
395 | 88 | if (tablet_schema->column(col).aggregation() == |
396 | 88 | FieldAggregationMethod::OLAP_FIELD_AGGREGATION_REPLACE) { |
397 | 38 | has_replace_col = true; |
398 | 38 | break; |
399 | 38 | } |
400 | 88 | } |
401 | 39 | if (auto sequence_col_idx = tablet_schema->sequence_col_idx(); |
402 | 39 | has_replace_col && tablet_schema->has_sequence_col() && |
403 | 39 | std::find(_return_columns.begin(), _return_columns.end(), sequence_col_idx) == |
404 | 26 | _return_columns.end()) { |
405 | 15 | _tablet_reader_params.return_columns.push_back(sequence_col_idx); |
406 | 15 | } |
407 | 39 | if (has_replace_col) { |
408 | 38 | const auto& val_to_seq = tablet_schema->value_col_idx_to_seq_col_idx(); |
409 | 38 | std::set<uint32_t> return_seq_columns; |
410 | | |
411 | 236 | for (auto col : _tablet_reader_params.return_columns) { |
412 | | // we need to add the necessary sequence column in _return_columns, and |
413 | | // Avoid adding the same seq column twice |
414 | 236 | const auto val_iter = val_to_seq.find(col); |
415 | 236 | if (val_iter != val_to_seq.end()) { |
416 | 42 | auto seq = val_iter->second; |
417 | 42 | if (std::find(_tablet_reader_params.return_columns.begin(), |
418 | 42 | _tablet_reader_params.return_columns.end(), |
419 | 42 | seq) == _tablet_reader_params.return_columns.end()) { |
420 | 4 | return_seq_columns.insert(seq); |
421 | 4 | } |
422 | 42 | } |
423 | 236 | } |
424 | 38 | _tablet_reader_params.return_columns.insert( |
425 | 38 | std::end(_tablet_reader_params.return_columns), |
426 | 38 | std::begin(return_seq_columns), std::end(return_seq_columns)); |
427 | 38 | } |
428 | 39 | } |
429 | 13.1k | } |
430 | | |
431 | 1.17M | _tablet_reader_params.use_page_cache = _state->enable_page_cache(); |
432 | | |
433 | 1.17M | DBUG_EXECUTE_IF("NewOlapScanner::_init_tablet_reader_params.block", DBUG_BLOCK); |
434 | | |
435 | 1.17M | if (!_state->skip_storage_engine_merge()) { |
436 | 1.17M | auto* olap_scan_local_state = (OlapScanLocalState*)_local_state; |
437 | 1.17M | TOlapScanNode& olap_scan_node = olap_scan_local_state->olap_scan_node(); |
438 | | |
439 | | // Set MOR value predicate pushdown flag |
440 | 1.17M | if (olap_scan_node.__isset.enable_mor_value_predicate_pushdown && |
441 | 1.17M | olap_scan_node.enable_mor_value_predicate_pushdown) { |
442 | 25 | _tablet_reader_params.enable_mor_value_predicate_pushdown = true; |
443 | 25 | } |
444 | | |
445 | 1.17M | const bool has_key_topn = |
446 | 1.17M | olap_scan_node.__isset.sort_info && !olap_scan_node.sort_info.is_asc_order.empty(); |
447 | 1.17M | if (has_key_topn) { |
448 | 2.14k | _limit = _local_state->limit_per_scanner(); |
449 | 2.14k | } |
450 | | |
451 | 1.17M | const bool no_runtime_filters = _total_rf_num == 0; |
452 | 1.17M | const bool segment_limit_enabled = _state->enable_segment_limit_pushdown(); |
453 | 1.17M | const bool storage_no_merge = olap_scan_local_state->_storage_no_merge(); |
454 | | |
455 | 1.17M | if (_limit > 0 && no_runtime_filters && segment_limit_enabled && storage_no_merge) { |
456 | 3.91k | for (const auto& conjunct : _conjuncts) { |
457 | 0 | DORIS_CHECK(!olap_scan_local_state->_check_expr_storage_filter( |
458 | 0 | conjunct->root(), OlapScanLocalState::ExprStorageFilterCheckMode:: |
459 | 0 | HAS_SEGMENT_EVALUABLE_EXPR)); |
460 | 0 | } |
461 | 3.91k | } |
462 | | |
463 | | // Segment LIMIT has only two legal states: completely disabled, or enabled after every |
464 | | // row-filtering conjunct has become a storage predicate or SegmentIterator common expr. |
465 | 1.17M | const bool can_push_down_segment_limit = _limit > 0 && no_runtime_filters && |
466 | 1.17M | _conjuncts.empty() && segment_limit_enabled && |
467 | 1.17M | storage_no_merge; |
468 | 1.17M | if (can_push_down_segment_limit) { |
469 | 3.91k | if (has_key_topn) { |
470 | 2.04k | _tablet_reader_params.read_orderby_key = true; |
471 | 2.04k | if (!olap_scan_node.sort_info.is_asc_order[0]) { |
472 | 179 | _tablet_reader_params.read_orderby_key_reverse = true; |
473 | 179 | } |
474 | 2.04k | _tablet_reader_params.read_orderby_key_num_prefix_columns = |
475 | 2.04k | olap_scan_node.sort_info.is_asc_order.size(); |
476 | 2.04k | _tablet_reader_params.read_orderby_key_limit = _limit; |
477 | 2.04k | } else { |
478 | 1.87k | _tablet_reader_params.general_read_limit = _limit; |
479 | 1.87k | } |
480 | 3.91k | } |
481 | | |
482 | 1.17M | if (_tablet_reader_params.read_orderby_key_limit > 0 || |
483 | 1.17M | _tablet_reader_params.general_read_limit > 0) { |
484 | 3.91k | DORIS_CHECK(can_push_down_segment_limit); |
485 | 3.91k | DORIS_CHECK(_conjuncts.empty()); |
486 | 3.91k | } |
487 | | |
488 | | // A key TopN scan cannot share the plain LIMIT early-stop counter. If |
489 | | // storage TopN is pushed down, each scanner must produce its full local |
490 | | // candidates. If it is not pushed down for any reason, the upper TopN |
491 | | // still needs all rows from the scan. |
492 | 1.17M | if (has_key_topn) { |
493 | 2.14k | _shared_scan_limit = nullptr; |
494 | 2.14k | if (_tablet_reader_params.read_orderby_key_limit == 0) { |
495 | 97 | _limit = -1; |
496 | 97 | } |
497 | 2.14k | } |
498 | | // Note: _shared_scan_limit is intentionally not pushed into the |
499 | | // storage layer. SegmentIterator's _process_eof() is irreversible, |
500 | | // so a concurrently-decremented atomic could reach 0 while a segment |
501 | | // still has data needed by other scanners. |
502 | | |
503 | | // set push down topn filter |
504 | 1.17M | _tablet_reader_params.topn_filter_source_node_ids = |
505 | 1.17M | olap_scan_local_state->get_topn_filter_source_node_ids(_state, true); |
506 | 1.17M | if (!_tablet_reader_params.topn_filter_source_node_ids.empty()) { |
507 | 4.94k | _tablet_reader_params.topn_filter_target_node_id = |
508 | 4.94k | olap_scan_local_state->parent()->node_id(); |
509 | 4.94k | } |
510 | 1.17M | } |
511 | | |
512 | | // If this is a Two-Phase read query, and we need to delay the release of Rowset |
513 | | // by rowset->update_delayed_expired_timestamp().This could expand the lifespan of Rowset |
514 | 1.17M | if (tablet_schema->field_index(BeConsts::ROWID_COL) >= 0) { |
515 | 84 | constexpr static int delayed_s = 60; |
516 | 170 | for (auto rs_reader : _tablet_reader_params.rs_splits) { |
517 | 170 | uint64_t delayed_expired_timestamp = |
518 | 170 | UnixSeconds() + _tablet_reader_params.runtime_state->execution_timeout() + |
519 | 170 | delayed_s; |
520 | 170 | rs_reader.rs_reader->rowset()->update_delayed_expired_timestamp( |
521 | 170 | delayed_expired_timestamp); |
522 | 170 | ExecEnv::GetInstance()->storage_engine().add_quering_rowset( |
523 | 170 | rs_reader.rs_reader->rowset()); |
524 | 170 | } |
525 | 84 | } |
526 | | |
527 | 1.17M | if (tablet_schema->has_global_row_id()) { |
528 | 5.82k | auto& id_file_map = _state->get_id_file_map(); |
529 | 11.3k | for (auto rs_reader : _tablet_reader_params.rs_splits) { |
530 | 11.3k | id_file_map->add_temp_rowset(rs_reader.rs_reader->rowset()); |
531 | 11.3k | } |
532 | 5.82k | } |
533 | | |
534 | 1.17M | return Status::OK(); |
535 | 1.17M | } |
536 | | |
537 | 1.17M | Status OlapScanner::_init_variant_columns() { |
538 | 1.17M | auto& tablet_schema = _tablet_reader_params.tablet_schema; |
539 | 1.17M | if (tablet_schema->num_variant_columns() == 0) { |
540 | 1.16M | return Status::OK(); |
541 | 1.16M | } |
542 | | // Parent column has path info to distinction from each other |
543 | 15.0k | for (auto* slot : _output_tuple_desc->slots()) { |
544 | 15.0k | if (slot->type()->get_primitive_type() == PrimitiveType::TYPE_VARIANT) { |
545 | | // Such columns are not exist in frontend schema info, so we need to |
546 | | // add them into tablet_schema for later column indexing. |
547 | 7.80k | const auto& dt_variant = |
548 | 7.80k | assert_cast<const DataTypeVariant&>(*remove_nullable(slot->type())); |
549 | 7.80k | TabletColumn subcol = TabletColumn::create_materialized_variant_column( |
550 | 7.80k | tablet_schema->column_by_uid(slot->col_unique_id()).name_lower_case(), |
551 | 7.80k | slot->column_paths(), slot->col_unique_id(), |
552 | 7.80k | dt_variant.variant_max_subcolumns_count(), dt_variant.enable_doc_mode()); |
553 | 7.80k | if (tablet_schema->field_index(*subcol.path_info_ptr()) < 0) { |
554 | 5.87k | tablet_schema->append_column(subcol, TabletSchema::ColumnType::VARIANT); |
555 | 5.87k | } |
556 | 7.80k | } |
557 | 15.0k | } |
558 | 5.05k | variant_util::inherit_column_attributes(tablet_schema); |
559 | 5.05k | return Status::OK(); |
560 | 1.17M | } |
561 | | |
562 | 1.17M | Status OlapScanner::_init_return_columns() { |
563 | 12.8M | for (auto* slot : _output_tuple_desc->slots()) { |
564 | | // variant column using path to index a column |
565 | 12.8M | int32_t index = 0; |
566 | 12.8M | auto& tablet_schema = _tablet_reader_params.tablet_schema; |
567 | 12.8M | if (slot->type()->get_primitive_type() == PrimitiveType::TYPE_VARIANT) { |
568 | 7.80k | index = tablet_schema->field_index(PathInData( |
569 | 7.80k | tablet_schema->column_by_uid(slot->col_unique_id()).name_lower_case(), |
570 | 7.80k | slot->column_paths())); |
571 | 12.8M | } else { |
572 | 12.8M | index = slot->col_unique_id() >= 0 ? tablet_schema->field_index(slot->col_unique_id()) |
573 | 18.4E | : tablet_schema->field_index(slot->col_name()); |
574 | 12.8M | } |
575 | | |
576 | 12.8M | if (index < 0) { |
577 | 0 | return Status::InternalError( |
578 | 0 | "field name is invalid. field={}, field_name_to_index={}, col_unique_id={}", |
579 | 0 | slot->col_name(), tablet_schema->get_all_field_names(), slot->col_unique_id()); |
580 | 0 | } |
581 | | |
582 | 12.8M | if (slot->get_virtual_column_expr()) { |
583 | 412 | ColumnId virtual_column_cid = index; |
584 | 412 | _virtual_column_exprs[virtual_column_cid] = _slot_id_to_virtual_column_expr[slot->id()]; |
585 | 412 | size_t idx_in_block = _slot_id_to_index_in_block[slot->id()]; |
586 | 412 | _vir_cid_to_idx_in_block[virtual_column_cid] = idx_in_block; |
587 | 412 | _vir_col_idx_to_type[idx_in_block] = _slot_id_to_col_type[slot->id()]; |
588 | | |
589 | 412 | VLOG_DEBUG << fmt::format( |
590 | 1 | "Virtual column, slot id: {}, cid {}, column index: {}, type: {}", slot->id(), |
591 | 1 | virtual_column_cid, _vir_cid_to_idx_in_block[virtual_column_cid], |
592 | 1 | _vir_col_idx_to_type[idx_in_block]->get_name()); |
593 | 412 | } |
594 | | |
595 | 12.8M | const auto& column = tablet_schema->column(index); |
596 | 12.8M | int32_t unique_id = |
597 | 12.8M | column.unique_id() >= 0 ? column.unique_id() : column.parent_unique_id(); |
598 | 12.8M | if (!slot->all_access_paths().empty()) { |
599 | 73.5k | _tablet_reader_params.all_access_paths.insert({unique_id, slot->all_access_paths()}); |
600 | 73.5k | } |
601 | | |
602 | 12.8M | if (!slot->predicate_access_paths().empty()) { |
603 | 5.71k | _tablet_reader_params.predicate_access_paths.insert( |
604 | 5.71k | {unique_id, slot->predicate_access_paths()}); |
605 | 5.71k | } |
606 | | |
607 | 12.8M | if ((slot->type()->get_primitive_type() == PrimitiveType::TYPE_STRUCT || |
608 | 12.8M | slot->type()->get_primitive_type() == PrimitiveType::TYPE_MAP || |
609 | 12.8M | slot->type()->get_primitive_type() == PrimitiveType::TYPE_ARRAY) && |
610 | 12.8M | !slot->all_access_paths().empty()) { |
611 | 67.5k | tablet_schema->add_pruned_columns_data_type(column.unique_id(), slot->type()); |
612 | 67.5k | } |
613 | | |
614 | 12.8M | _return_columns.push_back(index); |
615 | 12.8M | if (slot->is_nullable() && !tablet_schema->column(index).is_nullable()) { |
616 | 0 | _tablet_columns_convert_to_null_set.emplace(index); |
617 | 12.8M | } else if (!slot->is_nullable() && tablet_schema->column(index).is_nullable()) { |
618 | 0 | return Status::Error<ErrorCode::INVALID_SCHEMA>( |
619 | 0 | "slot(id: {}, name: {})'s nullable does not match " |
620 | 0 | "column(tablet id: {}, index: {}, name: {}) ", |
621 | 0 | slot->id(), slot->col_name(), tablet_schema->table_id(), index, |
622 | 0 | tablet_schema->column(index).name()); |
623 | 0 | } |
624 | 12.8M | } |
625 | | |
626 | 1.17M | if (_return_columns.empty()) { |
627 | 0 | return Status::InternalError("failed to build storage scanner, no materialized slot!"); |
628 | 0 | } |
629 | | |
630 | 1.17M | return Status::OK(); |
631 | 1.17M | } |
632 | | |
633 | 1.22M | doris::TabletStorageType OlapScanner::get_storage_type() { |
634 | 1.22M | if (config::is_cloud_mode()) { |
635 | | // we don't have cold storage in cloud mode, all storage is treated as local |
636 | 882k | return doris::TabletStorageType::STORAGE_TYPE_LOCAL; |
637 | 882k | } |
638 | 341k | int local_reader = 0; |
639 | 550k | for (const auto& reader : _tablet_reader_params.rs_splits) { |
640 | 550k | local_reader += reader.rs_reader->rowset()->is_local(); |
641 | 550k | } |
642 | 341k | int total_reader = _tablet_reader_params.rs_splits.size(); |
643 | | |
644 | 341k | if (local_reader == total_reader) { |
645 | 341k | return doris::TabletStorageType::STORAGE_TYPE_LOCAL; |
646 | 341k | } else if (local_reader == 0) { |
647 | 0 | return doris::TabletStorageType::STORAGE_TYPE_REMOTE; |
648 | 0 | } |
649 | 0 | return doris::TabletStorageType::STORAGE_TYPE_REMOTE_AND_LOCAL; |
650 | 341k | } |
651 | | |
652 | 1.43M | Status OlapScanner::_get_block_impl(RuntimeState* state, Block* block, bool* eof) { |
653 | | // Read one block from block reader |
654 | | // ATTN: Here we need to let the _get_block_impl method guarantee the semantics of the interface, |
655 | | // that is, eof can be set to true only when the returned block is empty. |
656 | 1.43M | RETURN_IF_ERROR(_tablet_reader->next_block_with_aggregation(block, eof)); |
657 | 1.43M | if (block->rows() > 0) { |
658 | 266k | _tablet_reader_params.tablet->read_block_count.fetch_add(1, std::memory_order_relaxed); |
659 | 266k | *eof = false; |
660 | 266k | } |
661 | 1.43M | return Status::OK(); |
662 | 1.43M | } |
663 | | |
664 | 1.18M | Status OlapScanner::close(RuntimeState* state) { |
665 | 1.18M | if (!_try_close()) { |
666 | 150 | return Status::OK(); |
667 | 150 | } |
668 | 1.18M | RETURN_IF_ERROR(Scanner::close(state)); |
669 | 1.18M | return Status::OK(); |
670 | 1.18M | } |
671 | | |
672 | 1.22M | void OlapScanner::update_realtime_counters() { |
673 | 1.22M | if (!_has_prepared) { |
674 | | // Counter update need prepare successfully, or it maybe core. For example, olap scanner |
675 | | // will open tablet reader during prepare, if not prepare successfully, tablet reader == nullptr. |
676 | 0 | return; |
677 | 0 | } |
678 | 1.22M | OlapScanLocalState* local_state = static_cast<OlapScanLocalState*>(_local_state); |
679 | 1.22M | const OlapReaderStatistics& stats = _tablet_reader->stats(); |
680 | 1.22M | COUNTER_UPDATE(local_state->_read_compressed_counter, stats.compressed_bytes_read); |
681 | 1.22M | COUNTER_UPDATE(local_state->_read_uncompressed_counter, stats.uncompressed_bytes_read); |
682 | 1.22M | COUNTER_UPDATE(local_state->_scan_bytes, stats.uncompressed_bytes_read); |
683 | 1.22M | COUNTER_UPDATE(local_state->_scan_rows, stats.raw_rows_read); |
684 | | |
685 | | // Make sure the scan bytes and scan rows counter in audit log is the same as the counter in |
686 | | // doris metrics. |
687 | | // ScanBytes is the uncompressed bytes read from local + remote |
688 | | // bytes_read_from_local is the compressed bytes read from local |
689 | | // bytes_read_from_remote is the compressed bytes read from remote |
690 | | // scan bytes > bytes_read_from_local + bytes_read_from_remote |
691 | 1.22M | _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_rows(stats.raw_rows_read); |
692 | 1.22M | _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes( |
693 | 1.22M | stats.uncompressed_bytes_read); |
694 | | |
695 | | // In case of no cache, we still need to update the IO stats. uncompressed bytes read == local + remote |
696 | 1.22M | if (stats.file_cache_stats.bytes_read_from_local == 0 && |
697 | 1.22M | stats.file_cache_stats.bytes_read_from_remote == 0) { |
698 | 968k | _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes_from_local_storage( |
699 | 968k | stats.compressed_bytes_read); |
700 | 968k | DorisMetrics::instance()->query_scan_bytes_from_local->increment( |
701 | 968k | stats.compressed_bytes_read); |
702 | 968k | } else { |
703 | 253k | _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes_from_local_storage( |
704 | 253k | stats.file_cache_stats.bytes_read_from_local - _bytes_read_from_local); |
705 | 253k | _state->get_query_ctx() |
706 | 253k | ->resource_ctx() |
707 | 253k | ->io_context() |
708 | 253k | ->update_scan_bytes_from_remote_storage( |
709 | 253k | stats.file_cache_stats.bytes_read_from_remote - _bytes_read_from_remote); |
710 | | |
711 | 253k | DorisMetrics::instance()->query_scan_bytes_from_local->increment( |
712 | 253k | stats.file_cache_stats.bytes_read_from_local - _bytes_read_from_local); |
713 | 253k | DorisMetrics::instance()->query_scan_bytes_from_remote->increment( |
714 | 253k | stats.file_cache_stats.bytes_read_from_remote - _bytes_read_from_remote); |
715 | 253k | } |
716 | | |
717 | 1.22M | _tablet_reader->mutable_stats()->compressed_bytes_read = 0; |
718 | 1.22M | _tablet_reader->mutable_stats()->uncompressed_bytes_read = 0; |
719 | 1.22M | _tablet_reader->mutable_stats()->raw_rows_read = 0; |
720 | | |
721 | 1.22M | _bytes_read_from_local = _tablet_reader->stats().file_cache_stats.bytes_read_from_local; |
722 | 1.22M | _bytes_read_from_remote = _tablet_reader->stats().file_cache_stats.bytes_read_from_remote; |
723 | 1.22M | } |
724 | | |
725 | 1.17M | void OlapScanner::_collect_profile_before_close() { |
726 | | // Please don't directly enable the profile here, we need to set QueryStatistics using the counter inside. |
727 | 1.17M | if (_has_updated_counter) { |
728 | 0 | return; |
729 | 0 | } |
730 | 1.17M | _has_updated_counter = true; |
731 | 1.17M | _tablet_reader->update_profile(_profile); |
732 | | |
733 | 1.17M | Scanner::_collect_profile_before_close(); |
734 | | |
735 | | // Update counters for OlapScanner |
736 | | // Update counters from tablet reader's stats |
737 | 1.17M | auto& stats = _tablet_reader->stats(); |
738 | 1.17M | auto* local_state = (OlapScanLocalState*)_local_state; |
739 | 1.17M | COUNTER_UPDATE(local_state->_io_timer, stats.io_ns); |
740 | 1.17M | COUNTER_UPDATE(local_state->_read_compressed_counter, stats.compressed_bytes_read); |
741 | 1.17M | COUNTER_UPDATE(local_state->_scan_bytes, stats.uncompressed_bytes_read); |
742 | 1.17M | COUNTER_UPDATE(local_state->_decompressor_timer, stats.decompress_ns); |
743 | 1.17M | COUNTER_UPDATE(local_state->_read_uncompressed_counter, stats.uncompressed_bytes_read); |
744 | 1.17M | COUNTER_UPDATE(local_state->_block_load_timer, stats.block_load_ns); |
745 | 1.17M | COUNTER_UPDATE(local_state->_block_load_counter, stats.blocks_load); |
746 | 1.17M | COUNTER_UPDATE(local_state->_block_fetch_timer, stats.block_fetch_ns); |
747 | 1.17M | COUNTER_UPDATE(local_state->_delete_bitmap_get_agg_timer, stats.delete_bitmap_get_agg_ns); |
748 | 1.17M | COUNTER_UPDATE(local_state->_scan_rows, stats.raw_rows_read); |
749 | 1.17M | COUNTER_UPDATE(local_state->_vec_cond_timer, stats.vec_cond_ns); |
750 | 1.17M | COUNTER_UPDATE(local_state->_short_cond_timer, stats.short_cond_ns); |
751 | 1.17M | COUNTER_UPDATE(local_state->_expr_filter_timer, stats.expr_filter_ns); |
752 | 1.17M | COUNTER_UPDATE(local_state->_block_init_timer, stats.block_init_ns); |
753 | 1.17M | COUNTER_UPDATE(local_state->_block_init_seek_timer, stats.block_init_seek_ns); |
754 | 1.17M | COUNTER_UPDATE(local_state->_block_init_seek_counter, stats.block_init_seek_num); |
755 | 1.17M | COUNTER_UPDATE(local_state->_segment_generate_row_range_by_keys_timer, |
756 | 1.17M | stats.generate_row_ranges_by_keys_ns); |
757 | 1.17M | COUNTER_UPDATE(local_state->_segment_generate_row_range_by_column_conditions_timer, |
758 | 1.17M | stats.generate_row_ranges_by_column_conditions_ns); |
759 | 1.17M | COUNTER_UPDATE(local_state->_segment_generate_row_range_by_bf_timer, |
760 | 1.17M | stats.generate_row_ranges_by_bf_ns); |
761 | 1.17M | COUNTER_UPDATE(local_state->_collect_iterator_merge_next_timer, |
762 | 1.17M | stats.collect_iterator_merge_next_timer); |
763 | 1.17M | COUNTER_UPDATE(local_state->_segment_generate_row_range_by_zonemap_timer, |
764 | 1.17M | stats.generate_row_ranges_by_zonemap_ns); |
765 | 1.17M | COUNTER_UPDATE(local_state->_segment_generate_row_range_by_dict_timer, |
766 | 1.17M | stats.generate_row_ranges_by_dict_ns); |
767 | 1.17M | COUNTER_UPDATE(local_state->_predicate_column_read_timer, stats.predicate_column_read_ns); |
768 | 1.17M | COUNTER_UPDATE(local_state->_non_predicate_column_read_timer, stats.non_predicate_read_ns); |
769 | 1.17M | COUNTER_UPDATE(local_state->_predicate_column_read_seek_timer, |
770 | 1.17M | stats.predicate_column_read_seek_ns); |
771 | 1.17M | COUNTER_UPDATE(local_state->_predicate_column_read_seek_counter, |
772 | 1.17M | stats.predicate_column_read_seek_num); |
773 | 1.17M | COUNTER_UPDATE(local_state->_lazy_read_timer, stats.lazy_read_ns); |
774 | 1.17M | COUNTER_UPDATE(local_state->_lazy_read_seek_timer, stats.block_lazy_read_seek_ns); |
775 | 1.17M | COUNTER_UPDATE(local_state->_lazy_read_seek_counter, stats.block_lazy_read_seek_num); |
776 | 1.17M | COUNTER_UPDATE(local_state->_output_col_timer, stats.output_col_ns); |
777 | 1.17M | COUNTER_UPDATE(local_state->_rows_vec_cond_filtered_counter, stats.rows_vec_cond_filtered); |
778 | 1.17M | COUNTER_UPDATE(local_state->_rows_short_circuit_cond_filtered_counter, |
779 | 1.17M | stats.rows_short_circuit_cond_filtered); |
780 | 1.17M | COUNTER_UPDATE(local_state->_rows_expr_cond_filtered_counter, stats.rows_expr_cond_filtered); |
781 | 1.17M | COUNTER_UPDATE(local_state->_rows_vec_cond_input_counter, stats.vec_cond_input_rows); |
782 | 1.17M | COUNTER_UPDATE(local_state->_rows_short_circuit_cond_input_counter, |
783 | 1.17M | stats.short_circuit_cond_input_rows); |
784 | 1.17M | COUNTER_UPDATE(local_state->_rows_expr_cond_input_counter, stats.expr_cond_input_rows); |
785 | 1.17M | COUNTER_UPDATE(local_state->_stats_filtered_counter, stats.rows_stats_filtered); |
786 | 1.17M | COUNTER_UPDATE(local_state->_stats_rp_filtered_counter, stats.rows_stats_rp_filtered); |
787 | 1.17M | COUNTER_UPDATE(local_state->_dict_filtered_counter, stats.segment_dict_filtered); |
788 | 1.17M | COUNTER_UPDATE(local_state->_bf_filtered_counter, stats.rows_bf_filtered); |
789 | 1.17M | COUNTER_UPDATE(local_state->_del_filtered_counter, stats.rows_del_filtered); |
790 | 1.17M | COUNTER_UPDATE(local_state->_del_filtered_counter, stats.rows_del_by_bitmap); |
791 | 1.17M | COUNTER_UPDATE(local_state->_del_filtered_counter, stats.rows_vec_del_cond_filtered); |
792 | 1.17M | COUNTER_UPDATE(local_state->_conditions_filtered_counter, stats.rows_conditions_filtered); |
793 | 1.17M | COUNTER_UPDATE(local_state->_key_range_filtered_counter, stats.rows_key_range_filtered); |
794 | 1.17M | COUNTER_UPDATE(local_state->_total_pages_num_counter, stats.total_pages_num); |
795 | 1.17M | COUNTER_UPDATE(local_state->_cached_pages_num_counter, stats.cached_pages_num); |
796 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_filter_counter, stats.rows_inverted_index_filtered); |
797 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_filter_timer, stats.inverted_index_filter_timer); |
798 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_query_cache_hit_counter, |
799 | 1.17M | stats.inverted_index_query_cache_hit); |
800 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_query_cache_miss_counter, |
801 | 1.17M | stats.inverted_index_query_cache_miss); |
802 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_query_timer, stats.inverted_index_query_timer); |
803 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_query_null_bitmap_timer, |
804 | 1.17M | stats.inverted_index_query_null_bitmap_timer); |
805 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_query_bitmap_copy_timer, |
806 | 1.17M | stats.inverted_index_query_bitmap_copy_timer); |
807 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_searcher_open_timer, |
808 | 1.17M | stats.inverted_index_searcher_open_timer); |
809 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_searcher_search_timer, |
810 | 1.17M | stats.inverted_index_searcher_search_timer); |
811 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_searcher_search_init_timer, |
812 | 1.17M | stats.inverted_index_searcher_search_init_timer); |
813 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_searcher_search_exec_timer, |
814 | 1.17M | stats.inverted_index_searcher_search_exec_timer); |
815 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_searcher_cache_hit_counter, |
816 | 1.17M | stats.inverted_index_searcher_cache_hit); |
817 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_searcher_cache_miss_counter, |
818 | 1.17M | stats.inverted_index_searcher_cache_miss); |
819 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_downgrade_count_counter, |
820 | 1.17M | stats.inverted_index_downgrade_count); |
821 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_analyzer_timer, |
822 | 1.17M | stats.inverted_index_analyzer_timer); |
823 | 1.17M | COUNTER_UPDATE(local_state->_inverted_index_lookup_timer, stats.inverted_index_lookup_timer); |
824 | 1.17M | COUNTER_UPDATE(local_state->_variant_scan_sparse_column_timer, |
825 | 1.17M | stats.variant_scan_sparse_column_timer_ns); |
826 | 1.17M | COUNTER_UPDATE(local_state->_variant_scan_sparse_column_bytes, |
827 | 1.17M | stats.variant_scan_sparse_column_bytes); |
828 | 1.17M | COUNTER_UPDATE(local_state->_variant_fill_path_from_sparse_column_timer, |
829 | 1.17M | stats.variant_fill_path_from_sparse_column_timer_ns); |
830 | 1.17M | COUNTER_UPDATE(local_state->_variant_subtree_default_iter_count, |
831 | 1.17M | stats.variant_subtree_default_iter_count); |
832 | 1.17M | COUNTER_UPDATE(local_state->_variant_subtree_leaf_iter_count, |
833 | 1.17M | stats.variant_subtree_leaf_iter_count); |
834 | 1.17M | COUNTER_UPDATE(local_state->_variant_subtree_hierarchical_iter_count, |
835 | 1.17M | stats.variant_subtree_hierarchical_iter_count); |
836 | 1.17M | COUNTER_UPDATE(local_state->_variant_subtree_sparse_iter_count, |
837 | 1.17M | stats.variant_subtree_sparse_iter_count); |
838 | 1.17M | COUNTER_UPDATE(local_state->_variant_doc_value_column_iter_count, |
839 | 1.17M | stats.variant_doc_value_column_iter_count); |
840 | | |
841 | 1.17M | if (stats.adaptive_batch_size_predict_max_rows > 0) { |
842 | 929k | local_state->_adaptive_batch_predict_min_rows_counter->set( |
843 | 929k | stats.adaptive_batch_size_predict_min_rows); |
844 | 929k | local_state->_adaptive_batch_predict_max_rows_counter->set( |
845 | 929k | stats.adaptive_batch_size_predict_max_rows); |
846 | 929k | } |
847 | | |
848 | 1.17M | InvertedIndexProfileReporter inverted_index_profile; |
849 | 1.17M | inverted_index_profile.update(local_state->_index_filter_profile.get(), |
850 | 1.17M | &stats.inverted_index_stats); |
851 | | |
852 | | // only cloud deploy mode will use file cache. |
853 | 1.17M | if (config::is_cloud_mode() && config::enable_file_cache) { |
854 | 836k | io::FileCacheProfileReporter cache_profile(local_state->_segment_profile.get()); |
855 | 836k | cache_profile.update(&stats.file_cache_stats); |
856 | 836k | _state->get_query_ctx()->resource_ctx()->io_context()->update_bytes_write_into_cache( |
857 | 836k | stats.file_cache_stats.bytes_write_into_cache); |
858 | 836k | } |
859 | 1.17M | COUNTER_UPDATE(local_state->_output_index_result_column_timer, |
860 | 1.17M | stats.output_index_result_column_timer); |
861 | 1.17M | COUNTER_UPDATE(local_state->_filtered_segment_counter, stats.filtered_segment_number); |
862 | 1.17M | COUNTER_UPDATE(local_state->_total_segment_counter, stats.total_segment_number); |
863 | 1.17M | COUNTER_UPDATE(local_state->_condition_cache_hit_counter, stats.condition_cache_hit_seg_nums); |
864 | 1.17M | COUNTER_UPDATE(local_state->_condition_cache_filtered_rows_counter, |
865 | 1.17M | stats.condition_cache_filtered_rows); |
866 | | |
867 | 1.17M | COUNTER_UPDATE(local_state->_tablet_reader_init_timer, stats.tablet_reader_init_timer_ns); |
868 | 1.17M | COUNTER_UPDATE(local_state->_tablet_reader_capture_rs_readers_timer, |
869 | 1.17M | stats.tablet_reader_capture_rs_readers_timer_ns); |
870 | 1.17M | COUNTER_UPDATE(local_state->_tablet_reader_init_return_columns_timer, |
871 | 1.17M | stats.tablet_reader_init_return_columns_timer_ns); |
872 | 1.17M | COUNTER_UPDATE(local_state->_tablet_reader_init_keys_param_timer, |
873 | 1.17M | stats.tablet_reader_init_keys_param_timer_ns); |
874 | 1.17M | COUNTER_UPDATE(local_state->_tablet_reader_init_orderby_keys_param_timer, |
875 | 1.17M | stats.tablet_reader_init_orderby_keys_param_timer_ns); |
876 | 1.17M | COUNTER_UPDATE(local_state->_tablet_reader_init_conditions_param_timer, |
877 | 1.17M | stats.tablet_reader_init_conditions_param_timer_ns); |
878 | 1.17M | COUNTER_UPDATE(local_state->_tablet_reader_init_delete_condition_param_timer, |
879 | 1.17M | stats.tablet_reader_init_delete_condition_param_timer_ns); |
880 | 1.17M | COUNTER_UPDATE(local_state->_block_reader_vcollect_iter_init_timer, |
881 | 1.17M | stats.block_reader_vcollect_iter_init_timer_ns); |
882 | 1.17M | COUNTER_UPDATE(local_state->_block_reader_rs_readers_init_timer, |
883 | 1.17M | stats.block_reader_rs_readers_init_timer_ns); |
884 | 1.17M | COUNTER_UPDATE(local_state->_block_reader_build_heap_init_timer, |
885 | 1.17M | stats.block_reader_build_heap_init_timer_ns); |
886 | | |
887 | 1.17M | COUNTER_UPDATE(local_state->_rowset_reader_get_segment_iterators_timer, |
888 | 1.17M | stats.rowset_reader_get_segment_iterators_timer_ns); |
889 | 1.17M | COUNTER_UPDATE(local_state->_rowset_reader_create_iterators_timer, |
890 | 1.17M | stats.rowset_reader_create_iterators_timer_ns); |
891 | 1.17M | COUNTER_UPDATE(local_state->_rowset_reader_init_iterators_timer, |
892 | 1.17M | stats.rowset_reader_init_iterators_timer_ns); |
893 | 1.17M | COUNTER_UPDATE(local_state->_rowset_reader_load_segments_timer, |
894 | 1.17M | stats.rowset_reader_load_segments_timer_ns); |
895 | | |
896 | 1.17M | COUNTER_UPDATE(local_state->_segment_iterator_init_timer, stats.segment_iterator_init_timer_ns); |
897 | 1.17M | COUNTER_UPDATE(local_state->_segment_iterator_init_return_column_iterators_timer, |
898 | 1.17M | stats.segment_iterator_init_return_column_iterators_timer_ns); |
899 | 1.17M | COUNTER_UPDATE(local_state->_segment_iterator_init_index_iterators_timer, |
900 | 1.17M | stats.segment_iterator_init_index_iterators_timer_ns); |
901 | 1.17M | COUNTER_UPDATE(local_state->_segment_iterator_init_segment_prefetchers_timer, |
902 | 1.17M | stats.segment_iterator_init_segment_prefetchers_timer_ns); |
903 | | |
904 | 1.17M | COUNTER_UPDATE(local_state->_segment_create_column_readers_timer, |
905 | 1.17M | stats.segment_create_column_readers_timer_ns); |
906 | 1.17M | COUNTER_UPDATE(local_state->_segment_load_index_timer, stats.segment_load_index_timer_ns); |
907 | | |
908 | | // Update metrics |
909 | 1.17M | DorisMetrics::instance()->query_scan_bytes->increment( |
910 | 1.17M | local_state->_read_uncompressed_counter->value()); |
911 | 1.17M | DorisMetrics::instance()->query_scan_rows->increment(local_state->_scan_rows->value()); |
912 | 1.17M | auto& tablet = _tablet_reader_params.tablet; |
913 | 1.17M | tablet->query_scan_bytes->increment(local_state->_read_uncompressed_counter->value()); |
914 | 1.17M | tablet->query_scan_rows->increment(local_state->_scan_rows->value()); |
915 | 1.17M | tablet->query_scan_count->increment(1); |
916 | | |
917 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_search_filter_counter, |
918 | 1.17M | stats.rows_ann_index_range_filtered); |
919 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_filter_counter, stats.rows_ann_index_topn_filtered); |
920 | 1.17M | COUNTER_UPDATE(local_state->_ann_index_load_costs, stats.ann_index_load_ns); |
921 | 1.17M | COUNTER_UPDATE(local_state->_ann_ivf_on_disk_load_costs, stats.ann_ivf_on_disk_load_ns); |
922 | 1.17M | COUNTER_UPDATE(local_state->_ann_ivf_on_disk_cache_hit_cnt, |
923 | 1.17M | stats.ann_ivf_on_disk_cache_hit_cnt); |
924 | 1.17M | COUNTER_UPDATE(local_state->_ann_ivf_on_disk_cache_miss_cnt, |
925 | 1.17M | stats.ann_ivf_on_disk_cache_miss_cnt); |
926 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_search_costs, stats.ann_index_range_search_ns); |
927 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_search_cnt, stats.ann_index_range_search_cnt); |
928 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_engine_search_costs, stats.ann_range_engine_search_ns); |
929 | | // Engine prepare before search |
930 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_pre_process_costs, stats.ann_range_pre_process_ns); |
931 | | // Post process parent: Doris result process + engine convert |
932 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_post_process_costs, |
933 | 1.17M | stats.ann_range_result_convert_ns + stats.ann_range_engine_convert_ns); |
934 | | // Engine convert (child under post-process) |
935 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_engine_convert_costs, stats.ann_range_engine_convert_ns); |
936 | | // Doris-side result convert (child under post-process) |
937 | 1.17M | COUNTER_UPDATE(local_state->_ann_range_result_convert_costs, stats.ann_range_result_convert_ns); |
938 | | |
939 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_search_costs, stats.ann_topn_search_ns); |
940 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_search_cnt, stats.ann_index_topn_search_cnt); |
941 | | |
942 | | // Detailed ANN timers |
943 | | // ANN TopN timers with hierarchy |
944 | | // Engine search time (FAISS) |
945 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_engine_search_costs, |
946 | 1.17M | stats.ann_index_topn_engine_search_ns); |
947 | | // Engine prepare time (allocations/buffer setup before search) |
948 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_pre_process_costs, |
949 | 1.17M | stats.ann_index_topn_engine_prepare_ns); |
950 | | // Post process parent includes Doris result processing + engine convert |
951 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_post_process_costs, |
952 | 1.17M | stats.ann_index_topn_result_process_ns + stats.ann_index_topn_engine_convert_ns); |
953 | | // Engine-side conversion time inside FAISS wrappers (child under post-process) |
954 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_engine_convert_costs, |
955 | 1.17M | stats.ann_index_topn_engine_convert_ns); |
956 | | |
957 | | // Doris-side result convert costs (show separately as another child counter); use pure process time |
958 | 1.17M | COUNTER_UPDATE(local_state->_ann_topn_result_convert_costs, |
959 | 1.17M | stats.ann_index_topn_result_process_ns); |
960 | | |
961 | 1.17M | COUNTER_UPDATE(local_state->_ann_fallback_brute_force_cnt, stats.ann_fall_back_brute_force_cnt); |
962 | | |
963 | | // Overhead counter removed; precise instrumentation is reported via engine_prepare above. |
964 | 1.17M | } |
965 | | |
966 | | #include "common/compile_check_avoid_end.h" |
967 | | } // namespace doris |