提交 36fdaab9 编写于 作者: Hanr110's avatar Hanr110 提交者: ob-robot

[CP] to issue<56141233>:add sys_var influencing cache to pl cache key & fix case when issue

上级 1f14c6e8
......@@ -408,10 +408,16 @@ int ObGVSql::fill_cells(const ObILibCacheObject *cache_obj, const ObPlanCache &p
case share::ALL_VIRTUAL_PLAN_STAT_CDE::SYS_VARS: {
if (!cache_stat_updated) {
cells[i].set_null();
} else if (cache_obj->is_sql_crsr()) {
ObString sys_vars_str;
} else if (cache_obj->is_sql_crsr() ||
NULL != pl_object) {
ObString sys_vars_str, origin_str;
if (cache_obj->is_sql_crsr()) {
origin_str = plan->stat_.sys_vars_str_;
} else {
origin_str = pl_object->get_stat().sys_vars_str_;
}
if (OB_FAIL(ob_write_string(*allocator_,
plan->stat_.sys_vars_str_,
origin_str,
sys_vars_str))) {
SERVER_LOG(ERROR, "copy sys_vars_str failed", K(ret));
} else {
......
......@@ -4268,6 +4268,9 @@ int ObPLResolver::resolve_when(const ObStmtNodeTree *parse_tree, ObRawExpr *case
OZ (func.add_expr(expr));
OZ (expr->formalize(&resolve_ctx_.session_info_));
if (!is_bool_stmt && lib::is_mysql_mode()) {
OZ (set_cm_warn_on_fail(expr));
}
OZ (stmt->add_when_clause(func.get_expr_count() - 1, body));
}
}
......
......@@ -255,6 +255,7 @@ void ObPLObjectKey::reset()
sessid_ = 0;
name_.reset();
namespace_ = ObLibCacheNameSpace::NS_INVALID;
sys_vars_str_.reset();
}
int ObPLObjectKey::deep_copy(ObIAllocator &allocator, const ObILibCacheKey &other)
......@@ -263,6 +264,8 @@ int ObPLObjectKey::deep_copy(ObIAllocator &allocator, const ObILibCacheKey &othe
const ObPLObjectKey &key = static_cast<const ObPLObjectKey&>(other);
if (OB_FAIL(common::ob_write_string(allocator, key.name_, name_))) {
LOG_WARN("failed to deep copy name", K(ret), K(name_));
} else if (OB_FAIL(common::ob_write_string(allocator, key.sys_vars_str_, sys_vars_str_))) {
LOG_WARN("failed to deep copy name", K(ret), K(name_));
} else {
db_id_ = key.db_id_;
key_id_ = key.key_id_;
......@@ -277,6 +280,9 @@ void ObPLObjectKey::destory(common::ObIAllocator &allocator)
if (nullptr != name_.ptr()) {
allocator.free(const_cast<char *>(name_.ptr()));
}
if (nullptr != sys_vars_str_.ptr()) {
allocator.free(const_cast<char *>(sys_vars_str_.ptr()));
}
}
uint64_t ObPLObjectKey::hash() const
......@@ -286,6 +292,7 @@ uint64_t ObPLObjectKey::hash() const
hash_ret = murmurhash(&sessid_, sizeof(uint32_t), hash_ret);
hash_ret = name_.hash(hash_ret);
hash_ret = murmurhash(&namespace_, sizeof(ObLibCacheNameSpace), hash_ret);
hash_ret = sys_vars_str_.hash(hash_ret);
return hash_ret;
}
......@@ -296,7 +303,8 @@ bool ObPLObjectKey::is_equal(const ObILibCacheKey &other) const
key_id_ == key.key_id_ &&
sessid_ == key.sessid_ &&
name_ == key.name_ &&
namespace_ == key.namespace_;
namespace_ == key.namespace_ &&
sys_vars_str_ == key.sys_vars_str_;
return cmp_ret;
}
......
......@@ -206,13 +206,15 @@ struct ObPLObjectKey : public ObILibCacheKey
db_id_(common::OB_INVALID_ID),
key_id_(common::OB_INVALID_ID),
sessid_(0),
name_() {}
name_(),
sys_vars_str_() {}
ObPLObjectKey(uint64_t db_id, uint64_t key_id)
: ObILibCacheKey(ObLibCacheNameSpace::NS_INVALID),
db_id_(db_id),
key_id_(key_id),
sessid_(0),
name_() {}
name_(),
sys_vars_str_() {}
void reset();
virtual int deep_copy(common::ObIAllocator &allocator, const ObILibCacheKey &other) override;
......@@ -229,6 +231,7 @@ struct ObPLObjectKey : public ObILibCacheKey
uint64_t key_id_; // routine id or package id
uint32_t sessid_;
common::ObString name_;
common::ObString sys_vars_str_;
};
......
......@@ -27,13 +27,14 @@ int ObPLCacheMgr::get_pl_object(ObPlanCache *lib_cache, ObILibCacheCtx &ctx, ObC
{
int ret = OB_SUCCESS;
FLTSpanGuard(pc_get_pl_object);
ObPLCacheCtx &pc_ctx = static_cast<ObPLCacheCtx&>(ctx);
//guard.get_cache_obj() = NULL;
ObGlobalReqTimeService::check_req_timeinfo();
if (OB_ISNULL(lib_cache)) {
if (OB_ISNULL(lib_cache) || OB_ISNULL(pc_ctx.session_info_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("lib cache is null");
} else {
ObPLCacheCtx &pc_ctx = static_cast<ObPLCacheCtx&>(ctx);
pc_ctx.key_.sys_vars_str_ = pc_ctx.session_info_->get_sys_var_in_pc_str();
if (OB_FAIL(lib_cache->get_cache_obj(ctx, &pc_ctx.key_, guard))) {
PL_CACHE_LOG(DEBUG, "failed to get plan", K(ret));
// if schema expired, update pl cache;
......@@ -106,14 +107,15 @@ int ObPLCacheMgr::add_pl_object(ObPlanCache *lib_cache,
ObILibCacheObject *cache_obj)
{
int ret = OB_SUCCESS;
ObPLCacheCtx &pc_ctx = static_cast<ObPLCacheCtx&>(ctx);
if (OB_ISNULL(cache_obj)) {
ret = OB_INVALID_ARGUMENT;
PL_CACHE_LOG(WARN, "invalid cache obj", K(ret));
} else if (OB_ISNULL(lib_cache)) {
} else if (OB_ISNULL(lib_cache) || OB_ISNULL(pc_ctx.session_info_)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("lib cache is null");
} else {
ObPLCacheCtx &pc_ctx = static_cast<ObPLCacheCtx&>(ctx);
pc_ctx.key_.sys_vars_str_ = pc_ctx.session_info_->get_sys_var_in_pc_str();
do {
if (OB_FAIL(lib_cache->add_cache_obj(ctx, &pc_ctx.key_, cache_obj)) && OB_OLD_SCHEMA_VERSION == ret) {
PL_CACHE_LOG(INFO, "schema in pl cache value is old, start to remove pl object", K(ret), K(pc_ctx.key_));
......
......@@ -134,6 +134,10 @@ int ObPLCacheObject::update_cache_obj_stat(sql::ObILibCacheCtx &ctx)
trunc_name_sql.string(),
stat.name_))) {
LOG_WARN("failed to write sql", K(ret));
} else if (OB_FAIL(ob_write_string(get_allocator(),
pc_ctx.key_.sys_vars_str_,
stat_.sys_vars_str_))) {
LOG_WARN("failed to write sql", K(ret));
} else {
stat.sql_cs_type_ = pc_ctx.session_info_->get_local_collation_connection();
}
......
......@@ -88,6 +88,7 @@ struct PLCacheObjStat
uint64_t slowest_exec_usec_; // execution slowest usec
int64_t schema_version_;
int64_t ps_stmt_id_;//prepare stmt id
common::ObString sys_vars_str_;
PLCacheObjStat()
: pl_schema_id_(OB_INVALID_ID),
......@@ -104,7 +105,8 @@ struct PLCacheObjStat
slowest_exec_time_(0),
slowest_exec_usec_(0),
schema_version_(OB_INVALID_ID),
ps_stmt_id_(OB_INVALID_ID)
ps_stmt_id_(OB_INVALID_ID),
sys_vars_str_()
{
sql_id_[0] = '\0';
}
......@@ -131,6 +133,7 @@ struct PLCacheObjStat
slowest_exec_usec_ = 0;
schema_version_ = OB_INVALID_ID;
ps_stmt_id_ = OB_INVALID_ID;
sys_vars_str_.reset();
}
TO_STRING_KV(K_(pl_schema_id),
......@@ -141,7 +144,8 @@ struct PLCacheObjStat
K_(name),
K_(compile_time),
K_(type),
K_(schema_version));
K_(schema_version),
K_(sys_vars_str));
};
class ObPLCacheObject : public sql::ObILibCacheObject
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册