[CP] spm only accepts successfully executed plans as baseline

This commit is contained in:
obdev
2022-12-15 13:11:45 +00:00
committed by ob-robot
parent 2ff985ffdd
commit c91594425b
7 changed files with 21 additions and 21 deletions

View File

@ -1200,6 +1200,7 @@ OB_INLINE int ObMPQuery::response_result(ObMySQLResultSet &result,
CHECK_COMPATIBILITY_MODE(&session);
bool need_trans_cb = result.need_end_trans_callback() && (!force_sync_resp);
// 通过判断 plan 是否为 null 来确定是 plan 还是 cmd
// 针对 plan 和 cmd 分开处理,逻辑会较为清晰。
if (OB_LIKELY(NULL != result.get_physical_plan())) {

View File

@ -1306,12 +1306,7 @@ int ObMPStmtExecute::do_process(ObSQLSessionInfo &session,
|| RETRY_TYPE_NONE != retry_ctrl_.get_retry_type());
if (!is_ps_cursor()) {
// ps cursor has already record after inner_open in spi
if (NULL != result.get_exec_context().get_sql_ctx()) {
ObSQLUtils::handle_audit_record(need_retry, EXECUTE_PS_EXECUTE, session,
result.get_exec_context().get_sql_ctx()->is_sensitive_);
} else {
ObSQLUtils::handle_audit_record(need_retry, EXECUTE_PS_EXECUTE, session);
}
ObSQLUtils::handle_audit_record(need_retry, EXECUTE_PS_EXECUTE, session, ctx_.is_sensitive_);
}
}
return ret;

View File

@ -545,12 +545,7 @@ int ObMPStmtPrepare::do_process(ObSQLSessionInfo &session,
audit_record.update_stage_stat();
bool need_retry = (THIS_THWORKER.need_retry()
|| RETRY_TYPE_NONE != retry_ctrl_.get_retry_type());
if (NULL != result.get_exec_context().get_sql_ctx()) {
ObSQLUtils::handle_audit_record(need_retry, EXECUTE_PS_PREPARE, session,
result.get_exec_context().get_sql_ctx()->is_sensitive_);
} else {
ObSQLUtils::handle_audit_record(need_retry, EXECUTE_PS_PREPARE, session);
}
ObSQLUtils::handle_audit_record(need_retry, EXECUTE_PS_PREPARE, session, ctx_.is_sensitive_);
}
}

View File

