开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from OceanBase/oceanbase
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (7)
标签 (19)
master
3.1
4.1
4.2
4.0
None
oceanbase_competition
v4.1.0_CE_BP1
v3.1.5_CE
v4.1.0_CE
v4.1.0_CE_BETA
v3.1.4_CE_BP3
v4.0.0_CE_BP3
v4.0.0_CE_BP2
v3.1.4_CE_BP2
v4.0.0_CE_BP1
v4.0.0_CE
v3.1.4_CE_BP1
v3.1.4_CE
v3.1.3_CE_BP1
v3.1.3_CE
v3.1.2_CE
v3.1.1_CE_BP1
v3.1.1_CE
v3.1.0_CE_BP2
v3.1.0_CE_BP1
master
分支 (7)
标签 (19)
master
3.1
4.1
4.2
4.0
None
oceanbase_competition
v4.1.0_CE_BP1
v3.1.5_CE
v4.1.0_CE
v4.1.0_CE_BETA
v3.1.4_CE_BP3
v4.0.0_CE_BP3
v4.0.0_CE_BP2
v3.1.4_CE_BP2
v4.0.0_CE_BP1
v4.0.0_CE
v3.1.4_CE_BP1
v3.1.4_CE
v3.1.3_CE_BP1
v3.1.3_CE
v3.1.2_CE
v3.1.1_CE_BP1
v3.1.1_CE
v3.1.0_CE_BP2
v3.1.0_CE_BP1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (7)
标签 (19)
master
3.1
4.1
4.2
4.0
None
oceanbase_competition
v4.1.0_CE_BP1
v3.1.5_CE
v4.1.0_CE
v4.1.0_CE_BETA
v3.1.4_CE_BP3
v4.0.0_CE_BP3
v4.0.0_CE_BP2
v3.1.4_CE_BP2
v4.0.0_CE_BP1
v4.0.0_CE
v3.1.4_CE_BP1
v3.1.4_CE
v3.1.3_CE_BP1
v3.1.3_CE
v3.1.2_CE
v3.1.1_CE_BP1
v3.1.1_CE
v3.1.0_CE_BP2
v3.1.0_CE_BP1
oceanbase
/
src
/
sql
/
ob_sql_context.cpp
oceanbase
/
src
/
sql
/
ob_sql_context.cpp
ob_sql_context.cpp 25.35 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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
/**
* 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_RESV
#include "sql/ob_sql_context.h"
#include <algorithm>
#include "lib/container/ob_se_array_iterator.h"
#include "sql/resolver/dml/ob_sql_hint.h"
#include "sql/ob_sql_define.h"
#include "sql/optimizer/ob_log_plan.h"
#include "share/schema/ob_schema_getter_guard.h"
#include "sql/dblink/ob_dblink_utils.h"
#include "src/storage/tx/ob_trans_define_v4.h"
using namespace ::oceanbase::common;
namespace oceanbase
{
using namespace share::schema;
namespace sql
{
bool LocationConstraint::operator==(const LocationConstraint &other) const {
return key_ == other.key_ && phy_loc_type_ == other.phy_loc_type_ && constraint_flags_ == other.constraint_flags_ ;
}
bool LocationConstraint::operator!=(const LocationConstraint &other) const {
return !(*this == other);
}
int LocationConstraint::calc_constraints_inclusion(const ObLocationConstraint *left,
const ObLocationConstraint *right,
InclusionType &inclusion_result)
{
int ret = OB_SUCCESS;
inclusion_result = NotSubset;
if (OB_ISNULL(left) || OB_ISNULL(right)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(left), K(right));
} else {
const ObLocationConstraint *set1 = NULL, *set2 = NULL;
bool is_subset = true;
// insure set1.count() >= set2.count()
if (left->count() >= right->count()) {
inclusion_result = LeftIsSuperior;
set1 = left;
set2 = right;
} else {
inclusion_result = RightIsSuperior;
set1 = right;
set2 = left;
}
for (int64_t i = 0; is_subset && i < set2->count(); i++) {
bool detected = false;
for (int64_t j = 0; !detected && j < set1->count(); j++) {
if (set2->at(i) == set1->at(j)) {
detected = true;
}
}
// if the element is not in set1, set1 can not contain all the elements in set2
if (!detected) {
is_subset = false;
}
}
if (!is_subset) {
inclusion_result = NotSubset;
}
}
return ret;
}
int ObLocationConstraintContext::calc_constraints_inclusion(const ObPwjConstraint *left,
const ObPwjConstraint *right,
InclusionType &inclusion_result)
{
int ret = OB_SUCCESS;
inclusion_result = NotSubset;
if (OB_ISNULL(left) || OB_ISNULL(right)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), K(left), K(right));
} else {
const ObPwjConstraint *set1 = NULL, *set2 = NULL;
bool is_subset = true;
// insure set1.count() >= set2.count()
if (left->count() >= right->count()) {
inclusion_result = LeftIsSuperior;
set1 = left;
set2 = right;
} else {
inclusion_result = RightIsSuperior;
set1 = right;
set2 = left;
}
for (int64_t i = 0; is_subset && i < set2->count(); i++) {
bool detected = false;
for (int64_t j = 0; !detected && j < set1->count(); j++) {
if (set2->at(i) == set1->at(j)) {
detected = true;
}
}
// if the element is not in set1, set1 can not contain all the elements in set2
if (!detected) {
is_subset = false;
}
}
if (!is_subset) {
inclusion_result = NotSubset;
}
}
return ret;
}
int ObQueryRetryInfo::init()
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(inited_)) {
ret = OB_INIT_TWICE;
LOG_ERROR("init twice", K(ret));
} else {
inited_ = true;
}
return ret;
}
void ObQueryRetryInfo::reset()
{
inited_ = false;
is_rpc_timeout_ = false;
last_query_retry_err_ = OB_SUCCESS;
retry_cnt_ = 0;
query_switch_leader_retry_timeout_ts_ = 0;
}
void ObQueryRetryInfo::clear()
{
// 这里不能将inited_设为false
is_rpc_timeout_ = false;
//last_query_retry_err_ = OB_SUCCESS;
}
void ObQueryRetryInfo::set_is_rpc_timeout(bool is_rpc_timeout)
{
is_rpc_timeout_ = is_rpc_timeout;
}
bool ObQueryRetryInfo::is_rpc_timeout() const
{
return is_rpc_timeout_;
}
ObSqlCtx::ObSqlCtx()
: session_info_(NULL),
schema_guard_(NULL),
secondary_namespace_(NULL),
plan_cache_hit_(false),
self_add_plan_(false),
disable_privilege_check_(PRIV_CHECK_FLAG_NORMAL),
force_print_trace_(false),
is_show_trace_stmt_(false),
retry_times_(OB_INVALID_COUNT),
exec_type_(InvalidType),
is_prepare_protocol_(false),
is_pre_execute_(false),
is_prepare_stage_(false),
is_dynamic_sql_(false),
is_dbms_sql_(false),
is_cursor_(false),
is_remote_sql_(false),
statement_id_(common::OB_INVALID_ID),
stmt_type_(stmt::T_NONE),
is_restore_(false),
need_late_compile_(false),
all_plan_const_param_constraints_(nullptr),
all_possible_const_param_constraints_(nullptr),
all_equal_param_constraints_(nullptr),
all_pre_calc_constraints_(nullptr),
all_expr_constraints_(nullptr),
all_priv_constraints_(nullptr),
need_match_all_params_(false),
is_ddl_from_primary_(false),
cur_stmt_(NULL),
cur_plan_(nullptr),
can_reroute_sql_(false),
is_sensitive_(false),
is_protocol_weak_read_(false),
flashback_query_expr_(nullptr),
is_execute_call_stmt_(false),
enable_sql_resource_manage_(false),
res_map_rule_id_(OB_INVALID_ID),
res_map_rule_param_idx_(OB_INVALID_INDEX),
res_map_rule_version_(0),
is_text_ps_mode_(false),
first_plan_hash_(0),
is_bulk_(false),
ins_opt_ctx_(),
flags_(0),
reroute_info_(nullptr)
{
sql_id_[0] = '0円';
sql_id_[common::OB_MAX_SQL_ID_LENGTH] = '0円';
}
void ObSqlCtx::reset()
{
multi_stmt_item_.reset();
session_info_ = NULL;
schema_guard_ = NULL;
plan_cache_hit_ = false;
self_add_plan_ = false;
disable_privilege_check_ = PRIV_CHECK_FLAG_NORMAL;
force_print_trace_ = false;
is_show_trace_stmt_ = false;
retry_times_ = OB_INVALID_COUNT;
sql_id_[0] = '0円';
sql_id_[common::OB_MAX_SQL_ID_LENGTH] = '0円';
exec_type_ = InvalidType;
is_prepare_protocol_ = false;
is_pre_execute_ = false;
is_prepare_stage_ = false;
is_dynamic_sql_ = false;
is_remote_sql_ = false;
is_restore_ = false;
need_late_compile_ = false;
all_plan_const_param_constraints_ = nullptr;
all_possible_const_param_constraints_ = nullptr;
all_equal_param_constraints_ = nullptr;
all_pre_calc_constraints_ = nullptr;
all_expr_constraints_ = nullptr;
all_priv_constraints_ = nullptr;
need_match_all_params_ = false;
is_ddl_from_primary_ = false;
can_reroute_sql_ = false;
is_sensitive_ = false;
enable_sql_resource_manage_ = false;
res_map_rule_id_ = OB_INVALID_ID;
res_map_rule_param_idx_ = OB_INVALID_INDEX;
res_map_rule_version_ = 0;
is_protocol_weak_read_ = false;
first_plan_hash_ = 0;
first_outline_data_.reset();
if (nullptr != reroute_info_) {
reroute_info_->reset();
op_reclaim_free(reroute_info_);
reroute_info_ = nullptr;
}
clear();
flashback_query_expr_ = nullptr;
stmt_type_ = stmt::T_NONE;
cur_plan_ = nullptr;
is_execute_call_stmt_ = false;
is_text_ps_mode_ = false;
enable_strict_defensive_check_ = false;
enable_user_defined_rewrite_ = false;
is_bulk_ = false;
ins_opt_ctx_.reset();
}
//release dynamic allocated memory
void ObSqlCtx::clear()
{
partition_infos_.reset();
related_user_var_names_.reset();
base_constraints_.reset();
strict_constraints_.reset();
non_strict_constraints_.reset();
dup_table_replica_cons_.reset();
multi_stmt_rowkey_pos_.reset();
spm_ctx_.bl_key_.reset();
cur_stmt_ = nullptr;
is_text_ps_mode_ = false;
ins_opt_ctx_.clear();
}
OB_SERIALIZE_MEMBER(ObSqlCtx, stmt_type_);
void ObSqlSchemaGuard::reset()
{
table_schemas_.reset();
schema_guard_ = NULL;
allocator_.reset();
next_link_table_id_ = 1;
dblink_scn_.reuse();
}
TableItem *ObSqlSchemaGuard::get_table_item_by_ref_id(const ObDMLStmt *stmt, uint64_t ref_table_id)
{
TableItem *table_item = NULL;
if (NULL != stmt) {
const common::ObIArray<sql::TableItem*> &table_items = stmt->get_table_items();
int64_t num = table_items.count();
for (int64_t i = 0; i < num; ++i) {
if (table_items.at(i) != NULL && table_items.at(i)->ref_id_ == ref_table_id) {
table_item = table_items.at(i);
break;
}
}
}
return table_item;
}
bool ObSqlSchemaGuard::is_link_table(const ObDMLStmt *stmt, uint64_t table_id)
{
bool is_link = false;
TableItem *table_item = NULL;
if (NULL != stmt) {
table_item = stmt->get_table_item_by_id(table_id);
is_link = (NULL == table_item) ? false : table_item->is_link_table();
}
return is_link;
}
int ObSqlSchemaGuard::get_dblink_schema(const uint64_t tenant_id,
const uint64_t dblink_id,
const share::schema::ObDbLinkSchema *&dblink_schema)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(schema_guard_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpect null schema guard", K(ret));
} else if (OB_FAIL(schema_guard_->get_dblink_schema(tenant_id,
dblink_id,
dblink_schema))) {
LOG_WARN("failed to get dblink schema", K(ret));
}
return ret;
}
int ObSqlSchemaGuard::set_link_table_schema(uint64_t dblink_id,
const common::ObString &database_name,
share::schema::ObTableSchema *table_schema)
{
int ret = OB_SUCCESS;
table_schema->set_dblink_id(dblink_id);
table_schema->set_table_type(share::schema::ObTableType::USER_TABLE);
OX(table_schema->set_link_database_name(database_name);)
OX (table_schema->set_table_id(next_link_table_id_++));
OX (table_schema->set_link_table_id(table_schema->get_table_id()));
OV (table_schema->get_table_id() != OB_INVALID_ID,
OB_ERR_UNEXPECTED, dblink_id, next_link_table_id_);
if (OB_FAIL(table_schemas_.push_back(table_schema))) {
LOG_WARN("failed to push back table schema", K(ret));
}
return ret;
}
int ObSqlSchemaGuard::get_table_schema(uint64_t dblink_id,
const ObString &database_name,
const ObString &table_name,
const ObTableSchema *&table_schema,
sql::ObSQLSessionInfo *session_info,
const ObString &dblink_name,
bool is_reverse_link)
{
int ret = OB_SUCCESS;
int64_t schema_count = table_schemas_.count();
table_schema = NULL;
const uint64_t tenant_id = MTL_ID();
for (int64_t i = 0; OB_SUCC(ret) && OB_ISNULL(table_schema) && i < schema_count; i++) {
// database_name和table_name直接调用compare接口,使用memcmp语义比较,避免多字符集导致各种问题。
const ObTableSchema *tmp_schema = table_schemas_.at(i);
OV (OB_NOT_NULL(tmp_schema));
if (OB_SUCC(ret) && dblink_id == tmp_schema->get_dblink_id() &&
0 == database_name.compare(tmp_schema->get_link_database_name()) &&
0 == table_name.compare(tmp_schema->get_table_name_str())) {
table_schema = tmp_schema;
}
}
if (OB_SUCC(ret) && OB_ISNULL(table_schema)) {
ObTableSchema *tmp_schema = NULL;
OV (OB_NOT_NULL(schema_guard_), OB_NOT_INIT);
uint64_t current_scn = OB_INVALID_ID;
uint64_t *scn = NULL;
if (OB_SUCC(ret)) {
if (OB_ISNULL(session_info)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session info is null", K(ret));
} else {
bool use_scn = (session_info->is_in_transaction() &&
transaction::ObTxIsolationLevel::RC == session_info->get_tx_desc()->get_isolation_level())
|| !session_info->is_in_transaction();
if (use_scn && OB_FAIL(get_link_current_scn(dblink_id, tenant_id, session_info, current_scn))) {
if (OB_HASH_NOT_EXIST == ret) {
scn = &current_scn;
ret = OB_SUCCESS;
} else {
LOG_WARN("get link current scn failed", K(ret));
}
}
}
}
OZ (schema_guard_->get_link_table_schema(tenant_id,
dblink_id,
database_name, table_name,
allocator_, tmp_schema,
session_info,
dblink_name,
is_reverse_link,
scn));
if (OB_SUCC(ret) && (NULL != scn)) {
if (OB_FAIL(dblink_scn_.set_refactored(dblink_id, *scn))) {
LOG_WARN("set refactored failed", K(ret));
} else {
LOG_TRACE("set dblink current scn", K(dblink_id), K(*scn));
}
}
OV (OB_NOT_NULL(tmp_schema));
OX (tmp_schema->set_table_id(next_link_table_id_++));
OX (tmp_schema->set_link_table_id(tmp_schema->get_table_id()));
OV (tmp_schema->get_table_id() != OB_INVALID_ID,
OB_ERR_UNEXPECTED, dblink_id, next_link_table_id_);
OZ (table_schemas_.push_back(tmp_schema));
OX (table_schema = tmp_schema);
}
return ret;
}
int ObSqlSchemaGuard::get_table_schema(uint64_t table_id,
uint64_t ref_table_id,
const ObDMLStmt *stmt,
const ObTableSchema *&table_schema)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(stmt)) {
ret = OB_INVALID_ARGUMENT;;
LOG_WARN("get unexpected null", K(ret), K(stmt));
} else {
const TableItem *item = stmt->get_table_item_by_id(table_id);
if (NULL != item && item->is_link_table()) {
if (OB_FAIL(get_link_table_schema(ref_table_id, table_schema))) {
LOG_WARN("failed to get link table schema", K(table_id), K(ret));
}
} else if (OB_FAIL(get_table_schema(ref_table_id, table_schema))) {
LOG_WARN("failed to get table schema", K(table_id), K(ret));
}
}
return ret;
}
int ObSqlSchemaGuard::get_table_schema(uint64_t table_id,
const TableItem *table_item,
const ObTableSchema *&table_schema)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(table_item) ) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("get unexpected null", K(ret), K(table_item));
} else if (table_item->is_link_table()) {
if (OB_FAIL(get_link_table_schema(table_id, table_schema))) {
LOG_WARN("failed to get link table schema", K(table_id), K(ret));
}
} else if (OB_FAIL(get_table_schema(table_id, table_schema))) {
LOG_WARN("failed to get table schema", K(table_id), K(ret));
}
return ret;
}
int ObSqlSchemaGuard::get_table_schema(uint64_t table_id,
const ObTableSchema *&table_schema,
bool is_link /* = false*/) const
{
int ret = OB_SUCCESS;
if (is_link) {
OZ (get_link_table_schema(table_id, table_schema), table_id, is_link);
} else {
const uint64_t tenant_id = MTL_ID();
OV (OB_NOT_NULL(schema_guard_));
OZ (schema_guard_->get_table_schema(tenant_id, table_id, table_schema), table_id, is_link);
}
return ret;
}
int ObSqlSchemaGuard::get_column_schema(uint64_t table_id, const ObString &column_name,
const ObColumnSchemaV2 *&column_schema,
bool is_link /* = false */) const
{
int ret = OB_SUCCESS;
if (is_link) {
OZ (get_link_column_schema(table_id, column_name, column_schema),
table_id, column_name, is_link);
} else {
const uint64_t tenant_id = MTL_ID();
OV (OB_NOT_NULL(schema_guard_));
OZ (schema_guard_->get_column_schema(tenant_id, table_id, column_name, column_schema),
table_id, column_name, is_link);
}
return ret;
}
int ObSqlSchemaGuard::get_column_schema(uint64_t table_id, uint64_t column_id,
const ObColumnSchemaV2 *&column_schema,
bool is_link /* = false */) const
{
int ret = OB_SUCCESS;
if (is_link) {
OZ (get_link_column_schema(table_id, column_id, column_schema),
table_id, column_id, is_link);
} else {
const uint64_t tenant_id = MTL_ID();
OV (OB_NOT_NULL(schema_guard_));
OZ (schema_guard_->get_column_schema(tenant_id, table_id, column_id, column_schema),
table_id, column_id, is_link);
}
return ret;
}
int ObSqlSchemaGuard::get_table_schema_version(const uint64_t table_id,
int64_t &schema_version) const
{
int ret = OB_SUCCESS;
const uint64_t tenant_id = MTL_ID();
OV (OB_NOT_NULL(schema_guard_));
OZ (schema_guard_->get_schema_version(TABLE_SCHEMA, tenant_id, table_id, schema_version), table_id);
return ret;
}
int ObSqlSchemaGuard::get_can_read_index_array(uint64_t table_id,
uint64_t *index_tid_array,
int64_t &size,
bool with_mv,
bool with_global_index,
bool with_domain_index,
bool with_spatial_index)
{
int ret = OB_SUCCESS;
const uint64_t tenant_id = MTL_ID();
OV (OB_NOT_NULL(schema_guard_));
OZ (schema_guard_->get_can_read_index_array(tenant_id, table_id,
index_tid_array, size, with_mv,
with_global_index, with_domain_index,
with_spatial_index));
return ret;
}
int ObSqlSchemaGuard::get_link_table_schema(uint64_t table_id,
const ObTableSchema *&table_schema) const
{
int ret = OB_SUCCESS;
int64_t schema_count = table_schemas_.count();
const ObTableSchema *tmp_schema = NULL;
table_schema = NULL;
for (int64_t i = 0; OB_SUCC(ret) && OB_ISNULL(table_schema) && i < schema_count; i++) {
OX (tmp_schema = table_schemas_.at(i));
OV (OB_NOT_NULL(tmp_schema));
if (OB_SUCC(ret) && table_id == tmp_schema->get_table_id()) {
table_schema = tmp_schema;
}
}
return ret;
}
int ObSqlSchemaGuard::get_link_column_schema(uint64_t table_id, const ObString &column_name,
const ObColumnSchemaV2 *&column_schema) const
{
int ret = OB_SUCCESS;
const ObTableSchema *table_schema = NULL;
OZ (get_link_table_schema(table_id, table_schema), table_id);
if (OB_NOT_NULL(table_schema)) {
OX (column_schema = table_schema->get_column_schema(column_name));
}
return ret;
}
int ObSqlSchemaGuard::get_link_column_schema(uint64_t table_id, uint64_t column_id,
const ObColumnSchemaV2 *&column_schema) const
{
int ret = OB_SUCCESS;
const ObTableSchema *table_schema = NULL;
OZ (get_link_table_schema(table_id, table_schema), table_id);
if (OB_NOT_NULL(table_schema)) {
OX (column_schema = table_schema->get_column_schema(column_id));
}
return ret;
}
int ObSqlSchemaGuard::get_link_current_scn(uint64_t dblink_id, uint64_t tenant_id,
ObSQLSessionInfo *session_info,
uint64_t &current_scn)
{
int ret = OB_SUCCESS;
current_scn = OB_INVALID_ID;
if (!dblink_scn_.created()) {
if (OB_FAIL(dblink_scn_.create(4, "DblinkScnMap", "DblinkScnMap", tenant_id))) {
LOG_WARN("create hash map failed", K(ret));
} else {
ret = OB_HASH_NOT_EXIST;
}
} else {
if (OB_FAIL(dblink_scn_.get_refactored(dblink_id, current_scn))) {
if (OB_HASH_NOT_EXIST != ret) {
LOG_WARN("get dblink scn failed", K(ret));
}
}
}
return ret;
}
int ObSqlCtx::set_partition_infos(const ObTablePartitionInfoArray &info, ObIAllocator &allocator)
{
int ret = OB_SUCCESS;
int64_t count = info.count();
partition_infos_.reset();
if (count > 0) {
partition_infos_.set_allocator(&allocator);
if (OB_FAIL(partition_infos_.init(count))) {
LOG_WARN("init partition info failed", K(ret), K(count));
} else {
for (int64_t i = 0; i < count && OB_SUCC(ret); ++i) {
if (OB_FAIL(partition_infos_.push_back(info.at(i)))) {
LOG_WARN("push partition info failed", K(ret), K(count));
}
}
}
}
return ret;
}
int ObSqlCtx::set_related_user_var_names(const ObIArray<ObString> &user_var_names,
ObIAllocator &allocator)
{
int ret = OB_SUCCESS;
if (user_var_names.count() > 0) {
related_user_var_names_.reset();
related_user_var_names_.set_allocator(&allocator);
if (OB_FAIL(related_user_var_names_.init(user_var_names.count()))) {
LOG_WARN("failed to init related_user_var_names", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < user_var_names.count(); i++) {
if (OB_FAIL(related_user_var_names_.push_back(user_var_names.at(i)))) {
LOG_WARN("failed to push back user var names", K(ret));
}
}
}
}
if (OB_FAIL(ret)) {
related_user_var_names_.reset();
}
return ret;
}
int ObSqlCtx::set_location_constraints(const ObLocationConstraintContext &location_constraint,
ObIAllocator &allocator)
{
int ret = OB_SUCCESS;
base_constraints_.reset();
strict_constraints_.reset();
non_strict_constraints_.reset();
dup_table_replica_cons_.reset();
const ObIArray<LocationConstraint> &base_constraints = location_constraint.base_table_constraints_;
const ObIArray<ObPwjConstraint *> &strict_constraints = location_constraint.strict_constraints_;
const ObIArray<ObPwjConstraint *> &non_strict_constraints = location_constraint.non_strict_constraints_;
const ObIArray<ObDupTabConstraint> &dup_table_replica_cons = location_constraint.dup_table_replica_cons_;
if (base_constraints.count() > 0) {
base_constraints_.set_allocator(&allocator);
if (OB_FAIL(base_constraints_.init(base_constraints.count()))) {
LOG_WARN("init base constraints failed", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < base_constraints.count(); i++) {
if (OB_FAIL(base_constraints_.push_back(base_constraints.at(i)))) {
LOG_WARN("failed to push back base constraint", K(ret));
} else {
// table_partition_info_仅在计划生成阶段使用
base_constraints_.at(i).table_partition_info_ = NULL;
}
}
LOG_DEBUG("set base constraints", K(base_constraints.count()));
}
}
if (OB_SUCC(ret) && strict_constraints.count() > 0) {
strict_constraints_.set_allocator(&allocator);
if (OB_FAIL(strict_constraints_.init(strict_constraints.count()))) {
LOG_WARN("init strict constraints failed", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < strict_constraints.count(); i++) {
if (OB_FAIL(strict_constraints_.push_back(strict_constraints.at(i)))) {
LOG_WARN("failed to push back location constraint", K(ret));
}
}
LOG_DEBUG("set strict constraints", K(strict_constraints.count()));
}
}
if (OB_SUCC(ret) && non_strict_constraints.count() > 0) {
non_strict_constraints_.set_allocator(&allocator);
if (OB_FAIL(non_strict_constraints_.init(non_strict_constraints.count()))) {
LOG_WARN("init non strict constraints failed", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < non_strict_constraints.count(); i++) {
if (OB_FAIL(non_strict_constraints_.push_back(non_strict_constraints.at(i)))) {
LOG_WARN("failed to push back location constraint", K(ret));
}
}
LOG_DEBUG("set non strict constraints", K(non_strict_constraints.count()));
}
}
if (OB_SUCC(ret) && dup_table_replica_cons.count() > 0) {
dup_table_replica_cons_.set_allocator(&allocator);
if (OB_FAIL(dup_table_replica_cons_.init(dup_table_replica_cons.count()))) {
LOG_WARN("init duplicate table replica constraints failed", K(ret));
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < dup_table_replica_cons.count(); i++) {
if (OB_FAIL(dup_table_replica_cons_.push_back(dup_table_replica_cons.at(i)))) {
LOG_WARN("failed to push back location constraint", K(ret));
}
}
LOG_DEBUG("set duplicate table replica constraints", K(dup_table_replica_cons.count()));
}
}
return ret;
}
int ObSqlCtx::set_multi_stmt_rowkey_pos(const common::ObIArray<int64_t> &multi_stmt_rowkey_pos,
common::ObIAllocator &alloctor)
{
int ret = OB_SUCCESS;
if (!multi_stmt_rowkey_pos.empty()) {
multi_stmt_rowkey_pos_.set_allocator(&alloctor);
if (OB_FAIL(multi_stmt_rowkey_pos_.init(multi_stmt_rowkey_pos.count()))) {
LOG_WARN("failed to init rowkey count", K(ret));
} else if (OB_FAIL(append(multi_stmt_rowkey_pos_, multi_stmt_rowkey_pos))) {
LOG_WARN("failed to append multi stmt rowkey pos", K(ret));
} else { /*do nothing*/ }
}
return ret;
}
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

OceanBase is an enterprise distributed relational database with high availability, high performance, horizontal scalability and compatibility with SQL standards.
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/mobnet/oceanbase.git
git@gitee.com:mobnet/oceanbase.git
mobnet
oceanbase
oceanbase
master
点此查找更多帮助

搜索帮助

仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /