diff --git a/src/sql/plan_cache/ob_plan_cache_util.h b/src/sql/plan_cache/ob_plan_cache_util.h index 3b89183bcc3f8e2f277d6584033fcf59b0665394..59b2bda86180e0decfc7dbce1bcd3a18ce0ea235 100644 --- a/src/sql/plan_cache/ob_plan_cache_util.h +++ b/src/sql/plan_cache/ob_plan_cache_util.h @@ -376,12 +376,30 @@ struct ObPCConstParamInfo { common::ObSEArray const_idx_; common::ObSEArray const_params_; TO_STRING_KV(K_(const_idx), K_(const_params)); + bool operator==(const ObPCConstParamInfo &other) const + { + bool cmp_ret = true; + for (int i=0; cmp_ret && i < const_idx_.count(); i++) { + cmp_ret = const_idx_.at(i) == other.const_idx_.at(i); + } + for (int i=0; cmp_ret && i < const_params_.count(); i++) { + cmp_ret = const_params_.at(i) == other.const_params_.at(i); + } + return cmp_ret; + } }; struct ObPCParamEqualInfo { int64_t first_param_idx_; int64_t second_param_idx_; TO_STRING_KV(K_(first_param_idx), K_(second_param_idx)); + inline bool operator==(const ObPCParamEqualInfo &other) const + { + bool cmp_ret = first_param_idx_ == other.first_param_idx_ && + second_param_idx_ == other.second_param_idx_; + + return cmp_ret; + } }; struct ObFastParserResult { diff --git a/src/sql/plan_cache/ob_plan_set.cpp b/src/sql/plan_cache/ob_plan_set.cpp index be73ac5963348d85078744a09eed050afbf4aead..6865cf3f5dc323d1b63179f232df21effb8fbf18 100644 --- a/src/sql/plan_cache/ob_plan_set.cpp +++ b/src/sql/plan_cache/ob_plan_set.cpp @@ -386,6 +386,7 @@ int ObPlanSet::match_params_info( if (OB_SUCC(ret)) { const ParamStore& params = pc_ctx.exec_ctx_.get_physical_plan_ctx()->get_param_store(); OC((match_constraint)(params, is_same)); + OC( (match_cons)(pc_ctx, is_same)); } } } @@ -624,6 +625,41 @@ int ObPlanSet::set_equal_param_constraint(common::ObIArray& return ret; } +// match actually constraint +int ObPlanSet::match_cons(const ObPlanCacheCtx &pc_ctx, bool &is_matched) +{ + int ret = OB_SUCCESS; + ObIArray *param_cons = pc_ctx.sql_ctx_.all_plan_const_param_constraints_; + ObIArray *possible_param_cons = + pc_ctx.sql_ctx_.all_possible_const_param_constraints_; + ObIArray *equal_cons = pc_ctx.sql_ctx_.all_equal_param_constraints_; + is_matched = true; + + if (OB_ISNULL(param_cons) || + OB_ISNULL(possible_param_cons) || + OB_ISNULL(equal_cons)) { + is_matched = false; + ret = OB_INVALID_ARGUMENT; + LOG_WARN("invalid arugment", K(param_cons), K(possible_param_cons), K(equal_cons)); + } else if (param_cons->count() != all_plan_const_param_constraints_.count() || + possible_param_cons->count() != all_possible_const_param_constraints_.count() || + equal_cons->count() != all_equal_param_constraints_.count()) { + is_matched = false; + } else { + for (int64_t i=0; is_matched && i < all_plan_const_param_constraints_.count(); i++) { + is_matched = (all_plan_const_param_constraints_.at(i)==param_cons->at(i)); + } + for (int64_t i=0; is_matched && i < all_possible_const_param_constraints_.count(); i++) { + is_matched = (all_possible_const_param_constraints_.at(i)==possible_param_cons->at(i)); + } + for (int64_t i=0; is_matched && i < all_equal_param_constraints_.count(); i++) { + is_matched = (all_equal_param_constraints_.at(i)==equal_cons->at(i)); + } + } + + return ret; +} + int ObPlanSet::match_constraint(const ParamStore& params, bool& is_matched) { int ret = OB_SUCCESS; diff --git a/src/sql/plan_cache/ob_plan_set.h b/src/sql/plan_cache/ob_plan_set.h index 2d8c0317ebb1728b9b103dc6377d33517ed50d2d..49044d094dbadeb0ab93a558a9104dc2f9ebfec2 100644 --- a/src/sql/plan_cache/ob_plan_set.h +++ b/src/sql/plan_cache/ob_plan_set.h @@ -174,7 +174,8 @@ private: common::ObIArray& const_param_constraint, const bool is_all_constraint); int set_equal_param_constraint(common::ObIArray& equal_param_constraint); - + + int match_cons(const ObPlanCacheCtx &pc_ctx, bool &is_matched); /** * @brief Match const param constraint. * If all_plan_const_param_constraints_ is not empty, check wether the constraints is mached and return the result.