[CP] [#2024082800104288965]Use definer db_id as part of pl cache key for pl obj with definer right.

This commit is contained in:
bit-dance 2025-01-06 03:44:57 +00:00 committed by ob-robot
parent 03efb49b25
commit 8f352ed2be
4 changed files with 50 additions and 1 deletions

View File

@ -1380,7 +1380,7 @@ int ObPLContext::set_default_database(ObPLFunction &routine,
bool need_set_db = true;
// in mysql mode, only system packages with invoker's right do not need set db
// in oracle mode, set db by if the routine is invoker's right
// in oracle mode, set db by if the routine is definer's right
if (lib::is_oracle_mode()
|| get_tenant_id_by_object_id(routine.get_package_id()) == OB_SYS_TENANT_ID) {
need_set_db = !routine.is_invoker_right();

View File

@ -1291,5 +1291,47 @@ int64_t ObPLObjectSet::get_mem_size()
return value_mem_size;
}
int ObPLCacheCtx::adjust_definer_database_id()
{
int ret = OB_SUCCESS;
ObLibCacheNameSpace ns = key_.namespace_;
uint64_t key_id = key_.key_id_;
#define TRANS_DB_ID(type) \
do { \
OZ(schema_guard_->get_##type##_info(get_tenant_id_by_object_id(key_id), \
key_id, tmp_##type##_info)); \
CK(OB_NOT_NULL(tmp_##type##_info)); \
if (OB_FAIL(ret)) { \
} else if (!tmp_##type##_info->is_invoker_right()) { \
key_.db_id_ = tmp_##type##_info->get_database_id(); \
} \
} while (0)
switch (ns) {
case NS_PRCR:
case NS_SFC: {
// proc/func
const ObRoutineInfo* tmp_routine_info = NULL;
TRANS_DB_ID(routine);
break;
}
case NS_PKG: {
// package/udt/trigger
if (ObUDTObjectType::is_object_id_masked(key_id)) {
// TODO: udt info need set is_invoker_right flag
LOG_WARN("udt can not adjust db id for definer, will create new cache node", K(key_id));
} else {
const ObPackageInfo* tmp_package_info = NULL;
TRANS_DB_ID(package);
}
break;
}
default: {
// do nothing
}
}
#undef TRANS_DB_ID
return ret;
}
}
}

View File

@ -380,6 +380,7 @@ struct ObPLCacheCtx : public ObILibCacheCtx
ParamStore *cache_params_;
ObString raw_sql_;
int64_t compile_time_; // pl object cost time of compile
int adjust_definer_database_id();
};

View File

@ -85,6 +85,9 @@ int ObPLCacheMgr::get_pl_cache(ObPlanCache *lib_cache, ObCacheObjGuard& guard, O
if (OB_NOT_NULL(pc_ctx.session_info_) &&
false == pc_ctx.session_info_->get_local_ob_enable_pl_cache()) {
// do nothing
} else if (OB_FAIL(pc_ctx.adjust_definer_database_id())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("reset db_id failed!", K(ret));
} else if (OB_FAIL(get_pl_object(lib_cache, pc_ctx, guard))) {
PL_CACHE_LOG(DEBUG, "fail to get plan", K(ret));
} else if (OB_ISNULL(guard.get_cache_obj())) {
@ -176,6 +179,9 @@ int ObPLCacheMgr::add_pl_cache(ObPlanCache *lib_cache, ObILibCacheObject *pl_obj
}
if (OB_FAIL(ret)) {
} else if (FALSE_IT(pc_ctx.key_.namespace_ = ns)) {
} else if (OB_FAIL(pc_ctx.adjust_definer_database_id())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("reset db_id failed!", K(ret));
} else if (OB_FAIL(add_pl_object(lib_cache, pc_ctx, pl_object))) {
if (!is_not_supported_err(ret)
&& OB_SQL_PC_PLAN_DUPLICATE != ret) {