Coverage Report

Created: 2026-06-17 21:35

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
    _num_key_columns = other._num_key_columns;
59
5
    _delete_sign_idx = other._delete_sign_idx;
60
5
    _has_sequence_col = other._has_sequence_col;
61
5
    _rowid_col_idx = other._rowid_col_idx;
62
5
    _version_col_idx = other._version_col_idx;
63
5
    _lsn_col_idx = other._lsn_col_idx;
64
5
    _tso_col_idx = other._tso_col_idx;
65
66
5
    _cols.resize(other._cols.size());
67
15
    for (auto cid : _col_ids) {
68
15
        _cols[cid] = other._cols[cid];
69
15
    }
70
5
}
71
72
void Schema::_init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids,
73
12.5M
                   size_t num_key_columns) {
74
12.5M
    _col_ids = col_ids;
75
12.5M
    _num_key_columns = num_key_columns;
76
77
12.5M
    _cols.resize(cols.size());
78
79
12.5M
    std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end());
80
184M
    for (int cid = 0; cid < cols.size(); ++cid) {
81
171M
        if (col_id_set.find(cid) == col_id_set.end()) {
82
68.0M
            continue;
83
68.0M
        }
84
103M
        _cols[cid] = cols[cid];
85
103M
    }
86
12.5M
}
87
88
12.5M
Schema::~Schema() = default;
89
90
62.4M
DataTypePtr Schema::get_data_type_ptr(const TabletColumn& column) {
91
62.4M
    return DataTypeFactory::instance().create_data_type(column);
92
62.4M
}
93
94
IColumn::MutablePtr Schema::get_predicate_column_ptr(const DataTypePtr& data_type,
95
1.77M
                                                     const ReaderType reader_type) {
96
    // Low-cardinality dictionary optimization substitutes a ColumnDictI32 for the
97
    // canonical string column during query reads. Every other case just materializes
98
    // the data type's own canonical column (which already wraps nullable for us).
99
1.77M
    if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY &&
100
1.77M
        is_string_type(data_type->get_primitive_type())) {
101
14.7k
        IColumn::MutablePtr ptr = doris::ColumnDictI32::create();
102
14.7k
        if (data_type->is_nullable()) {
103
6.30k
            return doris::ColumnNullable::create(std::move(ptr), doris::ColumnUInt8::create());
104
6.30k
        }
105
8.41k
        return ptr;
106
14.7k
    }
107
1.76M
    return data_type->create_column();
108
1.77M
}
109
110
} // namespace doris