forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_index_info_cache.cpp
More file actions
142 lines (133 loc) · 4.5 KB
/
Copy pathob_index_info_cache.cpp
File metadata and controls
142 lines (133 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SQL_OPT
#include "ob_index_info_cache.h"
#include "sql/resolver/dml/ob_dml_stmt.h"
namespace oceanbase
{
using namespace common;
namespace sql
{
ObIndexInfoCache::~ObIndexInfoCache()
{
for (int i = 0; i < entry_count_; ++i) {
if (NULL != index_entrys_[i]) {
index_entrys_[i]->~IndexInfoEntry();
}
}
}
int ObIndexInfoCache::get_index_info_entry(const uint64_t table_id,
const uint64_t index_id,
IndexInfoEntry *&entry,
int64_t *idx) const
{
int ret = OB_SUCCESS;
entry = NULL;
if (table_id != table_id_ ||
OB_UNLIKELY(OB_INVALID_ID == index_id)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table_id is invalid", K(index_id), K_(table_id), K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < entry_count_; ++i) {
if (OB_ISNULL(index_entrys_[i])) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("entry should not be null", K(ret));
} else if (index_entrys_[i]->get_index_id() == index_id) {
entry = index_entrys_[i];
if (idx != nullptr) {
*idx = i;
}
break;
}
}
}
return ret;
}
int ObIndexInfoCache::get_query_range(const uint64_t table_id,
const uint64_t index_id,
const QueryRangeInfo *&range_info) const
{
int ret = OB_SUCCESS;
range_info = NULL;
if (table_id != table_id_) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table_id is invalid", K(table_id), K_(table_id), K(ret));
} else {
IndexInfoEntry *entry = NULL;
if (OB_FAIL(get_index_info_entry(table_id, index_id, entry))) {
LOG_WARN("failed to get index_info entry", K(index_id), K(ret));
} else if (OB_ISNULL(entry)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("entry should not be null", K(ret));
} else if (entry->get_range_info().is_valid()){
range_info = &entry->get_range_info();
} else {
LOG_TRACE("entry is invalid", K(table_id), K(index_id));
}
}
return ret;
}
/*
* This interface is the same as get_access_path_ordering in ob_join_order.cpp, it just gets the ordering info from the cache
* */
int ObIndexInfoCache::get_access_path_ordering(const uint64_t table_id,
const uint64_t index_id,
const OrderingInfo *&ordering_info) const
{
int ret = OB_SUCCESS;
ordering_info = NULL;
if (table_id != table_id_) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("table_id is invalid", K(table_id), K_(table_id), K(ret));
} else {
IndexInfoEntry *entry = NULL;
if (OB_FAIL(get_index_info_entry(table_id, index_id, entry))) {
LOG_WARN("failed to get index_info entry", K(index_id), K(ret));
} else if (OB_ISNULL(entry)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("entry should not be null", K(ret));
} else {
ordering_info = &entry->get_ordering_info();
}
}
return ret;
}
int ObIndexInfoCache::add_index_info_entry(IndexInfoEntry *entry)
{
int ret = OB_SUCCESS;
IndexInfoEntry *old_entry;
int64_t idx = OB_INVALID_INDEX;
if (OB_ISNULL(entry)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("entry should not be null", K(ret));
} else if (OB_FAIL(get_index_info_entry(table_id_, entry->get_index_id(), old_entry, &idx))) {
LOG_WARN("failed to get index info entry", KPC(entry), K(ret));
} else if (old_entry != nullptr) {
// update index info entry
old_entry->~IndexInfoEntry();
index_entrys_[idx] = entry;
} else if (entry_count_ >= OB_MAX_AUX_TABLE_PER_MAIN_TABLE + 1) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid entry count", K(ret), K_(entry_count),
K(OB_MAX_AUX_TABLE_PER_MAIN_TABLE));
} else {
index_entrys_[entry_count_] = entry;
++entry_count_;
}
return ret;
}
} //end of namespace sql
} //end of namespace oceanbase