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