Repair plan cache mode error about spm.
This commit is contained in:
@ -1363,7 +1363,7 @@ int ObSql::handle_sql_execute(const ObString &sql,
|
|||||||
if (mode == PC_PS_MODE || mode == PC_PL_MODE) {
|
if (mode == PC_PS_MODE || mode == PC_PL_MODE) {
|
||||||
pctx->get_param_store_for_update().reset();
|
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) {
|
if (OB_ERR_PROXY_REROUTE == ret) {
|
||||||
LOG_DEBUG("fail to handle physical plan", K(ret));
|
LOG_DEBUG("fail to handle physical plan", K(ret));
|
||||||
} else {
|
} else {
|
||||||
@ -2017,7 +2017,7 @@ int ObSql::handle_ps_execute(const ObPsStmtId client_stmt_id,
|
|||||||
} else if (!result.get_is_from_plan_cache()) {
|
} else if (!result.get_is_from_plan_cache()) {
|
||||||
pctx->set_original_param_cnt(origin_params_count);
|
pctx->set_original_param_cnt(origin_params_count);
|
||||||
pctx->get_param_store_for_update().reset();
|
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) {
|
if (OB_ERR_PROXY_REROUTE == ret) {
|
||||||
LOG_DEBUG("fail to handle physical plan", K(ret));
|
LOG_DEBUG("fail to handle physical plan", K(ret));
|
||||||
} else {
|
} else {
|
||||||
@ -2202,7 +2202,7 @@ int ObSql::handle_remote_query(const ObRemoteSqlInfo &remote_sql_info,
|
|||||||
remote_sql_info.ps_params_->pop_back();
|
remote_sql_info.ps_params_->pop_back();
|
||||||
}
|
}
|
||||||
PlanCacheMode mode = remote_sql_info.use_ps_ ? PC_PS_MODE : PC_TEXT_MODE;
|
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) {
|
if (OB_ERR_PROXY_REROUTE == ret) {
|
||||||
LOG_DEBUG("fail to handle physical plan", K(ret));
|
LOG_DEBUG("fail to handle physical plan", K(ret));
|
||||||
} else {
|
} else {
|
||||||
@ -4368,12 +4368,12 @@ OB_NOINLINE int ObSql::handle_physical_plan(const ObString &trimed_stmt,
|
|||||||
ObSqlCtx &context,
|
ObSqlCtx &context,
|
||||||
ObResultSet &result,
|
ObResultSet &result,
|
||||||
ObPlanCacheCtx &pc_ctx,
|
ObPlanCacheCtx &pc_ctx,
|
||||||
const int get_plan_err,
|
const int get_plan_err)
|
||||||
PlanCacheMode mode)
|
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
FLTSpanGuard(hard_parse);
|
FLTSpanGuard(hard_parse);
|
||||||
bool is_valid = true;
|
bool is_valid = true;
|
||||||
|
PlanCacheMode mode = pc_ctx.mode_;
|
||||||
ObString outlined_stmt = trimed_stmt;//use outline if available
|
ObString outlined_stmt = trimed_stmt;//use outline if available
|
||||||
ObString signature_sql;
|
ObString signature_sql;
|
||||||
ObOutlineState outline_state;
|
ObOutlineState outline_state;
|
||||||
|
@ -337,8 +337,7 @@ private:
|
|||||||
ObSqlCtx &context,
|
ObSqlCtx &context,
|
||||||
ObResultSet &result,
|
ObResultSet &result,
|
||||||
ObPlanCacheCtx &pc_ctx,
|
ObPlanCacheCtx &pc_ctx,
|
||||||
const int get_plan_err,
|
const int get_plan_err);
|
||||||
PlanCacheMode mode = PC_INVALID_MODE);
|
|
||||||
// @brief Generate 'stmt' from syntax tree
|
// @brief Generate 'stmt' from syntax tree
|
||||||
// @param parse_result[in] syntax tree
|
// @param parse_result[in] syntax tree
|
||||||
// @param select_item_param_infos select_item_param_infos from fast parser
|
// @param select_item_param_infos select_item_param_infos from fast parser
|
||||||
@ -370,7 +369,7 @@ private:
|
|||||||
ObSqlCtx &context,
|
ObSqlCtx &context,
|
||||||
ObResultSet &result,
|
ObResultSet &result,
|
||||||
const bool is_begin_commit_stmt,
|
const bool is_begin_commit_stmt,
|
||||||
const PlanCacheMode mode = PC_INVALID_MODE,
|
const PlanCacheMode mode,
|
||||||
ParseResult *outline_parse_result = NULL);
|
ParseResult *outline_parse_result = NULL);
|
||||||
|
|
||||||
int generate_plan(ParseResult &parse_result,
|
int generate_plan(ParseResult &parse_result,
|
||||||
|
@ -55,7 +55,7 @@ struct ObPlanCacheKey : public ObILibCacheKey
|
|||||||
: key_id_(common::OB_INVALID_ID),
|
: key_id_(common::OB_INVALID_ID),
|
||||||
db_id_(common::OB_INVALID_ID),
|
db_id_(common::OB_INVALID_ID),
|
||||||
sessid_(0),
|
sessid_(0),
|
||||||
mode_(PC_INVALID_MODE) {}
|
mode_(PC_TEXT_MODE) {}
|
||||||
ObPlanCacheKey(const ObString &name,
|
ObPlanCacheKey(const ObString &name,
|
||||||
uint64_t key_id,
|
uint64_t key_id,
|
||||||
uint64_t db_id,
|
uint64_t db_id,
|
||||||
@ -79,7 +79,7 @@ struct ObPlanCacheKey : public ObILibCacheKey
|
|||||||
key_id_ = common::OB_INVALID_ID;
|
key_id_ = common::OB_INVALID_ID;
|
||||||
db_id_ = common::OB_INVALID_ID;
|
db_id_ = common::OB_INVALID_ID;
|
||||||
sessid_ = 0;
|
sessid_ = 0;
|
||||||
mode_ = PC_INVALID_MODE;
|
mode_ = PC_TEXT_MODE;
|
||||||
sys_vars_str_.reset();
|
sys_vars_str_.reset();
|
||||||
config_str_.reset();
|
config_str_.reset();
|
||||||
namespace_ = NS_INVALID;
|
namespace_ = NS_INVALID;
|
||||||
@ -386,6 +386,7 @@ struct ObPlanCacheCtx : public ObILibCacheCtx
|
|||||||
bool is_rewrite_sql() const { return is_rewrite_sql_; }
|
bool is_rewrite_sql() const { return is_rewrite_sql_; }
|
||||||
void set_need_retry_add_plan(bool v) { need_retry_add_plan_ = v; }
|
void set_need_retry_add_plan(bool v) { need_retry_add_plan_ = v; }
|
||||||
bool need_retry_add_plan() const { return need_retry_add_plan_; }
|
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(
|
TO_STRING_KV(
|
||||||
K(mode_),
|
K(mode_),
|
||||||
K(raw_sql_),
|
K(raw_sql_),
|
||||||
|
@ -972,6 +972,10 @@ int ObSqlParameterization::parameterize_syntax_tree(common::ObIAllocator &alloca
|
|||||||
|| (is_prepare_mode(mode) && sql_info.ps_need_parameterized_));
|
|| (is_prepare_mode(mode) && sql_info.ps_need_parameterized_));
|
||||||
}
|
}
|
||||||
if (OB_FAIL(ret)) {
|
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)) {
|
} else if (is_execute_mode(mode)) {
|
||||||
if (OB_FAIL(gen_ps_not_param_var(sql_info.ps_not_param_offsets_, params, pc_ctx))) {
|
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));
|
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))) {
|
} else if (OB_FAIL(gen_special_param_info(sql_info, pc_ctx))) {
|
||||||
SQL_PC_LOG(WARN, "fail to gen special param info", K(ret));
|
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 {
|
} else {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ void UDRBackupRecoveryGuard::backup()
|
|||||||
{
|
{
|
||||||
is_prepare_protocol_ = sql_ctx_.is_prepare_protocol_;
|
is_prepare_protocol_ = sql_ctx_.is_prepare_protocol_;
|
||||||
cur_sql_ = sql_ctx_.cur_sql_;
|
cur_sql_ = sql_ctx_.cur_sql_;
|
||||||
|
mode_ = pc_ctx_.mode_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UDRBackupRecoveryGuard::recovery()
|
void UDRBackupRecoveryGuard::recovery()
|
||||||
@ -36,8 +37,8 @@ void UDRBackupRecoveryGuard::recovery()
|
|||||||
sql_ctx_.cur_sql_ = cur_sql_;
|
sql_ctx_.cur_sql_ = cur_sql_;
|
||||||
pc_ctx_.is_rewrite_sql_ = false;
|
pc_ctx_.is_rewrite_sql_ = false;
|
||||||
pc_ctx_.def_name_ctx_ = nullptr;
|
pc_ctx_.def_name_ctx_ = nullptr;
|
||||||
|
pc_ctx_.mode_ = mode_;
|
||||||
if (!is_prepare_protocol_) {
|
if (!is_prepare_protocol_) {
|
||||||
pc_ctx_.mode_ = PC_INVALID_MODE;
|
|
||||||
const_cast<ObString &>(pc_ctx_.raw_sql_) = cur_sql_;
|
const_cast<ObString &>(pc_ctx_.raw_sql_) = cur_sql_;
|
||||||
pc_ctx_.is_parameterized_execute_ = false;
|
pc_ctx_.is_parameterized_execute_ = false;
|
||||||
pc_ctx_.fp_result_.parameterized_params_.reuse();
|
pc_ctx_.fp_result_.parameterized_params_.reuse();
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "sql/udr/ob_udr_sql_service.h"
|
#include "sql/udr/ob_udr_sql_service.h"
|
||||||
#include "sql/udr/ob_udr_item_mgr.h"
|
#include "sql/udr/ob_udr_item_mgr.h"
|
||||||
#include "lib/task/ob_timer.h"
|
#include "lib/task/ob_timer.h"
|
||||||
|
#include "sql/plan_cache/ob_plan_cache_struct.h"
|
||||||
|
|
||||||
|
|
||||||
namespace oceanbase
|
namespace oceanbase
|
||||||
@ -42,6 +43,7 @@ private:
|
|||||||
ObPlanCacheCtx &pc_ctx_;
|
ObPlanCacheCtx &pc_ctx_;
|
||||||
bool is_prepare_protocol_;
|
bool is_prepare_protocol_;
|
||||||
common::ObString cur_sql_;
|
common::ObString cur_sql_;
|
||||||
|
PlanCacheMode mode_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UDRTmpAllocatorGuard
|
class UDRTmpAllocatorGuard
|
||||||
|
@ -138,7 +138,7 @@ TEST_F(TestPCVSet, basic)
|
|||||||
EXPECT_TRUE(OB_SUCCESS == session.load_default_sys_variable(false, true));
|
EXPECT_TRUE(OB_SUCCESS == session.load_default_sys_variable(false, true));
|
||||||
// when add generate_plan() , change TEST_PLAN_NUM
|
// when add generate_plan() , change TEST_PLAN_NUM
|
||||||
ObString sql = ObString::make_string("select * from t1 where c1 = 0");
|
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);
|
ObPCVSet pcv_set(plan_cache);
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
generate_plan(test_sql_ctx,
|
generate_plan(test_sql_ctx,
|
||||||
|
@ -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_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_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");
|
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_0(sql_0, PC_TEXT_MODE, 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_1(sql_0, PC_TEXT_MODE, 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_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_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_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());
|
pc_ctx_2.fp_result_.cache_params_ = &(pc_ctx_2.exec_ctx_.get_physical_plan_ctx()->get_param_store_for_update());
|
||||||
|
Reference in New Issue
Block a user