[CP] fix session var solidify ap-sysbench bugs
Co-authored-by: 2149 <260391947@qq.com>
This commit is contained in:
parent
028f6e1373
commit
3f6e55f2bc
@ -747,16 +747,85 @@ int ObExprUtil::convert_utf8_charset(ObIAllocator& allocator,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSolidifiedVarsContext::get_local_tz_info(const sql::ObBasicSessionInfo *session, const common::ObTimeZoneInfo *&tz_info)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
tz_info = NULL;
|
||||
if (NULL != local_session_var_ && NULL == local_tz_wrap_) {
|
||||
ObSessionSysVar *local_var = NULL;
|
||||
//init local tz_wrap
|
||||
if (OB_FAIL(local_session_var_->get_local_var(SYS_VAR_TIME_ZONE, local_var))) {
|
||||
LOG_WARN("get local var failed", K(ret));
|
||||
} else if (NULL != local_var) {
|
||||
const ObTZInfoMap *tz_info_map = NULL;
|
||||
if (OB_ISNULL(tz_info_map = session->get_timezone_info()->get_tz_info_map())) {
|
||||
ObTZMapWrap tz_map_wrap;
|
||||
if (OB_SUCC(OTTZ_MGR.get_tenant_tz(session->get_effective_tenant_id(), tz_map_wrap))) {
|
||||
tz_info_map = tz_map_wrap.get_tz_map();
|
||||
} else {
|
||||
LOG_WARN("get tz info map failed", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_ISNULL(local_tz_wrap_ = OB_NEWx(ObTimeZoneInfoWrap, alloc_))) {
|
||||
LOG_WARN("alloc tz wrap failed", K(ret));
|
||||
} else if (OB_FAIL(local_tz_wrap_->init_time_zone(local_var->val_.get_string(),
|
||||
OB_INVALID_VERSION,
|
||||
*(const_cast<ObTZInfoMap *>(tz_info_map))))) {
|
||||
LOG_WARN("tz_wrap init_time_zone failed", K(ret), K(local_var->val_.get_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (NULL != local_tz_wrap_) {
|
||||
tz_info = local_tz_wrap_->get_time_zone_info();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
OB_DEF_SERIALIZE(ObSolidifiedVarsContext)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL != local_session_var_) {
|
||||
OB_UNIS_ENCODE(*local_session_var_);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
OB_DEF_SERIALIZE_SIZE(ObSolidifiedVarsContext)
|
||||
{
|
||||
int64_t len = 0;
|
||||
if (NULL != local_session_var_) {
|
||||
OB_UNIS_ADD_LEN(*local_session_var_);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
OB_DEF_DESERIALIZE(ObSolidifiedVarsContext)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (NULL != local_session_var_) {
|
||||
OB_UNIS_DECODE(*local_session_var_);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
DEF_TO_STRING(ObSolidifiedVarsContext)
|
||||
{
|
||||
int64_t pos = 0;
|
||||
J_OBJ_START();
|
||||
J_KV(K_(local_session_var));
|
||||
J_OBJ_END();
|
||||
return pos;
|
||||
}
|
||||
|
||||
ObSolidifiedVarsGetter::ObSolidifiedVarsGetter(const ObExpr &expr, const ObEvalCtx &ctx, const ObBasicSessionInfo *session)
|
||||
:local_session_var_(NULL),
|
||||
session_(session),
|
||||
local_tz_wrap_()
|
||||
: local_session_var_(NULL),
|
||||
session_(session)
|
||||
{
|
||||
ObPhysicalPlanCtx * phy_ctx = ctx.exec_ctx_.get_physical_plan_ctx();
|
||||
if (OB_NOT_NULL(phy_ctx)) {
|
||||
const ObLocalSessionVar * local_var = NULL;
|
||||
if (OB_SUCCESS == (phy_ctx->get_local_session_vars(expr.local_session_var_id_, local_var))) {
|
||||
local_session_var_ = local_var;
|
||||
if (OB_SUCCESS == (phy_ctx->get_local_session_vars(expr.local_session_var_id_, local_session_var_))) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -772,7 +841,8 @@ int ObSolidifiedVarsGetter::get_dtc_params(ObDataTypeCastParams &dtc_params)
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else if (OB_FAIL(get_time_zone_info(tz_info))) {
|
||||
LOG_WARN("get time zone info failed", K(ret));
|
||||
} else if (OB_FAIL(ObSQLUtils::merge_solidified_var_into_dtc_params(local_session_var_,
|
||||
} else if (NULL != local_session_var_
|
||||
&& OB_FAIL(ObSQLUtils::merge_solidified_var_into_dtc_params(local_session_var_->get_local_vars(),
|
||||
tz_info,
|
||||
dtc_params))) {
|
||||
LOG_WARN("fail to create local dtc params", K(ret));
|
||||
@ -785,34 +855,15 @@ int ObSolidifiedVarsGetter::get_time_zone_info(const common::ObTimeZoneInfo *&tz
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_valid = false;
|
||||
ObSessionSysVar *local_var = NULL;
|
||||
tz_info = NULL;
|
||||
if (OB_ISNULL(session_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else if (NULL == local_session_var_) {
|
||||
} else if (NULL != local_session_var_
|
||||
&& OB_FAIL(const_cast<ObSolidifiedVarsContext *>(local_session_var_)->get_local_tz_info(session_, tz_info))) {
|
||||
LOG_WARN("get local tz_info failed", K(ret));
|
||||
} else if (NULL == tz_info) {
|
||||
tz_info = session_->get_timezone_info();
|
||||
} else if (OB_FAIL(get_local_var(SYS_VAR_TIME_ZONE, local_var))) {
|
||||
LOG_WARN("get local var failed", K(ret));
|
||||
} else if (NULL == local_var) {
|
||||
tz_info = session_->get_timezone_info();
|
||||
} else {
|
||||
const ObTZInfoMap * tz_info_map = NULL;
|
||||
if (OB_ISNULL(tz_info_map = session_->get_timezone_info()->get_tz_info_map())) {
|
||||
ObTZMapWrap tz_map_wrap;
|
||||
if (OB_SUCC(OTTZ_MGR.get_tenant_tz(session_->get_effective_tenant_id(), tz_map_wrap))) {
|
||||
tz_info_map = tz_map_wrap.get_tz_map();
|
||||
} else {
|
||||
LOG_WARN("get tz info map failed", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(local_tz_wrap_.init_time_zone(local_var->val_.get_string(),
|
||||
OB_INVALID_VERSION,
|
||||
*(const_cast<ObTZInfoMap *>(tz_info_map))))) {
|
||||
LOG_WARN("tz_wrap init_time_zone failed", K(ret), K(local_var->val_.get_string()));
|
||||
} else {
|
||||
tz_info = local_tz_wrap_.get_time_zone_info();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -825,8 +876,9 @@ int ObSolidifiedVarsGetter::get_sql_mode(ObSQLMode &sql_mode)
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else if (FALSE_IT(sql_mode = session_->get_sql_mode())) {
|
||||
} else if (OB_FAIL(ObSQLUtils::merge_solidified_var_into_sql_mode(local_session_var_,
|
||||
sql_mode))) {
|
||||
} else if (NULL != local_session_var_
|
||||
&& OB_FAIL(ObSQLUtils::merge_solidified_var_into_sql_mode(local_session_var_->get_local_vars(),
|
||||
sql_mode))) {
|
||||
LOG_WARN("try get local sql mode failed", K(ret));
|
||||
}
|
||||
return ret;
|
||||
@ -892,7 +944,8 @@ int ObSolidifiedVarsGetter::get_local_var(ObSysVarClassType var_type, ObSessionS
|
||||
int ret = OB_SUCCESS;
|
||||
sys_var = NULL;
|
||||
if (NULL != local_session_var_
|
||||
&& OB_FAIL(local_session_var_->get_local_var(var_type, sys_var))) {
|
||||
&& NULL != local_session_var_->get_local_vars()
|
||||
&& OB_FAIL(local_session_var_->get_local_vars()->get_local_var(var_type, sys_var))) {
|
||||
LOG_WARN("fail to get local var", K(ret));
|
||||
}
|
||||
return ret;
|
||||
@ -933,7 +986,8 @@ int ObSolidifiedVarsGetter::get_max_allowed_packet(int64_t &max_size)
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else if (FALSE_IT(session_->get_max_allowed_packet(max_size))) {
|
||||
} else if (OB_FAIL(ObSQLUtils::merge_solidified_var_into_max_allowed_packet(local_session_var_,
|
||||
} else if (NULL != local_session_var_
|
||||
&& OB_FAIL(ObSQLUtils::merge_solidified_var_into_max_allowed_packet(local_session_var_->get_local_vars(),
|
||||
max_size))) {
|
||||
LOG_WARN("try get local max allowed packet failed", K(ret));
|
||||
}
|
||||
|
@ -227,6 +227,39 @@ int calc_##tritype##_expr(const ObExpr &expr, ObEvalCtx &ctx, \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
class ObSolidifiedVarsContext
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObSolidifiedVarsContext() :
|
||||
local_session_var_(NULL),
|
||||
alloc_(NULL),
|
||||
local_tz_wrap_(NULL)
|
||||
{
|
||||
}
|
||||
ObSolidifiedVarsContext(share::schema::ObLocalSessionVar *local_var, common::ObIAllocator *alloc) :
|
||||
local_session_var_(local_var),
|
||||
alloc_(alloc),
|
||||
local_tz_wrap_(NULL)
|
||||
{
|
||||
}
|
||||
virtual ~ObSolidifiedVarsContext() {
|
||||
if (NULL != local_tz_wrap_ && NULL != alloc_) {
|
||||
alloc_->free(local_tz_wrap_);
|
||||
local_tz_wrap_ = NULL;
|
||||
}
|
||||
}
|
||||
int get_local_tz_info(const sql::ObBasicSessionInfo *session, const common::ObTimeZoneInfo *&tz_info);
|
||||
share::schema::ObLocalSessionVar *get_local_vars() const { return local_session_var_; }
|
||||
DECLARE_TO_STRING;
|
||||
private:
|
||||
share::schema::ObLocalSessionVar *local_session_var_;
|
||||
common::ObIAllocator *alloc_;
|
||||
//cached vars
|
||||
ObTimeZoneInfoWrap *local_tz_wrap_;
|
||||
};
|
||||
|
||||
//Get the merged values of solidified vars and current session vars
|
||||
//If a var is solidified, return the solidified value. Otherwise return currrent session value.
|
||||
//e.g. :
|
||||
@ -248,9 +281,8 @@ public:
|
||||
//get the specified solidified var
|
||||
int get_local_var(share::ObSysVarClassType var_type, share::schema::ObSessionSysVar *&sys_var);
|
||||
private:
|
||||
const share::schema::ObLocalSessionVar *local_session_var_;
|
||||
const ObSolidifiedVarsContext *local_session_var_;
|
||||
const ObBasicSessionInfo *session_;
|
||||
ObTimeZoneInfoWrap local_tz_wrap_;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -856,7 +856,7 @@ int ObExecContext::get_pwj_map(PWJTabletIdMap *&pwj_map)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObExecContext::get_local_var_array(int64_t local_var_array_id, const ObLocalSessionVar *&var_array)
|
||||
int ObExecContext::get_local_var_array(int64_t local_var_array_id, const ObSolidifiedVarsContext *&var_array)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
var_array = NULL;
|
||||
|
@ -513,9 +513,9 @@ public:
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int get_local_var_array(int64_t local_var_array_id, const ObSolidifiedVarsContext *&var_array);
|
||||
void set_is_online_stats_gathering(bool v) { is_online_stats_gathering_ = v; }
|
||||
bool is_online_stats_gathering() const { return is_online_stats_gathering_; }
|
||||
int get_local_var_array(int64_t local_var_array_id, const ObLocalSessionVar *&var_array);
|
||||
private:
|
||||
int build_temp_expr_ctx(const ObTempExpr &temp_expr, ObTempExprCtx *&temp_expr_ctx);
|
||||
int set_phy_op_ctx_ptr(uint64_t index, void *phy_op);
|
||||
|
@ -766,7 +766,12 @@ OB_DEF_SERIALIZE(ObPhysicalPlanCtx)
|
||||
OB_UNIS_ENCODE(enable_rich_format_);
|
||||
OB_UNIS_ENCODE(all_local_session_vars_.count());
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < all_local_session_vars_.count(); ++i) {
|
||||
OB_UNIS_ENCODE(*all_local_session_vars_.at(i));
|
||||
if (OB_ISNULL(all_local_session_vars_.at(i).get_local_vars())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret));
|
||||
} else {
|
||||
OB_UNIS_ENCODE(*all_local_session_vars_.at(i).get_local_vars());
|
||||
}
|
||||
}
|
||||
OB_UNIS_ENCODE(mview_ids_);
|
||||
OB_UNIS_ENCODE(last_refresh_scns_);
|
||||
@ -863,7 +868,9 @@ OB_DEF_SERIALIZE_SIZE(ObPhysicalPlanCtx)
|
||||
OB_UNIS_ADD_LEN(enable_rich_format_);
|
||||
OB_UNIS_ADD_LEN(all_local_session_vars_.count());
|
||||
for (int64_t i = 0; i < all_local_session_vars_.count(); ++i) {
|
||||
OB_UNIS_ADD_LEN(*all_local_session_vars_.at(i));
|
||||
if (OB_NOT_NULL(all_local_session_vars_.at(i).get_local_vars())) {
|
||||
OB_UNIS_ADD_LEN(*all_local_session_vars_.at(i).get_local_vars());
|
||||
}
|
||||
}
|
||||
OB_UNIS_ADD_LEN(mview_ids_);
|
||||
OB_UNIS_ADD_LEN(last_refresh_scns_);
|
||||
@ -974,7 +981,7 @@ OB_DEF_DESERIALIZE(ObPhysicalPlanCtx)
|
||||
if (NULL == local_vars) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("alloc local var failed", K(ret));
|
||||
} else if (OB_FAIL(all_local_session_vars_.push_back(local_vars))) {
|
||||
} else if (OB_FAIL(all_local_session_vars_.push_back(ObSolidifiedVarsContext(local_vars, &allocator_)))) {
|
||||
LOG_WARN("push back local session var array failed", K(ret));
|
||||
} else {
|
||||
local_vars->set_allocator(&allocator_);
|
||||
@ -1136,7 +1143,7 @@ int ObPhysicalPlanCtx::set_all_local_session_vars(ObIArray<ObLocalSessionVar> &a
|
||||
LOG_WARN("reserve for local_session_vars failed", K(ret));
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < all_local_session_vars.count(); ++i) {
|
||||
if (OB_FAIL(all_local_session_vars_.push_back(&all_local_session_vars.at(i)))) {
|
||||
if (OB_FAIL(all_local_session_vars_.push_back(ObSolidifiedVarsContext(&all_local_session_vars.at(i), &allocator_)))) {
|
||||
LOG_WARN("push back local session var failed", K(ret));
|
||||
}
|
||||
}
|
||||
@ -1207,7 +1214,7 @@ int ObPhysicalPlanCtx::build_subschema_ctx_by_param_store(share::schema::ObSchem
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPhysicalPlanCtx::get_local_session_vars(int64_t local_var_array_id, const ObLocalSessionVar *&local_vars)
|
||||
int ObPhysicalPlanCtx::get_local_session_vars(int64_t local_var_array_id, const ObSolidifiedVarsContext *&local_vars)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
local_vars = NULL;
|
||||
@ -1217,7 +1224,7 @@ int ObPhysicalPlanCtx::get_local_session_vars(int64_t local_var_array_id, const
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("index out of array range", K(ret), K(local_var_array_id), K(all_local_session_vars_.count()));
|
||||
} else {
|
||||
local_vars = all_local_session_vars_.at(local_var_array_id);
|
||||
local_vars = &all_local_session_vars_.at(local_var_array_id);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "sql/engine/expr/ob_expr.h"
|
||||
#include "lib/udt/ob_udt_type.h"
|
||||
#include "sql/engine/ob_subschema_ctx.h"
|
||||
#include "sql/engine/expr/ob_expr_util.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
@ -475,7 +476,7 @@ public:
|
||||
const ObIArray<ObArrayParamGroup> &get_array_param_groups() const { return array_param_groups_; }
|
||||
ObIArray<ObArrayParamGroup> &get_array_param_groups() { return array_param_groups_; }
|
||||
int set_all_local_session_vars(ObIArray<ObLocalSessionVar> &all_local_session_vars);
|
||||
int get_local_session_vars(int64_t idx, const ObLocalSessionVar *&local_vars);
|
||||
int get_local_session_vars(int64_t idx, const ObSolidifiedVarsContext *&local_vars);
|
||||
common::ObIArray<uint64_t> &get_mview_ids() { return mview_ids_; }
|
||||
common::ObIArray<uint64_t> &get_last_refresh_scns() { return last_refresh_scns_; }
|
||||
uint64_t get_last_refresh_scn(uint64_t mview_id) const;
|
||||
@ -630,7 +631,7 @@ private:
|
||||
ObSubSchemaCtx subschema_ctx_;
|
||||
bool enable_rich_format_;
|
||||
// for dependant exprs of generated columns
|
||||
common::ObFixedArray<ObLocalSessionVar *, common::ObIAllocator> all_local_session_vars_;
|
||||
common::ObFixedArray<ObSolidifiedVarsContext, common::ObIAllocator> all_local_session_vars_;
|
||||
// for last_refresh_scn expr to get last_refresh_scn for rt mview used in query
|
||||
common::ObFixedArray<uint64_t, common::ObIAllocator> mview_ids_;
|
||||
common::ObFixedArray<uint64_t, common::ObIAllocator> last_refresh_scns_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user