/root/doris/be/src/storage/schema.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #pragma once |
19 | | |
20 | | #include <stddef.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include <algorithm> |
24 | | #include <cstdint> |
25 | | #include <memory> |
26 | | #include <string> |
27 | | #include <vector> |
28 | | |
29 | | #include "common/consts.h" |
30 | | #include "core/column/column.h" |
31 | | #include "exprs/aggregate/aggregate_function.h" |
32 | | #include "io/io_common.h" |
33 | | #include "runtime/thread_context.h" |
34 | | #include "storage/olap_common.h" |
35 | | #include "storage/tablet/tablet_schema.h" |
36 | | #include "storage/utils.h" |
37 | | |
38 | | namespace doris { |
39 | | |
40 | | #include "common/compile_check_begin.h" |
41 | | |
42 | | // The class is used to represent row's format in memory. Each row contains |
43 | | // multiple columns, some of which are key-columns (the rest are value-columns). |
44 | | // NOTE: If both key-columns and value-columns exist, then the key-columns |
45 | | // must be placed before value-columns. |
46 | | // |
47 | | // To compare two rows whose schemas are different, but they are from the same origin |
48 | | // we store all column schema maybe accessed here. And default access through column id |
49 | | class Schema; |
50 | | using SchemaSPtr = std::shared_ptr<const Schema>; |
51 | | class Schema { |
52 | | public: |
53 | | // All the columns of one table may exist in the columns param, but col_ids is only a subset. |
54 | 7.00k | Schema(const std::vector<TabletColumnPtr>& columns, const std::vector<ColumnId>& col_ids) { |
55 | 7.00k | size_t num_key_columns = 0; |
56 | 68.8k | for (int i = 0; i < columns.size(); ++i) { |
57 | 61.8k | if (columns[i]->is_key()) { |
58 | 5.43k | ++num_key_columns; |
59 | 5.43k | } |
60 | 61.8k | if (columns[i]->name() == DELETE_SIGN) { |
61 | 1.74k | _delete_sign_idx = i; |
62 | 1.74k | } |
63 | 61.8k | if (columns[i]->name() == BeConsts::ROWID_COL || |
64 | 61.8k | columns[i]->name().starts_with(BeConsts::GLOBAL_ROWID_COL)) { |
65 | 0 | _rowid_col_idx = i; |
66 | 0 | } |
67 | 61.8k | if (columns[i]->name() == VERSION_COL) { |
68 | 0 | _version_col_idx = i; |
69 | 0 | } |
70 | 61.8k | } |
71 | 7.00k | _init(columns, col_ids, num_key_columns); |
72 | 7.00k | } |
73 | | |
74 | | Schema(const Schema&); |
75 | | Schema& operator=(const Schema& other); |
76 | | |
77 | | ~Schema(); |
78 | | |
79 | | static DataTypePtr get_data_type_ptr(const TabletColumn& column); |
80 | | |
81 | | static IColumn::MutablePtr get_predicate_column_ptr(const FieldType& type, bool is_nullable, |
82 | | const ReaderType reader_type); |
83 | | |
84 | 63.0k | const std::vector<TabletColumnPtr>& columns() const { return _cols; } |
85 | | |
86 | 1.10M | const TabletColumn* column(ColumnId cid) const { return _cols[cid].get(); } |
87 | | |
88 | 1.48k | size_t num_key_columns() const { return _num_key_columns; } |
89 | | |
90 | 13.3k | size_t num_columns() const { return _cols.size(); } |
91 | 988k | size_t num_column_ids() const { return _col_ids.size(); } |
92 | 48.0k | const std::vector<ColumnId>& column_ids() const { return _col_ids; } |
93 | 50.0k | ColumnId column_id(size_t index) const { return _col_ids[index]; } |
94 | 0 | int32_t delete_sign_idx() const { return _delete_sign_idx; } |
95 | 0 | bool has_sequence_col() const { return _has_sequence_col; } |
96 | 3.04k | int32_t rowid_col_idx() const { return _rowid_col_idx; } |
97 | 8.23k | int32_t version_col_idx() const { return _version_col_idx; } |
98 | | // Don't use. |
99 | | // TODO: memory size of Schema cannot be accurately tracked. |
100 | | // In some places, temporarily use num_columns() as Schema size. |
101 | 0 | int64_t mem_size() const { return _mem_size; } |
102 | | |
103 | | private: |
104 | | void _init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids, |
105 | | size_t num_key_columns); |
106 | | |
107 | | void _copy_from(const Schema& other); |
108 | | |
109 | | // NOTE: The ColumnId here represents the sequential index number (starting from 0) of |
110 | | // a column in current row, not the unique id-identifier of each column |
111 | | std::vector<ColumnId> _col_ids; |
112 | | // NOTE: _cols[cid] can only be accessed when the cid is |
113 | | // contained in _col_ids |
114 | | std::vector<TabletColumnPtr> _cols; |
115 | | |
116 | | size_t _num_key_columns; |
117 | | int32_t _delete_sign_idx = -1; |
118 | | bool _has_sequence_col = false; |
119 | | int32_t _rowid_col_idx = -1; |
120 | | int32_t _version_col_idx = -1; |
121 | | int64_t _mem_size = 0; |
122 | | }; |
123 | | |
124 | | #include "common/compile_check_end.h" |
125 | | |
126 | | } // namespace doris |