Skip to content

Commit

Permalink
[CP] The internal SQL of udf cannot hit the plan cache
Browse files Browse the repository at this point in the history
  • Loading branch information
obdev authored and ob-robot committed Oct 19, 2023
1 parent c6d616f commit 8d4a0a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/sql/ob_sql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,7 @@ int ObSql::handle_pl_execute(const ObString &sql,
LOG_WARN("failed to init result set", K(ret));
} else {
context.cur_sql_ = sql;
context.is_from_pl_ = true;
context.is_dynamic_sql_ = is_dynamic_sql;
context.is_prepare_protocol_ = is_prepare_protocol;
context.disable_privilege_check_ = OB_SYS_TENANT_ID == session.get_priv_tenant_id()
Expand Down Expand Up @@ -4177,7 +4178,7 @@ int ObSql::parser_and_check(const ObString &outlined_stmt,

if (OB_SUCC(ret)) {
//租户级别的read only检查
if (session->is_inner() || pc_ctx.is_begin_commit_stmt()) {
if ((session->is_inner() && !pc_ctx.sql_ctx_.is_from_pl_) || pc_ctx.is_begin_commit_stmt()) {
// FIXME:
// schema拆分后,为了避免建租户时获取不到租户read only属性导致建租户失败,对于inner sql
// 暂时跳过read only检查。实际上,对于tenant space系统表,不应该检查read only属性。
Expand Down
3 changes: 2 additions & 1 deletion src/sql/ob_sql_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@ struct ObSqlCtx
struct {
uint32_t enable_strict_defensive_check_: 1; //TRUE if the _enable_defensive_check is '2'
uint32_t enable_user_defined_rewrite_ : 1;//TRUE if enable_user_defined_rewrite_rules is open
uint32_t reserved_ : 30;
uint32_t is_from_pl_ : 1;
uint32_t reserved_ : 29;
};
};
private:
Expand Down
14 changes: 9 additions & 5 deletions src/sql/plan_cache/ob_plan_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,13 @@ int ObPlanCache::get_plan(common::ObIAllocator &allocator,
if (GCONF.enable_perf_event) {
uint64_t tenant_id = pc_ctx.sql_ctx_.session_info_->get_effective_tenant_id();
bool read_only = false;
if (OB_FAIL(pc_ctx.sql_ctx_.schema_guard_->get_tenant_read_only(tenant_id, read_only))) {
if ((pc_ctx.sql_ctx_.session_info_->is_inner() && !pc_ctx.sql_ctx_.is_from_pl_)) {
// do nothing
} else if (OB_FAIL(pc_ctx.sql_ctx_.schema_guard_->get_tenant_read_only(tenant_id,
read_only))) {
LOG_WARN("failed to check read_only privilege", K(ret));
} else if (OB_FAIL(pc_ctx.sql_ctx_.session_info_->check_read_only_privilege(
read_only, pc_ctx.sql_traits_))) {
read_only, pc_ctx.sql_traits_))) {
LOG_WARN("failed to check read_only privilege", K(ret));
}
}
Expand Down Expand Up @@ -2175,7 +2178,6 @@ int ObPlanCache::get_ps_plan(ObCacheObjGuard& guard,
int ret = OB_SUCCESS;
ObGlobalReqTimeService::check_req_timeinfo();
UNUSED(stmt_id);
ObSqlTraits sql_traits;
pc_ctx.handle_id_ = guard.ref_handle_;
int64_t original_param_cnt = 0;

Expand Down Expand Up @@ -2228,10 +2230,12 @@ int ObPlanCache::get_ps_plan(ObCacheObjGuard& guard,
if (OB_SUCC(ret) && GCONF.enable_perf_event) {
uint64_t tenant_id = pc_ctx.sql_ctx_.session_info_->get_effective_tenant_id();
bool read_only = false;
if (OB_FAIL(pc_ctx.sql_ctx_.schema_guard_->get_tenant_read_only(tenant_id, read_only))) {
if ((pc_ctx.sql_ctx_.session_info_->is_inner() && !pc_ctx.sql_ctx_.is_from_pl_)) {
// do nothing
} else if (OB_FAIL(pc_ctx.sql_ctx_.schema_guard_->get_tenant_read_only(tenant_id, read_only))) {
SQL_PC_LOG(WARN, "fail to get tenant read only attribute", K(tenant_id), K(ret));
} else if (OB_FAIL(pc_ctx.sql_ctx_.session_info_->check_read_only_privilege(read_only,
sql_traits))) {
pc_ctx.sql_traits_))) {
SQL_PC_LOG(WARN, "failed to check read_only privilege", K(ret));
}
}
Expand Down

0 comments on commit 8d4a0a5

Please sign in to comment.