forked from oceanbase/oceanbase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathob_index_info_cache.cpp
More file actions
126 lines (117 loc) · 3.95 KB
/
Copy pathob_index_info_cache.cpp
File metadata and controls
126 lines (117 loc) · 3.95 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
/**
* Copyright (c) 2021 OceanBase
* OceanBase CE is licensed under Mulan PubL v2.
* You can use this software according to the terms and conditions of the Mulan PubL v2.
* You may obtain a copy of Mulan PubL v2 at:
* http://license.coscl.org.cn/MulanPubL-2.0
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#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) 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];
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;
}
/*
* 这个接口和ob_join_order.cpp 的 get_access_path_ordering一样,只是从cache里面拿到ordering info
* */
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;
if (OB_ISNULL(entry)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("entry should not be null", K(ret));
} else if (entry_count_ >= common::OB_MAX_INDEX_PER_TABLE + 1) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid entry count", K(ret), K_(entry_count),
K(common::OB_MAX_INDEX_PER_TABLE));
} else {
index_entrys_[entry_count_] = entry;
++entry_count_;
}
return ret;
}
} //end of namespace sql
} //end of namespace oceanbase