Repair plan cache mode error about spm.

This commit is contained in:
obdev
2023-01-28 19:23:32 +08:00
committed by ob-robot
parent c24c75ed20
commit 91f036ae7c
8 changed files with 22 additions and 19 deletions

View File

@ -1363,7 +1363,7 @@ int ObSql::handle_sql_execute(const ObString &sql,
if (mode == PC_PS_MODE || mode == PC_PL_MODE) {
pctx->get_param_store_for_update().reset();
}
if (OB_FAIL(handle_physical_plan(sql, context, result, pc_ctx, get_plan_err, mode))) {
if (OB_FAIL(handle_physical_plan(sql, context, result, pc_ctx, get_plan_err))) {
if (OB_ERR_PROXY_REROUTE == ret) {
LOG_DEBUG("fail to handle physical plan", K(ret));
} else {
@ -2017,7 +2017,7 @@ int ObSql::handle_ps_execute(const ObPsStmtId client_stmt_id,
} else if (!result.get_is_from_plan_cache()) {
pctx->set_original_param_cnt(origin_params_count);
pctx->get_param_store_for_update().reset();
if (OB_FAIL(handle_physical_plan(sql, context, result, pc_ctx, get_plan_err, PC_PS_MODE))) {
if (OB_FAIL(handle_physical_plan(sql, context, result, pc_ctx, get_plan_err))) {
if (OB_ERR_PROXY_REROUTE == ret) {
LOG_DEBUG("fail to handle physical plan", K(ret));
} else {
@ -2202,7 +2202,7 @@ int ObSql::handle_remote_query(const ObRemoteSqlInfo &remote_sql_info,
remote_sql_info.ps_params_->pop_back();
}
PlanCacheMode mode = remote_sql_info.use_ps_ ? PC_PS_MODE : PC_TEXT_MODE;
if (OB_FAIL(handle_physical_plan(trimed_stmt, context, tmp_result, *pc_ctx, get_plan_err, mode))) {
if (OB_FAIL(handle_physical_plan(trimed_stmt, context, tmp_result, *pc_ctx, get_plan_err))) {
if (OB_ERR_PROXY_REROUTE == ret) {
LOG_DEBUG("fail to handle physical plan", K(ret));
} else {
@ -4368,12 +4368,12 @@ OB_NOINLINE int ObSql::handle_physical_plan(const ObString &trimed_stmt,
ObSqlCtx &context,
ObResultSet &result,
ObPlanCacheCtx &pc_ctx,
const int get_plan_err,
PlanCacheMode mode)
const int get_plan_err)
{
int ret = OB_SUCCESS;
FLTSpanGuard(hard_parse);
bool is_valid = true;
PlanCacheMode mode = pc_ctx.mode_;
ObString outlined_stmt = trimed_stmt;//use outline if available
ObString signature_sql;
ObOutlineState outline_state;

View File

@ -337,8 +337,7 @@ private:
ObSqlCtx &context,
ObResultSet &result,
ObPlanCacheCtx &pc_ctx,
const int get_plan_err,
PlanCacheMode mode = PC_INVALID_MODE);
const int get_plan_err);
// @brief Generate 'stmt' from syntax tree
// @param parse_result[in] syntax tree
// @param select_item_param_infos select_item_param_infos from fast parser
@ -370,7 +369,7 @@ private:
ObSqlCtx &context,
ObResultSet &result,
const bool is_begin_commit_stmt,
const PlanCacheMode mode = PC_INVALID_MODE,
const PlanCacheMode mode,
ParseResult *outline_parse_result = NULL);
int generate_plan(ParseResult &parse_result,

View File

@ -55,7 +55,7 @@ struct ObPlanCacheKey : public ObILibCacheKey
: key_id_(common::OB_INVALID_ID),
db_id_(common::OB_INVALID_ID),
sessid_(0),
mode_(PC_INVALID_MODE) {}
mode_(PC_TEXT_MODE) {}
ObPlanCacheKey(const ObString &name,
uint64_t key_id,
uint64_t db_id,
@ -79,7 +79,7 @@ struct ObPlanCacheKey : public ObILibCacheKey
key_id_ = common::OB_INVALID_ID;
db_id_ = common::OB_INVALID_ID;
sessid_ = 0;
mode_ = PC_INVALID_MODE;
mode_ = PC_TEXT_MODE;
sys_vars_str_.reset();
config_str_.reset();
namespace_ = NS_INVALID;
@ -386,6 +386,7 @@ struct ObPlanCacheCtx : public ObILibCacheCtx
bool is_rewrite_sql() const { return is_rewrite_sql_; }
void set_need_retry_add_plan(bool v) { need_retry_add_plan_ = v; }
bool need_retry_add_plan() const { return need_retry_add_plan_; }
void set_pc_key_mode() { fp_result_.pc_key_.mode_ = mode_; }
TO_STRING_KV(
K(mode_),
K(raw_sql_),

View File

@ -972,6 +972,10 @@ int ObSqlParameterization::parameterize_syntax_tree(common::ObIAllocator &alloca
|| (is_prepare_mode(mode) && sql_info.ps_need_parameterized_));
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(get_related_user_vars(tree, user_var_names))) {
LOG_WARN("failed to get related session vars", K(ret));
} else if (OB_FAIL(pc_ctx.sql_ctx_.set_related_user_var_names(user_var_names, allocator))) {
LOG_WARN("failed to set related user var names for sql ctx", K(ret));
} else if (is_execute_mode(mode)) {
if (OB_FAIL(gen_ps_not_param_var(sql_info.ps_not_param_offsets_, params, pc_ctx))) {
SQL_PC_LOG(WARN, "fail to gen ps not param var", K(ret));
@ -991,10 +995,6 @@ int ObSqlParameterization::parameterize_syntax_tree(common::ObIAllocator &alloca
}
} else if (OB_FAIL(gen_special_param_info(sql_info, pc_ctx))) {
SQL_PC_LOG(WARN, "fail to gen special param info", K(ret));
} else if (OB_FAIL(get_related_user_vars(tree, user_var_names))) {
LOG_WARN("failed to get related session vars", K(ret));
} else if (OB_FAIL(pc_ctx.sql_ctx_.set_related_user_var_names(user_var_names, allocator))) {
LOG_WARN("failed to set related user var names for sql ctx", K(ret));
} else {
// do nothing
}

View File

@ -28,6 +28,7 @@ void UDRBackupRecoveryGuard::backup()
{
is_prepare_protocol_ = sql_ctx_.is_prepare_protocol_;
cur_sql_ = sql_ctx_.cur_sql_;
mode_ = pc_ctx_.mode_;
}
void UDRBackupRecoveryGuard::recovery()
@ -36,8 +37,8 @@ void UDRBackupRecoveryGuard::recovery()
sql_ctx_.cur_sql_ = cur_sql_;
pc_ctx_.is_rewrite_sql_ = false;
pc_ctx_.def_name_ctx_ = nullptr;
pc_ctx_.mode_ = mode_;
if (!is_prepare_protocol_) {
pc_ctx_.mode_ = PC_INVALID_MODE;
const_cast<ObString &>(pc_ctx_.raw_sql_) = cur_sql_;
pc_ctx_.is_parameterized_execute_ = false;
pc_ctx_.fp_result_.parameterized_params_.reuse();

View File

@ -10,6 +10,7 @@
#include "sql/udr/ob_udr_sql_service.h"
#include "sql/udr/ob_udr_item_mgr.h"
#include "lib/task/ob_timer.h"
#include "sql/plan_cache/ob_plan_cache_struct.h"
namespace oceanbase
@ -42,6 +43,7 @@ private:
ObPlanCacheCtx &pc_ctx_;
bool is_prepare_protocol_;
common::ObString cur_sql_;
PlanCacheMode mode_;
};
class UDRTmpAllocatorGuard

View File

@ -138,7 +138,7 @@ TEST_F(TestPCVSet, basic)
EXPECT_TRUE(OB_SUCCESS == session.load_default_sys_variable(false, true));
// when add generate_plan() , change TEST_PLAN_NUM
ObString sql = ObString::make_string("select * from t1 where c1 = 0");
ObPlanCacheCtx pc_ctx(sql, false, allocator, sql_ctx, exec_ctx, common::OB_SYS_TENANT_ID);
ObPlanCacheCtx pc_ctx(sql, PC_TEXT_MODE, allocator, sql_ctx, exec_ctx, common::OB_SYS_TENANT_ID);
ObPCVSet pcv_set(plan_cache);
int ret = OB_SUCCESS;
generate_plan(test_sql_ctx,

View File

@ -173,9 +173,9 @@ TEST_F(TestPlanCacheValue, basic)
ObString sql_0 = ObString::make_string("select /*no_use_px*/ * from t1 where c1 = 1");
ObString sql_1 = ObString::make_string("select /*no_use_px*/ * from t1 where c1 = '1'");
ObString sql_2 = ObString::make_string("select /*no_use_px*/ * from t1 where c1=1 and c2=2");
ObPlanCacheCtx pc_ctx_0(sql_0, false, allocator, sql_ctx[0], exec_ctx[0], common::OB_SYS_TENANT_ID);
ObPlanCacheCtx pc_ctx_1(sql_0, false, allocator, sql_ctx[1], exec_ctx[1], common::OB_SYS_TENANT_ID);
ObPlanCacheCtx pc_ctx_2(sql_0, false, allocator, sql_ctx[2], exec_ctx[2], common::OB_SYS_TENANT_ID);
ObPlanCacheCtx pc_ctx_0(sql_0, PC_TEXT_MODE, allocator, sql_ctx[0], exec_ctx[0], common::OB_SYS_TENANT_ID);
ObPlanCacheCtx pc_ctx_1(sql_0, PC_TEXT_MODE, allocator, sql_ctx[1], exec_ctx[1], common::OB_SYS_TENANT_ID);
ObPlanCacheCtx pc_ctx_2(sql_0, PC_TEXT_MODE, allocator, sql_ctx[2], exec_ctx[2], common::OB_SYS_TENANT_ID);
pc_ctx_0.fp_result_.cache_params_ = &(pc_ctx_0.exec_ctx_.get_physical_plan_ctx()->get_param_store_for_update());
pc_ctx_1.fp_result_.cache_params_ = &(pc_ctx_1.exec_ctx_.get_physical_plan_ctx()->get_param_store_for_update());
pc_ctx_2.fp_result_.cache_params_ = &(pc_ctx_2.exec_ctx_.get_physical_plan_ctx()->get_param_store_for_update());