Fix some user-defined_rules bug

This commit is contained in:
obdev
2023-04-27 14:41:41 +00:00
committed by ob-robot
parent cef0b50339
commit 271e8aa047
4 changed files with 38 additions and 13 deletions

View File

@ -362,6 +362,31 @@ int ObPlanCache::init(int64_t hash_bucket, uint64_t tenant_id)
return ret; return ret;
} }
int ObPlanCache::get_normalized_pattern_digest(const ObPlanCacheCtx &pc_ctx, uint64_t &pattern_digest)
{
int ret = OB_SUCCESS;
pattern_digest = 0;
if (pc_ctx.mode_ == PC_PS_MODE || pc_ctx.mode_ == PC_PL_MODE || pc_ctx.fp_result_.pc_key_.name_.empty()) {
ObFastParserResult fp_result;
ObSQLMode sql_mode = pc_ctx.sql_ctx_.session_info_->get_sql_mode();
ObCollationType conn_coll = pc_ctx.sql_ctx_.session_info_->get_local_collation_connection();
FPContext fp_ctx(conn_coll);
fp_ctx.enable_batched_multi_stmt_ = pc_ctx.sql_ctx_.handle_batched_multi_stmt();
fp_ctx.sql_mode_ = sql_mode;
if (OB_FAIL(ObSqlParameterization::fast_parser(pc_ctx.allocator_,
fp_ctx,
pc_ctx.raw_sql_,
fp_result))) {
LOG_WARN("failed to fast parser", K(ret), K(sql_mode), K(pc_ctx.raw_sql_));
} else {
pattern_digest = fp_result.pc_key_.name_.hash();
}
} else {
pattern_digest = pc_ctx.fp_result_.pc_key_.name_.hash();
}
return ret;
}
int ObPlanCache::check_after_get_plan(int tmp_ret, int ObPlanCache::check_after_get_plan(int tmp_ret,
ObILibCacheCtx &ctx, ObILibCacheCtx &ctx,
ObILibCacheObject *cache_obj) ObILibCacheObject *cache_obj)
@ -391,12 +416,15 @@ int ObPlanCache::check_after_get_plan(int tmp_ret,
} }
if (OB_SUCC(ret) && plan != NULL) { if (OB_SUCC(ret) && plan != NULL) {
bool is_exists = false; bool is_exists = false;
uint64_t pattern_digest = 0;
sql::ObUDRMgr *rule_mgr = MTL(sql::ObUDRMgr*); sql::ObUDRMgr *rule_mgr = MTL(sql::ObUDRMgr*);
// when the global rule version changes or enable_user_defined_rewrite_rules changes // when the global rule version changes or enable_user_defined_rewrite_rules changes
// it is necessary to check whether the physical plan are expired // it is necessary to check whether the physical plan are expired
if ((plan->get_rule_version() != rule_mgr->get_rule_version() if ((plan->get_rule_version() != rule_mgr->get_rule_version()
|| plan->is_enable_udr() != enable_udr)) { || plan->is_enable_udr() != enable_udr)) {
if (OB_FAIL(rule_mgr->fuzzy_check_by_pattern_digest(pc_ctx.get_normalized_pattern_digest(), is_exists))) { if (OB_FAIL(get_normalized_pattern_digest(pc_ctx, pattern_digest))) {
LOG_WARN("failed to calc normalized pattern digest", K(ret));
} else if (OB_FAIL(rule_mgr->fuzzy_check_by_pattern_digest(pattern_digest, is_exists))) {
LOG_WARN("failed to fuzzy check by pattern digest", K(ret)); LOG_WARN("failed to fuzzy check by pattern digest", K(ret));
} else if (is_exists || plan->is_rewrite_sql()) { } else if (is_exists || plan->is_rewrite_sql()) {
ret = OB_OLD_SCHEMA_VERSION; ret = OB_OLD_SCHEMA_VERSION;

View File

@ -427,6 +427,7 @@ private:
ObPlanCacheCtx &pc_ctx, ObPlanCacheCtx &pc_ctx,
const ObILibCacheObject &cache_object); const ObILibCacheObject &cache_object);
int check_after_get_plan(int tmp_ret, ObILibCacheCtx &ctx, ObILibCacheObject *cache_obj); int check_after_get_plan(int tmp_ret, ObILibCacheCtx &ctx, ObILibCacheObject *cache_obj);
int get_normalized_pattern_digest(const ObPlanCacheCtx &pc_ctx, uint64_t &pattern_digest);
private: private:
enum PlanCacheGCStrategy { INVALID = -1, OFF = 0, REPORT = 1, AUTO = 2}; enum PlanCacheGCStrategy { INVALID = -1, OFF = 0, REPORT = 1, AUTO = 2};
static int get_plan_cache_gc_strategy(); static int get_plan_cache_gc_strategy();

View File

@ -347,17 +347,6 @@ struct ObPlanCacheCtx : public ObILibCacheCtx
return ret; return ret;
} }
uint64_t get_normalized_pattern_digest() const
{
common::ObString normalized_pattern;
if (mode_ == PC_PS_MODE || mode_ == PC_PL_MODE || fp_result_.pc_key_.name_.empty()) {
normalized_pattern = raw_sql_;
} else {
normalized_pattern = fp_result_.pc_key_.name_;
}
return normalized_pattern.hash();
}
int is_retry(bool &v) const; //是否在重试之中 int is_retry(bool &v) const; //是否在重试之中
int is_retry_for_dup_tbl(bool &v) const; //仅复制表原因的重试才会设置为true int is_retry_for_dup_tbl(bool &v) const; //仅复制表原因的重试才会设置为true
void set_begin_commit_stmt() { begin_commit_stmt_ = true; } void set_begin_commit_stmt() { begin_commit_stmt_ = true; }

View File

@ -449,7 +449,14 @@ int ObRawExprDeduceType::calc_result_type(ObNonTerminalRawExpr &expr,
} }
if (OB_FAIL(ret) && my_session_->is_ps_prepare_stage()) { if (OB_FAIL(ret) && my_session_->is_ps_prepare_stage()) {
// the ps prepare stage does not do type deduction, and directly gives a default type. // the ps prepare stage does not do type deduction, and directly gives a default type.
result_type.set_null(); result_type.set_type(ObVarcharType);
result_type.set_calc_type(ObVarcharType);
for (int64_t i = 0; i < types.count(); i++) {
types.at(i).set_type(ObVarcharType);
types.at(i).set_calc_type(ObVarcharType);
}
expr.set_result_type(result_type);
expr.set_input_types(types);
ret = OB_SUCCESS; ret = OB_SUCCESS;
} }
// check parameters can cast to expected type // check parameters can cast to expected type