From 6ecc0292a5f7f4a763ae2c3249ccaea8add6af68 Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 1 Nov 2023 07:10:00 +0000 Subject: [PATCH] [CP] The internal SQL of udf cannot hit the plan cache --- src/sql/ob_sql.cpp | 3 ++- src/sql/ob_sql_context.h | 3 ++- src/sql/plan_cache/ob_plan_cache.cpp | 14 +++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/sql/ob_sql.cpp b/src/sql/ob_sql.cpp index 5513934f7b..27c7ef1240 100644 --- a/src/sql/ob_sql.cpp +++ b/src/sql/ob_sql.cpp @@ -1511,6 +1511,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.spm_ctx_.bl_key_.db_id_ = session.get_database_id(); @@ -4173,7 +4174,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属性。 diff --git a/src/sql/ob_sql_context.h b/src/sql/ob_sql_context.h index 5ef385ee43..9da137bae2 100644 --- a/src/sql/ob_sql_context.h +++ b/src/sql/ob_sql_context.h @@ -634,7 +634,8 @@ public: 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: diff --git a/src/sql/plan_cache/ob_plan_cache.cpp b/src/sql/plan_cache/ob_plan_cache.cpp index a949a29bbb..96a8020a15 100644 --- a/src/sql/plan_cache/ob_plan_cache.cpp +++ b/src/sql/plan_cache/ob_plan_cache.cpp @@ -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)); } } @@ -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; @@ -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)); } }