Coverage Report

Created: 2026-07-03 09:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/schema.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 "storage/schema.h"
19
20
#include <glog/logging.h>
21
22
#include <boost/iterator/iterator_facade.hpp>
23
#include <ostream>
24
#include <unordered_set>
25
#include <utility>
26
27
#include "common/config.h"
28
#include "core/column/column_array.h"
29
#include "core/column/column_decimal.h"
30
#include "core/column/column_dictionary.h"
31
#include "core/column/column_map.h"
32
#include "core/column/column_nullable.h"
33
#include "core/column/column_string.h"
34
#include "core/column/column_struct.h"
35
#include "core/column/column_vector.h"
36
#include "core/data_type/data_type.h"
37
#include "core/data_type/data_type_factory.hpp"
38
#include "core/data_type/define_primitive_type.h"
39
#include "core/types.h"
40
#include "storage/olap_common.h"
41
#include "util/trace.h"
42
43
namespace doris {
44
45
5
Schema::Schema(const Schema& other) {
46
5
    _copy_from(other);
47
5
}
48
49
0
Schema& Schema::operator=(const Schema& other) {
50
0
    if (this != &other) {
51
0
        _copy_from(other);
52
0
    }
53
0
    return *this;
54
0
}
55
56
5
void Schema::_copy_from(const Schema& other) {
57
5
    _col_ids = other._col_ids;
58
5
    _column_id_to_index = other._column_id_to_index;
59
5
    _num_key_columns = other._num_key_columns;
60
5
    _delete_sign_idx = other._delete_sign_idx;
61
5
    _has_sequence_col = other._has_sequence_col;
62
5
    _rowid_col_idx = other._rowid_col_idx;
63
5
    _version_col_idx = other._version_col_idx;
64
5
    _lsn_col_idx = other._lsn_col_idx;
65
5
    _tso_col_idx = other._tso_col_idx;
66
67
5
    _cols.resize(other._cols.size());
68
15
    for (auto cid : _col_ids) {
69
15
        _cols[cid] = other._cols[cid];
70
15
    }
71
5
}
72
73
void Schema::_init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids,
74
13.4M
                   size_t num_key_columns) {
75
13.4M
    _col_ids = col_ids;
76
13.4M
    _num_key_columns = num_key_columns;
77
78
13.4M
    _cols.resize(cols.size());
79
80
13.4M
    std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end());
81
13.4M
    _column_id_to_index.assign(cols.size(), -1);
82
123M
    for (size_t i = 0; i < col_ids.size(); ++i) {
83
110M
        _column_id_to_index[col_ids[i]] = static_cast<int>(i);
84
110M
    }
85
86
193M
    for (int cid = 0; cid < cols.size(); ++cid) {
87
180M
        if (col_id_set.find(cid) == col_id_set.end()) {
88
70.2M
            continue;
89
70.2M
        }
90
109M
        _cols[cid] = cols[cid];
91
109M
    }
92
13.4M
}
93
94
13.4M
Schema::~Schema() = default;
95
96
64.9M
DataTypePtr Schema::get_data_type_ptr(const TabletColumn& column) {
97
64.9M
    return DataTypeFactory::instance().create_data_type(column);
98
64.9M
}
99
100
IColumn::MutablePtr Schema::get_predicate_column_ptr(const DataTypePtr& data_type,
101
1.82M
                                                     const ReaderType reader_type) {
102
    // Low-cardinality dictionary optimization substitutes a ColumnDictI32 for the
103
    // canonical string column during query reads. Every other case just materializes
104
    // the data type's own canonical column (which already wraps nullable for us).
105
1.83M
    if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY &&
106
1.82M
        is_string_type(data_type->get_primitive_type())) {
107
15.0k
        IColumn::MutablePtr ptr = doris::ColumnDictI32::create();
108
15.0k
        if (data_type->is_nullable()) {
109
6.19k
            return doris::ColumnNullable::create(std::move(ptr), doris::ColumnUInt8::create());
110
6.19k
        }
111
8.86k
        return ptr;
112
15.0k
    }
113
1.81M
    return data_type->create_column();
114
1.82M
}
115
116
} // namespace doris