Fix some user-defined rewrite rules bug
This commit is contained in:
@ -1027,7 +1027,10 @@ int ObSql::do_real_prepare(const ObString &sql,
|
|||||||
&& !is_inner_sql
|
&& !is_inner_sql
|
||||||
&& enable_udr
|
&& enable_udr
|
||||||
&& OB_FAIL(ObUDRUtils::match_udr_item(sql, session, allocator, item_guard))) {
|
&& OB_FAIL(ObUDRUtils::match_udr_item(sql, session, allocator, item_guard))) {
|
||||||
LOG_WARN("failed to match rewrite rule", K(ret));
|
if (!ObSQLUtils::check_need_disconnect_parser_err(ret)) {
|
||||||
|
ectx.set_need_disconnect(false);
|
||||||
|
}
|
||||||
|
LOG_WARN("failed to match rewrite rule", K(ret));
|
||||||
} else if (ObStmt::is_dml_stmt(stmt_type)
|
} else if (ObStmt::is_dml_stmt(stmt_type)
|
||||||
&& NULL == item_guard.get_ref_obj()
|
&& NULL == item_guard.get_ref_obj()
|
||||||
&& !ObStmt::is_show_stmt(stmt_type)
|
&& !ObStmt::is_show_stmt(stmt_type)
|
||||||
@ -3000,6 +3003,9 @@ int ObSql::generate_plan(ParseResult &parse_result,
|
|||||||
// and we shouldn't add this plan to plan cache.
|
// and we shouldn't add this plan to plan cache.
|
||||||
if (NULL != pc_ctx) {
|
if (NULL != pc_ctx) {
|
||||||
pc_ctx->should_add_plan_ = (effective_tid==phy_plan->get_tenant_id());
|
pc_ctx->should_add_plan_ = (effective_tid==phy_plan->get_tenant_id());
|
||||||
|
if (!pc_ctx->rule_name_.empty() && OB_FAIL(phy_plan->set_rule_name(pc_ctx->rule_name_))) {
|
||||||
|
LOG_WARN("failed to deep copy rule name", K(ret));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3943,22 +3949,8 @@ int ObSql::parser_and_check(const ObString &outlined_stmt,
|
|||||||
//FIXME qianfu NG_TRACE_EXT(set_need_disconnect, OB_ID(need_disconnect), false);
|
//FIXME qianfu NG_TRACE_EXT(set_need_disconnect, OB_ID(need_disconnect), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (OB_LIKELY(OB_ERR_PARSE_SQL == ret
|
} else if (!ObSQLUtils::check_need_disconnect_parser_err(ret)) {
|
||||||
|| OB_ERR_EMPTY_QUERY == ret
|
|
||||||
|| OB_SIZE_OVERFLOW == ret
|
|
||||||
|| OB_ERR_ILLEGAL_NAME == ret
|
|
||||||
|| OB_ERR_STR_LITERAL_TOO_LONG == ret
|
|
||||||
|| OB_ERR_NOT_VALID_ROUTINE_NAME == ret
|
|
||||||
|| OB_ERR_CONSTRUCT_MUST_RETURN_SELF == ret
|
|
||||||
|| OB_ERR_ONLY_FUNC_CAN_PIPELINED == ret
|
|
||||||
|| OB_ERR_NO_ATTR_FOUND == ret
|
|
||||||
|| OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK == ret
|
|
||||||
|| OB_ERR_NON_INT_LITERAL == ret
|
|
||||||
|| OB_ERR_PARSER_INIT == ret
|
|
||||||
|| OB_NOT_SUPPORTED == ret)) {
|
|
||||||
// parser返回已知的错误码,不需要断掉与客户端的连接
|
|
||||||
exec_ctx.set_need_disconnect(false);
|
exec_ctx.set_need_disconnect(false);
|
||||||
//FIXME qianfu NG_TRACE_EXT(set_need_disconnect, OB_ID(need_disconnect), false);
|
|
||||||
} else {
|
} else {
|
||||||
// parser返回未知的错误码,需要断掉与客户端的连接
|
// parser返回未知的错误码,需要断掉与客户端的连接
|
||||||
LOG_WARN("parser error number is unexpected, need disconnect", K(ret));
|
LOG_WARN("parser error number is unexpected, need disconnect", K(ret));
|
||||||
@ -4173,8 +4165,6 @@ int ObSql::pc_add_plan(ObPlanCacheCtx &pc_ctx,
|
|||||||
pc_ctx.sql_ctx_.spm_ctx_.bl_key_.sql_id_,
|
pc_ctx.sql_ctx_.spm_ctx_.bl_key_.sql_id_,
|
||||||
phy_plan->stat_.sql_id_))) {
|
phy_plan->stat_.sql_id_))) {
|
||||||
LOG_WARN("failed to ob write string", K(ret));
|
LOG_WARN("failed to ob write string", K(ret));
|
||||||
} else if (pc_ctx.is_rewrite_sql_ && OB_FAIL(phy_plan->set_rule_name(pc_ctx.rule_name_))) {
|
|
||||||
LOG_WARN("failed to ob write string", K(ret));
|
|
||||||
} else {
|
} else {
|
||||||
sql::ObUDRMgr *rule_mgr = MTL(sql::ObUDRMgr*);
|
sql::ObUDRMgr *rule_mgr = MTL(sql::ObUDRMgr*);
|
||||||
phy_plan->set_outline_state(outline_state);
|
phy_plan->set_outline_state(outline_state);
|
||||||
|
|||||||
@ -4962,6 +4962,27 @@ int ObSQLUtils::find_synonym_ref_obj(const ObString &database_name,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ObSQLUtils::check_need_disconnect_parser_err(const int ret_code)
|
||||||
|
{
|
||||||
|
bool bret = true;
|
||||||
|
if (OB_LIKELY(OB_ERR_PARSE_SQL == ret_code
|
||||||
|
|| OB_ERR_PARSER_SYNTAX == ret_code
|
||||||
|
|| OB_ERR_EMPTY_QUERY == ret_code
|
||||||
|
|| OB_SIZE_OVERFLOW == ret_code
|
||||||
|
|| OB_ERR_ILLEGAL_NAME == ret_code
|
||||||
|
|| OB_ERR_STR_LITERAL_TOO_LONG == ret_code
|
||||||
|
|| OB_ERR_NOT_VALID_ROUTINE_NAME == ret_code
|
||||||
|
|| OB_ERR_CONSTRUCT_MUST_RETURN_SELF == ret_code
|
||||||
|
|| OB_ERR_ONLY_FUNC_CAN_PIPELINED == ret_code
|
||||||
|
|| OB_ERR_NO_ATTR_FOUND == ret_code
|
||||||
|
|| OB_ERR_VIEW_SELECT_CONTAIN_QUESTIONMARK == ret_code
|
||||||
|
|| OB_ERR_NON_INT_LITERAL == ret_code
|
||||||
|
|| OB_ERR_PARSER_INIT == ret_code
|
||||||
|
|| OB_NOT_SUPPORTED == ret_code)) {
|
||||||
|
bret = false;
|
||||||
|
}
|
||||||
|
return bret;
|
||||||
|
}
|
||||||
|
|
||||||
int ObSQLUtils::find_synonym_ref_obj(const uint64_t database_id,
|
int ObSQLUtils::find_synonym_ref_obj(const uint64_t database_id,
|
||||||
const ObString &object_name,
|
const ObString &object_name,
|
||||||
|
|||||||
@ -592,6 +592,7 @@ public:
|
|||||||
uint64_t &object_id,
|
uint64_t &object_id,
|
||||||
share::schema::ObObjectType &obj_type,
|
share::schema::ObObjectType &obj_type,
|
||||||
uint64_t &schema_version);
|
uint64_t &schema_version);
|
||||||
|
static bool check_need_disconnect_parser_err(const int ret_code);
|
||||||
private:
|
private:
|
||||||
static int check_ident_name(const common::ObCollationType cs_type, common::ObString &name,
|
static int check_ident_name(const common::ObCollationType cs_type, common::ObString &name,
|
||||||
const bool check_for_path_char, const int64_t max_ident_len);
|
const bool check_for_path_char, const int64_t max_ident_len);
|
||||||
|
|||||||
@ -632,7 +632,7 @@ int ObPlanCacheValue::resolver_params(ObPlanCacheCtx &pc_ctx,
|
|||||||
if (OB_ISNULL(session)) {
|
if (OB_ISNULL(session)) {
|
||||||
ret = OB_INVALID_ARGUMENT;
|
ret = OB_INVALID_ARGUMENT;
|
||||||
SQL_PC_LOG(WARN, "invalid argument", K(ret), KP(session));
|
SQL_PC_LOG(WARN, "invalid argument", K(ret), KP(session));
|
||||||
} else if (obj_params != NULL) {
|
} else if (obj_params != NULL && PC_PS_MODE != pc_ctx.mode_ && PC_PL_MODE != pc_ctx.mode_) {
|
||||||
ObCollationType collation_connection = static_cast<ObCollationType>(
|
ObCollationType collation_connection = static_cast<ObCollationType>(
|
||||||
session->get_local_collation_connection());
|
session->get_local_collation_connection());
|
||||||
int64_t N = raw_params.count();
|
int64_t N = raw_params.count();
|
||||||
|
|||||||
@ -9,6 +9,7 @@
|
|||||||
#include "sql/ob_sql.h"
|
#include "sql/ob_sql.h"
|
||||||
#include "share/config/ob_server_config.h"
|
#include "share/config/ob_server_config.h"
|
||||||
#include "sql/resolver/ob_resolver_utils.h"
|
#include "sql/resolver/ob_resolver_utils.h"
|
||||||
|
#include "sql/ob_sql_utils.h"
|
||||||
#include "sql/udr/ob_udr_analyzer.h"
|
#include "sql/udr/ob_udr_analyzer.h"
|
||||||
#include "sql/udr/ob_udr_mgr.h"
|
#include "sql/udr/ob_udr_mgr.h"
|
||||||
#include "sql/udr/ob_udr_utils.h"
|
#include "sql/udr/ob_udr_utils.h"
|
||||||
@ -187,7 +188,7 @@ int ObUDRUtils::clac_dynamic_param_store(const DynamicParamInfoArray& dynamic_pa
|
|||||||
ParseNode *raw_param = NULL;
|
ParseNode *raw_param = NULL;
|
||||||
ObPCParam *pc_param = NULL;
|
ObPCParam *pc_param = NULL;
|
||||||
if (dynamic_param_info.raw_param_idx_ >= raw_params.count()) {
|
if (dynamic_param_info.raw_param_idx_ >= raw_params.count()) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_PARSER_SYNTAX;
|
||||||
LOG_WARN("invalid idx", K(dynamic_param_info.raw_param_idx_), K(raw_params.count()));
|
LOG_WARN("invalid idx", K(dynamic_param_info.raw_param_idx_), K(raw_params.count()));
|
||||||
} else if (OB_ISNULL(pc_param = raw_params.at(dynamic_param_info.raw_param_idx_))) {
|
} else if (OB_ISNULL(pc_param = raw_params.at(dynamic_param_info.raw_param_idx_))) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
@ -197,7 +198,7 @@ int ObUDRUtils::clac_dynamic_param_store(const DynamicParamInfoArray& dynamic_pa
|
|||||||
LOG_WARN("node is null", K(ret));
|
LOG_WARN("node is null", K(ret));
|
||||||
} else if (T_QUESTIONMARK == raw_param->type_) {
|
} else if (T_QUESTIONMARK == raw_param->type_) {
|
||||||
if (pc_ctx.mode_ != PC_PS_MODE || raw_param->value_ >= pc_ctx.fp_result_.parameterized_params_.count()) {
|
if (pc_ctx.mode_ != PC_PS_MODE || raw_param->value_ >= pc_ctx.fp_result_.parameterized_params_.count()) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_PARSER_SYNTAX;
|
||||||
LOG_WARN("invalid argument", K(ret), K(raw_param->value_), K(dynamic_param_info.raw_param_idx_),
|
LOG_WARN("invalid argument", K(ret), K(raw_param->value_), K(dynamic_param_info.raw_param_idx_),
|
||||||
K(pc_ctx.mode_), K(pc_ctx.fp_result_.parameterized_params_.count()));
|
K(pc_ctx.mode_), K(pc_ctx.fp_result_.parameterized_params_.count()));
|
||||||
} else if (OB_FAIL(param_store.push_back(*pc_ctx.fp_result_.parameterized_params_.at(raw_param->value_)))) {
|
} else if (OB_FAIL(param_store.push_back(*pc_ctx.fp_result_.parameterized_params_.at(raw_param->value_)))) {
|
||||||
@ -242,6 +243,7 @@ int ObUDRUtils::match_udr_and_refill_ctx(const ObString &pattern,
|
|||||||
bool enable_udr = false;
|
bool enable_udr = false;
|
||||||
is_match_udr = false;
|
is_match_udr = false;
|
||||||
ObSQLSessionInfo &session = result.get_session();
|
ObSQLSessionInfo &session = result.get_session();
|
||||||
|
ObExecContext &ectx = result.get_exec_context();
|
||||||
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(session.get_effective_tenant_id()));
|
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(session.get_effective_tenant_id()));
|
||||||
if (tenant_config.is_valid()) {
|
if (tenant_config.is_valid()) {
|
||||||
enable_udr = tenant_config->enable_user_defined_rewrite_rules;
|
enable_udr = tenant_config->enable_user_defined_rewrite_rules;
|
||||||
@ -266,6 +268,10 @@ int ObUDRUtils::match_udr_and_refill_ctx(const ObString &pattern,
|
|||||||
is_match_udr = true;
|
is_match_udr = true;
|
||||||
LOG_TRACE("succ to match user-defined rule", K(ret));
|
LOG_TRACE("succ to match user-defined rule", K(ret));
|
||||||
}
|
}
|
||||||
|
if (OB_SUCCESS != ret
|
||||||
|
&& !ObSQLUtils::check_need_disconnect_parser_err(ret)) {
|
||||||
|
ectx.set_need_disconnect(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user