@ -3714,6 +3714,7 @@ OB_NOINLINE int ObSql::handle_physical_plan(const ObString &trimed_stmt,
bool add_plan_to_pc = false;
ObSQLSessionInfo &session = result.get_session();
ObPlanCache *plan_cache = session.get_plan_cache();
ObSpmCacheCtx &spm_ctx = context.spm_ctx_;
bool use_plan_cache = session.get_local_ob_enable_plan_cache();
// record whether needs to do parameterization at this time,
// if exact mode is on, not do parameterizaiton
@ -3723,7 +3724,7 @@ OB_NOINLINE int ObSql::handle_physical_plan(const ObString &trimed_stmt,
pc_ctx.neg_param_index_.reset();
bool plan_added = false;
bool need_get_baseline = false;
LOG_DEBUG("gen plan info", K(context.spm_ctx_.bl_key_), K(get_plan_err));
LOG_DEBUG("gen plan info", K(spm_ctx.bl_key_), K(get_plan_err));
// for batched multi stmt, we only parse and optimize the first statement
// only in multi_query, need do this
if (!is_psmode &&

View File

@ -18,6 +18,7 @@
#include "lib/task/ob_timer.h"
#include "lib/list/ob_list.h"
#include "lib/lock/ob_spin_rwlock.h"
#include "sql/monitor/ob_exec_stat.h"
namespace oceanbase
@ -76,15 +77,15 @@ public:
int add_list(EvolutionTaskResult& result);
int check_baseline_exists(ObSpmCacheCtx& spm_ctx,
const uint64_t plan_hash,
const bool cache_only,
bool& is_exists);
bool& is_exists,
bool& need_add_baseline);
int get_best_baseline(ObSpmCacheCtx& spm_ctx,
ObCacheObjGuard& obj_guard);
int add_baseline(ObSpmCacheCtx& spm_ctx,
ObPlanCacheCtx& pc_ctx,
ObPhysicalPlan* plan);
int update_plan_baseline_statistic(EvolutionTaskResult& result);
int accept_new_plan_baseline(ObSpmCacheCtx& spm_ctx);
int accept_new_plan_baseline(ObSpmCacheCtx& spm_ctx, const ObAuditRecordData &audit_record);
int force_accept_new_plan_baseline(ObSpmCacheCtx& spm_ctx, uint64_t plan_hash, const bool with_plan_hash);
int sync_baseline_from_inner_table();
int sync_baseline_from_server();
@ -103,6 +104,7 @@ public:
int64_t &baseline_affected);
int load_baseline(ObBaselineKey &key, ObPhysicalPlan* plan, const bool fixed, const bool enabled);
int purge_baselines(const uint64_t tenant_id, int64_t baseline_affected);
int evict_plan_baseline(ObSpmCacheCtx& spm_ctx);
private:
int init(uint64_t tenant_id);
int init_mem_context(uint64_t tenant_id);

View File

@ -16,6 +16,7 @@
#include "sql/plan_cache/ob_plan_cache_util.h"
#include "sql/spm/ob_spm_define.h"
#include "share/ob_rpc_struct.h"
#include "sql/monitor/ob_exec_stat.h"
namespace oceanbase
{
@ -33,13 +34,14 @@ public:
ObPhysicalPlan* plan,
bool& is_exists);
static void get_next_baseline_outline(ObSpmCacheCtx& spm_ctx);
static int accept_new_plan_as_baseline(ObSpmCacheCtx& spm_ctx);
static int accept_new_plan_as_baseline(ObSpmCacheCtx& spm_ctx, const ObAuditRecordData &audit_record);
static int update_evolution_task_result(EvolutionTaskResult& result);
static int accept_plan_baseline_by_user(obrpc::ObModifyPlanBaselineArg& arg);
static int cancel_evolve_task(obrpc::ObModifyPlanBaselineArg& arg);
static int load_baseline(const obrpc::ObLoadPlanBaselineArg& arg, ObPhysicalPlan* plan);
static int deny_new_plan_as_baseline(ObSpmCacheCtx& spm_ctx);
};
} // namespace sql end

View File

@ -207,7 +207,8 @@ public:
ObSpmSet(ObPlanCache *lib_cache, lib::MemoryContext &mem_context)
: ObILibCacheNode(lib_cache, mem_context),
is_inited_(false),
baseline_key_()
baseline_key_(),
enabled_fixed_baseline_count_(0)
{
}
virtual ~ObSpmSet()
@ -232,6 +233,7 @@ private:
ObBaselineKey baseline_key_; //used for manager key memory
common::ObSEArray<ObPlanBaselineItem*, 4> baseline_array_;
common::ObSEArray<ObPlanBaselineItem*, 4> fixed_baseline_array_;
int64_t enabled_fixed_baseline_count_;
};
struct BaselineCmp
@ -254,7 +256,7 @@ struct ObSpmCacheCtx : public ObILibCacheCtx
handle_cache_mode_(MODE_INVALID),
plan_hash_value_(0),
offset_(-1),
need_sync_(false),
check_execute_status_(false),
is_retry_for_spm_(false),
capture_baseline_(false),
new_plan_hash_(0),
@ -264,7 +266,8 @@ struct ObSpmCacheCtx : public ObILibCacheCtx
spm_force_disable_(false),
has_fixed_plan_to_check_(false),
evolution_plan_type_(OB_PHY_PLAN_UNINITIALIZED),
select_plan_type_(INVALID_TYPE)
select_plan_type_(INVALID_TYPE),
cur_baseline_not_enable_(false)
{}
enum SpmMode {
MODE_INVALID,
@ -310,7 +313,7 @@ struct ObSpmCacheCtx : public ObILibCacheCtx
SpmMode handle_cache_mode_;
uint64_t plan_hash_value_;
int64_t offset_;
bool need_sync_;
bool check_execute_status_;
bool is_retry_for_spm_;
char sql_id_[common::OB_MAX_SQL_ID_LENGTH + 1];
bool capture_baseline_;
@ -322,6 +325,7 @@ struct ObSpmCacheCtx : public ObILibCacheCtx
bool has_fixed_plan_to_check_;
ObPhyPlanType evolution_plan_type_;
SpmSelectPlanType select_plan_type_; // for retry
bool cur_baseline_not_enable_;
};
struct EvolutionTaskResult