/root/doris/be/src/olap/tablet_schema.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/Types_types.h> |
21 | | #include <gen_cpp/olap_common.pb.h> |
22 | | #include <gen_cpp/olap_file.pb.h> |
23 | | #include <gen_cpp/segment_v2.pb.h> |
24 | | #include <parallel_hashmap/phmap.h> |
25 | | |
26 | | #include <algorithm> |
27 | | #include <map> |
28 | | #include <memory> |
29 | | #include <string> |
30 | | #include <unordered_map> |
31 | | #include <unordered_set> |
32 | | #include <utility> |
33 | | #include <vector> |
34 | | |
35 | | #include "common/consts.h" |
36 | | #include "common/status.h" |
37 | | #include "gutil/stringprintf.h" |
38 | | #include "olap/metadata_adder.h" |
39 | | #include "olap/olap_common.h" |
40 | | #include "olap/rowset/segment_v2/options.h" |
41 | | #include "runtime/define_primitive_type.h" |
42 | | #include "runtime/descriptors.h" |
43 | | #include "runtime/memory/lru_cache_policy.h" |
44 | | #include "util/debug_points.h" |
45 | | #include "util/string_util.h" |
46 | | #include "vec/aggregate_functions/aggregate_function.h" |
47 | | #include "vec/common/string_ref.h" |
48 | | #include "vec/common/string_utils/string_utils.h" |
49 | | #include "vec/core/types.h" |
50 | | #include "vec/json/path_in_data.h" |
51 | | |
52 | | namespace doris { |
53 | | namespace vectorized { |
54 | | class Block; |
55 | | class PathInData; |
56 | | class IDataType; |
57 | | } // namespace vectorized |
58 | | |
59 | | struct OlapTableIndexSchema; |
60 | | class TColumn; |
61 | | class TOlapTableIndex; |
62 | | class TabletColumn; |
63 | | |
64 | | using TabletColumnPtr = std::shared_ptr<TabletColumn>; |
65 | | |
66 | | class TabletColumn : public MetadataAdder<TabletColumn> { |
67 | | public: |
68 | | TabletColumn(); |
69 | | TabletColumn(const ColumnPB& column); |
70 | | TabletColumn(const TColumn& column); |
71 | | TabletColumn(FieldAggregationMethod agg, FieldType type); |
72 | | TabletColumn(FieldAggregationMethod agg, FieldType filed_type, bool is_nullable); |
73 | | TabletColumn(FieldAggregationMethod agg, FieldType filed_type, bool is_nullable, |
74 | | int32_t unique_id, size_t length); |
75 | | void init_from_pb(const ColumnPB& column); |
76 | | void init_from_thrift(const TColumn& column); |
77 | | void to_schema_pb(ColumnPB* column) const; |
78 | | |
79 | 310k | int32_t unique_id() const { return _unique_id; } |
80 | 77 | void set_unique_id(int32_t id) { _unique_id = id; } |
81 | 149k | const std::string& name() const { return _col_name; } |
82 | 0 | const std::string& name_lower_case() const { return _col_name_lower_case; } |
83 | 108 | void set_name(std::string col_name) { |
84 | 108 | _col_name = col_name; |
85 | 108 | _col_name_lower_case = to_lower(_col_name); |
86 | 108 | } |
87 | 933k | FieldType type() const { return _type; } |
88 | 105 | void set_type(FieldType type) { _type = type; } |
89 | 86.0k | bool is_key() const { return _is_key; } |
90 | 166k | bool is_nullable() const { return _is_nullable; } |
91 | 0 | bool is_auto_increment() const { return _is_auto_increment; } |
92 | 75.0k | bool is_variant_type() const { return _type == FieldType::OLAP_FIELD_TYPE_VARIANT; } |
93 | 12.8k | bool is_bf_column() const { return _is_bf_column; } |
94 | 12.8k | bool has_bitmap_index() const { return _has_bitmap_index; } |
95 | 13.6k | bool is_array_type() const { return _type == FieldType::OLAP_FIELD_TYPE_ARRAY; } |
96 | 12.2k | bool is_agg_state_type() const { return _type == FieldType::OLAP_FIELD_TYPE_AGG_STATE; } |
97 | 0 | bool is_jsonb_type() const { return _type == FieldType::OLAP_FIELD_TYPE_JSONB; } |
98 | 0 | bool is_length_variable_type() const { |
99 | 0 | return _type == FieldType::OLAP_FIELD_TYPE_CHAR || |
100 | 0 | _type == FieldType::OLAP_FIELD_TYPE_VARCHAR || |
101 | 0 | _type == FieldType::OLAP_FIELD_TYPE_STRING || |
102 | 0 | _type == FieldType::OLAP_FIELD_TYPE_HLL || |
103 | 0 | _type == FieldType::OLAP_FIELD_TYPE_OBJECT || |
104 | 0 | _type == FieldType::OLAP_FIELD_TYPE_QUANTILE_STATE || |
105 | 0 | _type == FieldType::OLAP_FIELD_TYPE_AGG_STATE; |
106 | 0 | } |
107 | | // Such columns are not exist in frontend schema info, so we need to |
108 | | // add them into tablet_schema for later column indexing. |
109 | | static TabletColumn create_materialized_variant_column(const std::string& root, |
110 | | const std::vector<std::string>& paths, |
111 | | int32_t parent_unique_id); |
112 | 188 | bool has_default_value() const { return _has_default_value; } |
113 | 12.8k | std::string default_value() const { return _default_value; } |
114 | 38.8k | size_t length() const { return _length; } |
115 | 31 | void set_length(size_t length) { _length = length; } |
116 | 0 | void set_default_value(const std::string& default_value) { |
117 | 0 | _default_value = default_value; |
118 | 0 | _has_default_value = true; |
119 | 0 | } |
120 | 29.3k | size_t index_length() const { return _index_length; } |
121 | 17 | void set_index_length(size_t index_length) { _index_length = index_length; } |
122 | 61 | void set_is_key(bool is_key) { _is_key = is_key; } |
123 | 28 | void set_is_nullable(bool is_nullable) { _is_nullable = is_nullable; } |
124 | 0 | void set_is_auto_increment(bool is_auto_increment) { _is_auto_increment = is_auto_increment; } |
125 | | void set_path_info(const vectorized::PathInData& path); |
126 | 19.2k | FieldAggregationMethod aggregation() const { return _aggregation; } |
127 | | vectorized::AggregateFunctionPtr get_aggregate_function_union( |
128 | | vectorized::DataTypePtr type, int current_be_exec_version) const; |
129 | | vectorized::AggregateFunctionPtr get_aggregate_function(std::string suffix, |
130 | | int current_be_exec_version) const; |
131 | 147k | int precision() const { return _precision; } |
132 | 147k | int frac() const { return _frac; } |
133 | 0 | inline bool visible() const { return _visible; } |
134 | | |
135 | 4 | void set_aggregation_method(FieldAggregationMethod agg) { |
136 | 4 | _aggregation = agg; |
137 | 4 | _aggregation_name = get_string_by_aggregation_type(agg); |
138 | 4 | } |
139 | | |
140 | | /** |
141 | | * Add a sub column. |
142 | | */ |
143 | | void add_sub_column(TabletColumn& sub_column); |
144 | | |
145 | 12.8k | uint32_t get_subtype_count() const { return _sub_column_count; } |
146 | 60 | const TabletColumn& get_sub_column(uint32_t i) const { return *_sub_columns[i]; } |
147 | 0 | const std::vector<TabletColumnPtr>& get_sub_columns() const { return _sub_columns; } |
148 | | |
149 | | friend bool operator==(const TabletColumn& a, const TabletColumn& b); |
150 | | friend bool operator!=(const TabletColumn& a, const TabletColumn& b); |
151 | | |
152 | | static std::string get_string_by_field_type(FieldType type); |
153 | | static std::string get_string_by_aggregation_type(FieldAggregationMethod aggregation_type); |
154 | | static FieldType get_field_type_by_string(const std::string& str); |
155 | | static FieldType get_field_type_by_type(PrimitiveType type); |
156 | | static FieldAggregationMethod get_aggregation_type_by_string(const std::string& str); |
157 | | static uint32_t get_field_length_by_type(TPrimitiveType::type type, uint32_t string_length); |
158 | | bool is_row_store_column() const; |
159 | 12.8k | std::string get_aggregation_name() const { return _aggregation_name; } |
160 | 12.8k | bool get_result_is_nullable() const { return _result_is_nullable; } |
161 | 12.8k | int get_be_exec_version() const { return _be_exec_version; } |
162 | 108k | bool has_path_info() const { return _column_path != nullptr && !_column_path->empty(); } |
163 | 25.9k | const vectorized::PathInDataPtr& path_info_ptr() const { return _column_path; } |
164 | | // If it is an extracted column from variant column |
165 | 90.1k | bool is_extracted_column() const { |
166 | 90.1k | return _column_path != nullptr && !_column_path->empty() && _parent_col_unique_id > 0; |
167 | 90.1k | }; |
168 | 25.9k | std::string suffix_path() const { |
169 | 25.9k | return is_extracted_column() ? _column_path->get_path() : ""; |
170 | 25.9k | } |
171 | 0 | bool is_nested_subcolumn() const { |
172 | 0 | return _column_path != nullptr && _column_path->has_nested_part(); |
173 | 0 | } |
174 | 25.9k | int32_t parent_unique_id() const { return _parent_col_unique_id; } |
175 | 6 | void set_parent_unique_id(int32_t col_unique_id) { _parent_col_unique_id = col_unique_id; } |
176 | 11 | void set_is_bf_column(bool is_bf_column) { _is_bf_column = is_bf_column; } |
177 | 0 | void set_has_bitmap_index(bool has_bitmap_index) { _has_bitmap_index = has_bitmap_index; } |
178 | | std::shared_ptr<const vectorized::IDataType> get_vec_type() const; |
179 | | |
180 | | void append_sparse_column(TabletColumn column); |
181 | | const TabletColumn& sparse_column_at(size_t oridinal) const; |
182 | | const std::vector<TabletColumnPtr>& sparse_columns() const; |
183 | 12.8k | size_t num_sparse_columns() const { return _num_sparse_columns; } |
184 | | |
185 | 1 | Status check_valid() const { |
186 | 1 | if (type() != FieldType::OLAP_FIELD_TYPE_ARRAY && |
187 | 1 | type() != FieldType::OLAP_FIELD_TYPE_STRUCT && |
188 | 1 | type() != FieldType::OLAP_FIELD_TYPE_MAP) { |
189 | 1 | return Status::OK(); |
190 | 1 | } |
191 | 0 | if (is_bf_column()) { |
192 | 0 | return Status::NotSupported("Do not support bloom filter index, type={}", |
193 | 0 | get_string_by_field_type(type())); |
194 | 0 | } |
195 | 0 | if (has_bitmap_index()) { |
196 | 0 | return Status::NotSupported("Do not support bitmap index, type={}", |
197 | 0 | get_string_by_field_type(type())); |
198 | 0 | } |
199 | 0 | return Status::OK(); |
200 | 0 | } |
201 | | |
202 | | private: |
203 | | int32_t _unique_id = -1; |
204 | | std::string _col_name; |
205 | | std::string _col_name_lower_case; |
206 | | // the field _type will change from TPrimitiveType |
207 | | // to string by 'EnumToString(TPrimitiveType, tcolumn.column_type.type, data_type);' (reference: TabletMeta::init_column_from_tcolumn) |
208 | | // to FieldType by 'TabletColumn::get_field_type_by_string' (reference: TabletColumn::init_from_pb). |
209 | | // And the _type in columnPB is string and it changed from FieldType by 'get_string_by_field_type' (reference: TabletColumn::to_schema_pb). |
210 | | FieldType _type; |
211 | | bool _is_key = false; |
212 | | FieldAggregationMethod _aggregation; |
213 | | std::string _aggregation_name; |
214 | | bool _is_nullable = false; |
215 | | bool _is_auto_increment = false; |
216 | | |
217 | | bool _has_default_value = false; |
218 | | std::string _default_value; |
219 | | |
220 | | bool _is_decimal = false; |
221 | | int32_t _precision = -1; |
222 | | int32_t _frac = -1; |
223 | | |
224 | | int32_t _length = -1; |
225 | | int32_t _index_length = -1; |
226 | | |
227 | | bool _is_bf_column = false; |
228 | | |
229 | | bool _has_bitmap_index = false; |
230 | | bool _visible = true; |
231 | | |
232 | | std::vector<TabletColumnPtr> _sub_columns; |
233 | | uint32_t _sub_column_count = 0; |
234 | | |
235 | | bool _result_is_nullable = false; |
236 | | int _be_exec_version = -1; |
237 | | |
238 | | // The extracted sub-columns from "variant" contain the following information: |
239 | | int32_t _parent_col_unique_id = -1; // "variant" -> col_unique_id |
240 | | vectorized::PathInDataPtr _column_path; // the path of the sub-columns themselves |
241 | | |
242 | | // Record information about columns merged into a sparse column within a variant |
243 | | // `{"id": 100, "name" : "jack", "point" : 3.9}` |
244 | | // If the information mentioned above is inserted into the variant column, |
245 | | // 'id' and 'name' are correctly extracted, while 'point' is merged into the sparse column due to its sparsity. |
246 | | // The path_info and type of 'point' will be recorded using the TabletColumn. |
247 | | // Use shared_ptr for reuse and reducing column memory usage |
248 | | std::vector<TabletColumnPtr> _sparse_cols; |
249 | | size_t _num_sparse_columns = 0; |
250 | | }; |
251 | | |
252 | | bool operator==(const TabletColumn& a, const TabletColumn& b); |
253 | | bool operator!=(const TabletColumn& a, const TabletColumn& b); |
254 | | |
255 | | class TabletIndex : public MetadataAdder<TabletIndex> { |
256 | | public: |
257 | 7.31k | TabletIndex() = default; |
258 | | void init_from_thrift(const TOlapTableIndex& index, const TabletSchema& tablet_schema); |
259 | | void init_from_thrift(const TOlapTableIndex& index, const std::vector<int32_t>& column_uids); |
260 | | void init_from_pb(const TabletIndexPB& index); |
261 | | void to_schema_pb(TabletIndexPB* index) const; |
262 | | |
263 | 10.5k | int64_t index_id() const { return _index_id; } |
264 | 0 | const std::string& index_name() const { return _index_name; } |
265 | 9.24k | IndexType index_type() const { return _index_type; } |
266 | 9.04k | const vector<int32_t>& col_unique_ids() const { return _col_unique_ids; } |
267 | 21.0k | const std::map<string, string>& properties() const { return _properties; } |
268 | 0 | int32_t get_gram_size() const { |
269 | 0 | if (_properties.contains("gram_size")) { |
270 | 0 | return std::stoi(_properties.at("gram_size")); |
271 | 0 | } |
272 | | |
273 | 0 | return 0; |
274 | 0 | } |
275 | 0 | int32_t get_gram_bf_size() const { |
276 | 0 | if (_properties.contains("bf_size")) { |
277 | 0 | return std::stoi(_properties.at("bf_size")); |
278 | 0 | } |
279 | | |
280 | 0 | return 0; |
281 | 0 | } |
282 | | |
283 | 14.9k | const std::string& get_index_suffix() const { return _escaped_index_suffix_path; } |
284 | | |
285 | | void set_escaped_escaped_index_suffix_path(const std::string& name); |
286 | | |
287 | | private: |
288 | | int64_t _index_id = -1; |
289 | | // Identify the different index with the same _index_id |
290 | | std::string _escaped_index_suffix_path; |
291 | | std::string _index_name; |
292 | | IndexType _index_type; |
293 | | std::vector<int32_t> _col_unique_ids; |
294 | | std::map<string, string> _properties; |
295 | | }; |
296 | | |
297 | | using TabletIndexPtr = std::shared_ptr<TabletIndex>; |
298 | | |
299 | | class TabletSchema : public MetadataAdder<TabletSchema> { |
300 | | public: |
301 | | enum ColumnType { NORMAL = 0, DROPPED = 1, VARIANT = 2 }; |
302 | | // TODO(yingchun): better to make constructor as private to avoid |
303 | | // manually init members incorrectly, and define a new function like |
304 | | // void create_from_pb(const TabletSchemaPB& schema, TabletSchema* tablet_schema). |
305 | | TabletSchema(); |
306 | | virtual ~TabletSchema(); |
307 | | |
308 | | // Init from pb |
309 | | // ignore_extracted_columns: ignore the extracted columns from variant column |
310 | | // reuse_cached_column: reuse the cached column in the schema if they are the same, to reduce memory usage |
311 | | void init_from_pb(const TabletSchemaPB& schema, bool ignore_extracted_columns = false, |
312 | | bool reuse_cached_column = false); |
313 | | // Notice: Use deterministic way to serialize protobuf, |
314 | | // since serialize Map in protobuf may could lead to un-deterministic by default |
315 | | template <class PbType> |
316 | 3.70k | static std::string deterministic_string_serialize(const PbType& pb) { |
317 | 3.70k | std::string output; |
318 | 3.70k | google::protobuf::io::StringOutputStream string_output_stream(&output); |
319 | 3.70k | google::protobuf::io::CodedOutputStream output_stream(&string_output_stream); |
320 | 3.70k | output_stream.SetSerializationDeterministic(true); |
321 | 3.70k | pb.SerializeToCodedStream(&output_stream); |
322 | 3.70k | return output; |
323 | 3.70k | } _ZN5doris12TabletSchema30deterministic_string_serializeINS_14TabletSchemaPBEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKT_ Line | Count | Source | 316 | 3.34k | static std::string deterministic_string_serialize(const PbType& pb) { | 317 | 3.34k | std::string output; | 318 | 3.34k | google::protobuf::io::StringOutputStream string_output_stream(&output); | 319 | 3.34k | google::protobuf::io::CodedOutputStream output_stream(&string_output_stream); | 320 | 3.34k | output_stream.SetSerializationDeterministic(true); | 321 | 3.34k | pb.SerializeToCodedStream(&output_stream); | 322 | 3.34k | return output; | 323 | 3.34k | } |
_ZN5doris12TabletSchema30deterministic_string_serializeINS_8ColumnPBEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKT_ Line | Count | Source | 316 | 250 | static std::string deterministic_string_serialize(const PbType& pb) { | 317 | 250 | std::string output; | 318 | 250 | google::protobuf::io::StringOutputStream string_output_stream(&output); | 319 | 250 | google::protobuf::io::CodedOutputStream output_stream(&string_output_stream); | 320 | 250 | output_stream.SetSerializationDeterministic(true); | 321 | 250 | pb.SerializeToCodedStream(&output_stream); | 322 | 250 | return output; | 323 | 250 | } |
_ZN5doris12TabletSchema30deterministic_string_serializeINS_13TabletIndexPBEEENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKT_ Line | Count | Source | 316 | 109 | static std::string deterministic_string_serialize(const PbType& pb) { | 317 | 109 | std::string output; | 318 | 109 | google::protobuf::io::StringOutputStream string_output_stream(&output); | 319 | 109 | google::protobuf::io::CodedOutputStream output_stream(&string_output_stream); | 320 | 109 | output_stream.SetSerializationDeterministic(true); | 321 | 109 | pb.SerializeToCodedStream(&output_stream); | 322 | 109 | return output; | 323 | 109 | } |
|
324 | | void to_schema_pb(TabletSchemaPB* tablet_meta_pb) const; |
325 | | void append_column(TabletColumn column, ColumnType col_type = ColumnType::NORMAL); |
326 | | void append_index(TabletIndex&& index); |
327 | | void update_index(const TabletColumn& column, const IndexType& index_type, TabletIndex&& index); |
328 | | void remove_index(int64_t index_id); |
329 | | void clear_index(); |
330 | | // Must make sure the row column is always the last column |
331 | | void add_row_column(); |
332 | | void copy_from(const TabletSchema& tablet_schema); |
333 | | // lightweight copy, take care of lifecycle of TabletColumn |
334 | | void shawdow_copy_without_columns(const TabletSchema& tablet_schema); |
335 | | void update_index_info_from(const TabletSchema& tablet_schema); |
336 | | std::string to_key() const; |
337 | | // get_metadata_size is only the memory of the TabletSchema itself, not include child objects. |
338 | 48 | int64_t mem_size() const { return get_metadata_size(); } |
339 | | size_t row_size() const; |
340 | | int32_t field_index(const std::string& field_name) const; |
341 | | int32_t field_index(const vectorized::PathInData& path) const; |
342 | | int32_t field_index(int32_t col_unique_id) const; |
343 | | const TabletColumn& column(size_t ordinal) const; |
344 | | Result<const TabletColumn*> column(const std::string& field_name) const; |
345 | | Status have_column(const std::string& field_name) const; |
346 | | bool exist_column(const std::string& field_name) const; |
347 | | bool has_column_unique_id(int32_t col_unique_id) const; |
348 | | const TabletColumn& column_by_uid(int32_t col_unique_id) const; |
349 | | TabletColumn& mutable_column_by_uid(int32_t col_unique_id); |
350 | | TabletColumn& mutable_column(size_t ordinal); |
351 | | void replace_column(size_t pos, TabletColumn new_col); |
352 | | const std::vector<TabletColumnPtr>& columns() const; |
353 | 660k | size_t num_columns() const { return _num_columns; } |
354 | 1.08M | size_t num_key_columns() const { return _num_key_columns; } |
355 | 136k | const std::vector<uint32_t>& cluster_key_uids() const { return _cluster_key_uids; } |
356 | 0 | size_t num_null_columns() const { return _num_null_columns; } |
357 | 5.04k | size_t num_short_key_columns() const { return _num_short_key_columns; } |
358 | 0 | size_t num_rows_per_row_block() const { return _num_rows_per_row_block; } |
359 | 1.27k | size_t num_variant_columns() const { return _num_variant_columns; }; |
360 | 7.11M | KeysType keys_type() const { return _keys_type; } |
361 | 5.49k | SortType sort_type() const { return _sort_type; } |
362 | 0 | size_t sort_col_num() const { return _sort_col_num; } |
363 | 0 | CompressKind compress_kind() const { return _compress_kind; } |
364 | 0 | size_t next_column_unique_id() const { return _next_column_unique_id; } |
365 | 4 | bool has_bf_fpp() const { return _has_bf_fpp; } |
366 | 4 | double bloom_filter_fpp() const { return _bf_fpp; } |
367 | 27.7k | bool is_in_memory() const { return _is_in_memory; } |
368 | 0 | void set_is_in_memory(bool is_in_memory) { _is_in_memory = is_in_memory; } |
369 | 0 | void set_disable_auto_compaction(bool disable_auto_compaction) { |
370 | 0 | _disable_auto_compaction = disable_auto_compaction; |
371 | 0 | } |
372 | 285 | bool disable_auto_compaction() const { return _disable_auto_compaction; } |
373 | 0 | void set_enable_variant_flatten_nested(bool flatten_nested) { |
374 | 0 | _enable_variant_flatten_nested = flatten_nested; |
375 | 0 | } |
376 | 0 | bool variant_flatten_nested() const { return _enable_variant_flatten_nested; } |
377 | 0 | void set_enable_single_replica_compaction(bool enable_single_replica_compaction) { |
378 | 0 | _enable_single_replica_compaction = enable_single_replica_compaction; |
379 | 0 | } |
380 | 340 | bool enable_single_replica_compaction() const { return _enable_single_replica_compaction; } |
381 | | // indicate if full row store column(all the columns encodes as row) exists |
382 | 0 | bool has_row_store_for_all_columns() const { |
383 | 0 | return _store_row_column && row_columns_uids().empty(); |
384 | 0 | } |
385 | 0 | void set_skip_write_index_on_load(bool skip) { _skip_write_index_on_load = skip; } |
386 | 63 | bool skip_write_index_on_load() const { return _skip_write_index_on_load; } |
387 | 4.15k | int32_t delete_sign_idx() const { return _delete_sign_idx; } |
388 | 0 | void set_delete_sign_idx(int32_t delete_sign_idx) { _delete_sign_idx = delete_sign_idx; } |
389 | 142k | bool has_sequence_col() const { return _sequence_col_idx != -1; } |
390 | 64.7k | int32_t sequence_col_idx() const { return _sequence_col_idx; } |
391 | 0 | void set_version_col_idx(int32_t version_col_idx) { _version_col_idx = version_col_idx; } |
392 | 0 | int32_t version_col_idx() const { return _version_col_idx; } |
393 | 0 | bool has_skip_bitmap_col() const { return _skip_bitmap_col_idx != -1; } |
394 | 0 | int32_t skip_bitmap_col_idx() const { return _skip_bitmap_col_idx; } |
395 | 4.93k | segment_v2::CompressionTypePB compression_type() const { return _compression_type; } |
396 | 0 | void set_row_store_page_size(long page_size) { _row_store_page_size = page_size; } |
397 | 0 | long row_store_page_size() const { return _row_store_page_size; } |
398 | 0 | void set_storage_page_size(long storage_page_size) { _storage_page_size = storage_page_size; } |
399 | 12.8k | long storage_page_size() const { return _storage_page_size; } |
400 | | |
401 | 88 | const std::vector<const TabletIndex*> inverted_indexes() const { |
402 | 88 | std::vector<const TabletIndex*> inverted_indexes; |
403 | 1.23k | for (const auto& index : _indexes) { |
404 | 1.23k | if (index->index_type() == IndexType::INVERTED) { |
405 | 1.23k | inverted_indexes.emplace_back(index.get()); |
406 | 1.23k | } |
407 | 1.23k | } |
408 | 88 | return inverted_indexes; |
409 | 88 | } |
410 | 10.6k | bool has_inverted_index() const { |
411 | 10.6k | for (const auto& index : _indexes) { |
412 | 640 | DBUG_EXECUTE_IF("tablet_schema::has_inverted_index", { |
413 | 640 | if (index->col_unique_ids().empty()) { |
414 | 640 | throw Exception(Status::InternalError("col unique ids cannot be empty")); |
415 | 640 | } |
416 | 640 | }); |
417 | | |
418 | 640 | if (index->index_type() == IndexType::INVERTED) { |
419 | | //if index_id == -1, ignore it. |
420 | 640 | if (!index->col_unique_ids().empty() && index->col_unique_ids()[0] >= 0) { |
421 | 640 | return true; |
422 | 640 | } |
423 | 640 | } |
424 | 640 | } |
425 | 10.0k | return false; |
426 | 10.6k | } |
427 | | bool has_inverted_index_with_index_id(int64_t index_id) const; |
428 | | // Check whether this column supports inverted index |
429 | | // Some columns (Float, Double, JSONB ...) from the variant do not support index, but they are listed in TabletIndex. |
430 | | const TabletIndex* inverted_index(const TabletColumn& col) const; |
431 | | |
432 | | // Regardless of whether this column supports inverted index |
433 | | // TabletIndex information will be returned as long as it exists. |
434 | | const TabletIndex* inverted_index(int32_t col_unique_id, |
435 | | const std::string& suffix_path = "") const; |
436 | | bool has_ngram_bf_index(int32_t col_unique_id) const; |
437 | | const TabletIndex* get_ngram_bf_index(int32_t col_unique_id) const; |
438 | | void update_indexes_from_thrift(const std::vector<doris::TOlapTableIndex>& indexes); |
439 | | // If schema version is not set, it should be -1 |
440 | 1.50k | int32_t schema_version() const { return _schema_version; } |
441 | | void clear_columns(); |
442 | | vectorized::Block create_block( |
443 | | const std::vector<uint32_t>& return_columns, |
444 | | const std::unordered_set<uint32_t>* tablet_columns_need_convert_null = nullptr) const; |
445 | | vectorized::Block create_block(bool ignore_dropped_col = true) const; |
446 | 0 | void set_schema_version(int32_t version) { _schema_version = version; } |
447 | 0 | void set_auto_increment_column(const std::string& auto_increment_column) { |
448 | 0 | _auto_increment_column = auto_increment_column; |
449 | 0 | } |
450 | 0 | std::string auto_increment_column() const { return _auto_increment_column; } |
451 | | |
452 | 28 | void set_table_id(int64_t table_id) { _table_id = table_id; } |
453 | 461 | int64_t table_id() const { return _table_id; } |
454 | 28 | void set_db_id(int64_t db_id) { _db_id = db_id; } |
455 | 0 | int64_t db_id() const { return _db_id; } |
456 | | void build_current_tablet_schema(int64_t index_id, int32_t version, |
457 | | const OlapTableIndexSchema* index, |
458 | | const TabletSchema& out_tablet_schema); |
459 | | |
460 | | // Merge columns that not exit in current schema, these column is dropped in current schema |
461 | | // but they are useful in some cases. For example, |
462 | | // 1. origin schema is ColA, ColB |
463 | | // 2. insert values 1, 2 |
464 | | // 3. delete where ColB = 2 |
465 | | // 4. drop ColB |
466 | | // 5. insert values 3 |
467 | | // 6. add column ColB, although it is name ColB, but it is different with previous ColB, the new ColB we name could call ColB' |
468 | | // 7. insert value 4, 5 |
469 | | // Then the read schema should be ColA, ColB, ColB' because the delete predicate need ColB to remove related data. |
470 | | // Because they have same name, so that the dropped column should not be added to the map, only with unique id. |
471 | | void merge_dropped_columns(const TabletSchema& src_schema); |
472 | | |
473 | | bool is_dropped_column(const TabletColumn& col) const; |
474 | | |
475 | | // copy extracted columns from src_schema |
476 | | void copy_extracted_columns(const TabletSchema& src_schema); |
477 | | |
478 | | // only reserve extracted columns |
479 | | void reserve_extracted_columns(); |
480 | | |
481 | 0 | string get_all_field_names() const { |
482 | 0 | string str = "["; |
483 | 0 | for (auto p : _field_name_to_index) { |
484 | 0 | if (str.size() > 1) { |
485 | 0 | str += ", "; |
486 | 0 | } |
487 | 0 | str += p.first.to_string() + "(" + std::to_string(_cols[p.second]->unique_id()) + ")"; |
488 | 0 | } |
489 | 0 | str += "]"; |
490 | 0 | return str; |
491 | 0 | } |
492 | | |
493 | | // Dump [(name, type, is_nullable), ...] |
494 | 0 | string dump_structure() const { |
495 | 0 | string str = "["; |
496 | 0 | for (auto p : _cols) { |
497 | 0 | if (str.size() > 1) { |
498 | 0 | str += ", "; |
499 | 0 | } |
500 | 0 | str += "("; |
501 | 0 | str += p->name(); |
502 | 0 | str += ", "; |
503 | 0 | str += TabletColumn::get_string_by_field_type(p->type()); |
504 | 0 | str += ", "; |
505 | 0 | str += "is_nullable:"; |
506 | 0 | str += (p->is_nullable() ? "true" : "false"); |
507 | 0 | str += ")"; |
508 | 0 | } |
509 | 0 | str += "]"; |
510 | 0 | return str; |
511 | 0 | } |
512 | | |
513 | 1 | string dump_full_schema() const { |
514 | 1 | string str = "["; |
515 | 4 | for (auto p : _cols) { |
516 | 4 | if (str.size() > 1) { |
517 | 3 | str += ", "; |
518 | 3 | } |
519 | 4 | ColumnPB col_pb; |
520 | 4 | p->to_schema_pb(&col_pb); |
521 | 4 | str += "("; |
522 | 4 | str += col_pb.ShortDebugString(); |
523 | 4 | str += ")"; |
524 | 4 | } |
525 | 1 | str += "]"; |
526 | 1 | return str; |
527 | 1 | } |
528 | | |
529 | | vectorized::Block create_block_by_cids(const std::vector<uint32_t>& cids) const; |
530 | | |
531 | | std::shared_ptr<TabletSchema> copy_without_variant_extracted_columns(); |
532 | 8.98k | InvertedIndexStorageFormatPB get_inverted_index_storage_format() const { |
533 | 8.98k | return _inverted_index_storage_format; |
534 | 8.98k | } |
535 | | |
536 | | void update_tablet_columns(const TabletSchema& tablet_schema, |
537 | | const std::vector<TColumn>& t_columns); |
538 | | |
539 | 0 | const std::vector<int32_t>& row_columns_uids() const { return _row_store_column_unique_ids; } |
540 | | |
541 | | int64_t get_metadata_size() const override; |
542 | | |
543 | | private: |
544 | | friend bool operator==(const TabletSchema& a, const TabletSchema& b); |
545 | | friend bool operator!=(const TabletSchema& a, const TabletSchema& b); |
546 | 0 | TabletSchema(const TabletSchema&) = default; |
547 | | |
548 | | void clear_column_cache_handlers(); |
549 | | void clear_index_cache_handlers(); |
550 | | |
551 | | KeysType _keys_type = DUP_KEYS; |
552 | | SortType _sort_type = SortType::LEXICAL; |
553 | | size_t _sort_col_num = 0; |
554 | | std::vector<TabletColumnPtr> _cols; |
555 | | std::vector<Cache::Handle*> _column_cache_handlers; |
556 | | |
557 | | std::vector<TabletIndexPtr> _indexes; |
558 | | std::vector<Cache::Handle*> _index_cache_handlers; |
559 | | std::unordered_map<StringRef, int32_t, StringRefHash> _field_name_to_index; |
560 | | std::unordered_map<int32_t, int32_t> _field_id_to_index; |
561 | | std::unordered_map<vectorized::PathInDataRef, int32_t, vectorized::PathInDataRef::Hash> |
562 | | _field_path_to_index; |
563 | | |
564 | | // index_type/col_unique_id/suffix -> idx in _indexes |
565 | | using IndexKey = std::tuple<IndexType, int32_t, std::string>; |
566 | | struct IndexKeyHash { |
567 | 48.7k | size_t operator()(const IndexKey& t) const { |
568 | 48.7k | std::size_t seed = 0; |
569 | 48.7k | seed = doris::HashUtil::hash((const char*)&std::get<0>(t), sizeof(std::get<0>(t)), |
570 | 48.7k | seed); |
571 | 48.7k | seed = doris::HashUtil::hash((const char*)&std::get<1>(t), sizeof(std::get<1>(t)), |
572 | 48.7k | seed); |
573 | 48.7k | seed = doris::HashUtil::hash((const char*)std::get<2>(t).c_str(), std::get<2>(t).size(), |
574 | 48.7k | seed); |
575 | 48.7k | return seed; |
576 | 48.7k | } |
577 | | }; |
578 | | std::unordered_map<IndexKey, int32_t, IndexKeyHash> _col_id_suffix_to_index; |
579 | | |
580 | | size_t _num_columns = 0; |
581 | | size_t _num_variant_columns = 0; |
582 | | size_t _num_key_columns = 0; |
583 | | std::vector<uint32_t> _cluster_key_uids; |
584 | | size_t _num_null_columns = 0; |
585 | | size_t _num_short_key_columns = 0; |
586 | | size_t _num_rows_per_row_block = 0; |
587 | | CompressKind _compress_kind = COMPRESS_NONE; |
588 | | segment_v2::CompressionTypePB _compression_type = segment_v2::CompressionTypePB::LZ4F; |
589 | | long _row_store_page_size = segment_v2::ROW_STORE_PAGE_SIZE_DEFAULT_VALUE; |
590 | | long _storage_page_size = segment_v2::STORAGE_PAGE_SIZE_DEFAULT_VALUE; |
591 | | size_t _next_column_unique_id = 0; |
592 | | std::string _auto_increment_column; |
593 | | |
594 | | bool _has_bf_fpp = false; |
595 | | double _bf_fpp = 0; |
596 | | bool _is_in_memory = false; |
597 | | int32_t _delete_sign_idx = -1; |
598 | | int32_t _sequence_col_idx = -1; |
599 | | int32_t _version_col_idx = -1; |
600 | | int32_t _skip_bitmap_col_idx = -1; |
601 | | int32_t _schema_version = -1; |
602 | | int64_t _table_id = -1; |
603 | | int64_t _db_id = -1; |
604 | | bool _disable_auto_compaction = false; |
605 | | bool _enable_single_replica_compaction = false; |
606 | | bool _store_row_column = false; |
607 | | bool _skip_write_index_on_load = false; |
608 | | InvertedIndexStorageFormatPB _inverted_index_storage_format = InvertedIndexStorageFormatPB::V1; |
609 | | |
610 | | // Contains column ids of which columns should be encoded into row store. |
611 | | // ATTN: For compability reason empty cids means all columns of tablet schema are encoded to row column |
612 | | std::vector<int32_t> _row_store_column_unique_ids; |
613 | | bool _enable_variant_flatten_nested = false; |
614 | | }; |
615 | | |
616 | | bool operator==(const TabletSchema& a, const TabletSchema& b); |
617 | | bool operator!=(const TabletSchema& a, const TabletSchema& b); |
618 | | |
619 | | using TabletSchemaSPtr = std::shared_ptr<TabletSchema>; |
620 | | |
621 | | } // namespace doris |