diff --git a/src/observer/virtual_table/ob_gv_sql.cpp b/src/observer/virtual_table/ob_gv_sql.cpp index 0f06dc97d5e40f77218b8dcf4fb3d2f5a88974e0..efdabe346c17ee2705e5e9d31eddc4230a92f0a7 100644 --- a/src/observer/virtual_table/ob_gv_sql.cpp +++ b/src/observer/virtual_table/ob_gv_sql.cpp @@ -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 { diff --git a/src/pl/ob_pl_resolver.cpp b/src/pl/ob_pl_resolver.cpp index 82cbfbf1eaf57db771efdc9055c35069f6acc188..813bae80ceb4b623c6a9a6bb7f62f9ab8591399d 100644 --- a/src/pl/ob_pl_resolver.cpp +++ b/src/pl/ob_pl_resolver.cpp @@ -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)); } } diff --git a/src/pl/pl_cache/ob_pl_cache.cpp b/src/pl/pl_cache/ob_pl_cache.cpp index feff01be9cddbfc04d67dd4c9320e17d9698d515..414232c28847055b18ec436edee59f4e58131b18 100644 --- a/src/pl/pl_cache/ob_pl_cache.cpp +++ b/src/pl/pl_cache/ob_pl_cache.cpp @@ -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(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(name_.ptr())); } + if (nullptr != sys_vars_str_.ptr()) { + allocator.free(const_cast(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; } diff --git a/src/pl/pl_cache/ob_pl_cache.h b/src/pl/pl_cache/ob_pl_cache.h index 965fd6abf0ff7e68464f6f0cd4ba96d5f76f8da2..7e3cf7f2d1e4485d37cd0563295efd3e11c14e61 100644 --- a/src/pl/pl_cache/ob_pl_cache.h +++ b/src/pl/pl_cache/ob_pl_cache.h @@ -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_; }; diff --git a/src/pl/pl_cache/ob_pl_cache_mgr.cpp b/src/pl/pl_cache/ob_pl_cache_mgr.cpp index 972c2ff5185a40ad0983b7682f77146a4fb116e2..7850eac59a025bdd60157e9f28076f2087d33556 100644 --- a/src/pl/pl_cache/ob_pl_cache_mgr.cpp +++ b/src/pl/pl_cache/ob_pl_cache_mgr.cpp @@ -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(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(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(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(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_)); diff --git a/src/pl/pl_cache/ob_pl_cache_object.cpp b/src/pl/pl_cache/ob_pl_cache_object.cpp index a7b057f08c2cbab9f9ef142d45c6ab4e96a77fcf..0788d6683c711a46f02738170bb07a616ae4e373 100644 --- a/src/pl/pl_cache/ob_pl_cache_object.cpp +++ b/src/pl/pl_cache/ob_pl_cache_object.cpp @@ -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(); } diff --git a/src/pl/pl_cache/ob_pl_cache_object.h b/src/pl/pl_cache/ob_pl_cache_object.h index 3d29cff5180aece9373a4279f308febc3ef34fde..76abd94e562c07137697dc6755408ac69d43fd6f 100644 --- a/src/pl/pl_cache/ob_pl_cache_object.h +++ b/src/pl/pl_cache/ob_pl_cache_object.h @@ -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