[FEAT MERGE] 4.1 PL/SQL enhence & development
This commit is contained in:
@ -30,7 +30,7 @@ namespace sql
|
||||
|
||||
OB_SERIALIZE_MEMBER(
|
||||
(ObExprOpSubQueryInPl, ObFuncExprOperator),
|
||||
id_, type_, route_sql_, result_type_, is_ignore_fail_);
|
||||
id_, type_, route_sql_, result_type_, is_ignore_fail_, ps_sql_);
|
||||
|
||||
|
||||
ObExprOpSubQueryInPl::ObExprOpSubQueryInPl(common::ObIAllocator &alloc)
|
||||
@ -38,6 +38,7 @@ ObExprOpSubQueryInPl::ObExprOpSubQueryInPl(common::ObIAllocator &alloc)
|
||||
alloc, T_FUN_SUBQUERY, N_PL_SUBQUERY_CONSTRUCT,
|
||||
PARAM_NUM_UNKNOWN, NOT_ROW_DIMENSION, INTERNAL_IN_MYSQL_MODE),
|
||||
id_(common::OB_INVALID_ID),
|
||||
ps_sql_(ObString()),
|
||||
type_(stmt::T_NONE),
|
||||
route_sql_(ObString()),
|
||||
result_type_(),
|
||||
@ -57,7 +58,7 @@ int ObExprOpSubQueryInPl::assign(const ObExprOperator &other)
|
||||
if (OB_FAIL(ObExprOperator::assign(other))) {
|
||||
LOG_WARN("copy in Base class ObExprOperator failed", K(other), K(ret));
|
||||
} else {
|
||||
OX (this->id_ = tmp_other->id_);
|
||||
OZ (deep_copy_ps_sql(tmp_other->ps_sql_));
|
||||
OX (this->type_ = tmp_other->type_);
|
||||
OX (this->result_type_ = tmp_other->result_type_);
|
||||
OZ (deep_copy_route_sql(tmp_other->route_sql_));
|
||||
@ -124,17 +125,21 @@ int ObExprOpSubQueryInPl::eval_subquery(const ObExpr &expr,
|
||||
CK(OB_NOT_NULL(session = ctx.exec_ctx_.get_my_session()));
|
||||
CK (OB_NOT_NULL(ctx.exec_ctx_.get_sql_ctx()));
|
||||
|
||||
share::schema::ObSchemaGetterGuard schema_guard;
|
||||
observer::ObQueryRetryCtrl retry_ctrl;
|
||||
int64_t tenant_version = 0;
|
||||
int64_t sys_version = 0;
|
||||
bool is_stack_overflow = false;
|
||||
|
||||
if (info->id_ != common::OB_INVALID_ID) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "observer version need upate to 4.1 ver");
|
||||
}
|
||||
|
||||
OZ(check_stack_overflow(is_stack_overflow));
|
||||
if (OB_SUCC(ret) && is_stack_overflow) {
|
||||
ret = OB_SIZE_OVERFLOW;
|
||||
LOG_WARN("too deep recursive",
|
||||
K(ret), K(is_stack_overflow), K(info->id_), K(info->type_));
|
||||
K(ret), K(is_stack_overflow), K(info->ps_sql_), K(info->type_));
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
@ -152,67 +157,66 @@ int ObExprOpSubQueryInPl::eval_subquery(const ObExpr &expr,
|
||||
pl::ObPLExecCtx pl_exec_ctx(&alloc, &ctx.exec_ctx_, params, nullptr, &ret, nullptr);
|
||||
|
||||
SMART_VAR(ObSPIResultSet, spi_result) {
|
||||
OZ (spi_result.init(*session));
|
||||
OZ (spi_result.start_nested_stmt_if_need(&pl_exec_ctx, static_cast<stmt::StmtType>(info->type_)));
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
ObMySQLProxy::MySQLResult &mysql_result = spi_result.get_mysql_result();
|
||||
ObSPIOutParams out_params;
|
||||
int64_t old_query_start_time = session->get_query_start_time();
|
||||
session->set_query_start_time(ObTimeUtility::current_time());
|
||||
|
||||
bool is_retry = false;
|
||||
do {
|
||||
if (is_retry) {
|
||||
out_params.reset();
|
||||
spi_result.reset_member_for_retry(*session);
|
||||
}
|
||||
retry_ctrl.clear_state_before_each_retry(session->get_retry_info_for_update());
|
||||
if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(session->get_effective_tenant_id(),
|
||||
schema_guard))) {
|
||||
spi_result.get_scheme_guard()))) {
|
||||
LOG_WARN("get schema guard failed", K(ret));
|
||||
} else if (OB_FAIL(schema_guard.get_schema_version(session->get_effective_tenant_id(),
|
||||
} else if (OB_FAIL(spi_result.get_scheme_guard().get_schema_version(session->get_effective_tenant_id(),
|
||||
tenant_version))) {
|
||||
LOG_WARN("fail get schema version", K(ret));
|
||||
} else if (OB_FAIL(schema_guard.get_schema_version(OB_SYS_TENANT_ID, sys_version))) {
|
||||
} else if (OB_FAIL(spi_result.get_scheme_guard().get_schema_version(OB_SYS_TENANT_ID, sys_version))) {
|
||||
LOG_WARN("fail get sys schema version", K(ret));
|
||||
} else {
|
||||
retry_ctrl.set_tenant_local_schema_version(tenant_version);
|
||||
retry_ctrl.set_sys_local_schema_version(sys_version);
|
||||
|
||||
mysql_result.reset();
|
||||
|
||||
spi_result.get_sql_ctx().schema_guard_ = &spi_result.get_scheme_guard();
|
||||
OZ (ObSPIService::inner_open(&pl_exec_ctx,
|
||||
expr.arg_cnt_ == 0 ? info->route_sql_.ptr() : nullptr,
|
||||
info->id_,
|
||||
info->ps_sql_.ptr(),
|
||||
info->type_,
|
||||
*params,
|
||||
mysql_result,
|
||||
spi_result,
|
||||
out_params));
|
||||
|
||||
observer::ObInnerSQLResult *result_set =
|
||||
static_cast<observer::ObInnerSQLResult*>(mysql_result.get_result());
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
LOG_WARN("inner open error", K(ret));
|
||||
} else if (OB_FAIL(get_result(result_set, result, alloc))) {
|
||||
} else if (OB_FAIL(get_result(spi_result.get_result_set(), result, alloc))) {
|
||||
if (OB_ERR_TOO_MANY_ROWS != ret) {
|
||||
int cli_ret = OB_SUCCESS;
|
||||
retry_ctrl.test_and_save_retry_state(GCTX,
|
||||
*ctx.exec_ctx_.get_sql_ctx(),
|
||||
result_set->result_set(),
|
||||
ret, cli_ret, true);
|
||||
*spi_result.get_result_set(),
|
||||
ret, cli_ret, true, true, true);
|
||||
ret = cli_ret;
|
||||
}
|
||||
}
|
||||
session->set_session_in_retry(retry_ctrl.need_retry());
|
||||
|
||||
int64_t close_ret = mysql_result.close();
|
||||
int64_t close_ret = spi_result.get_result_set()->close();
|
||||
if (OB_SUCCESS != close_ret) {
|
||||
LOG_WARN("close spi result failed", K(ret), K(close_ret));
|
||||
}
|
||||
ret = OB_SUCCESS == ret ? close_ret : ret;
|
||||
}
|
||||
|
||||
is_retry = true;
|
||||
} while (observer::RETRY_TYPE_NONE != retry_ctrl.get_retry_type());
|
||||
session->get_retry_info_for_update().clear();
|
||||
session->set_query_start_time(old_query_start_time);
|
||||
}
|
||||
spi_result.get_mysql_result().reset();
|
||||
spi_result.end_nested_stmt_if_need(&pl_exec_ctx, ret);
|
||||
}
|
||||
}
|
||||
@ -280,15 +284,12 @@ int ObExprOpSubQueryInPl::fetch_row(void *result_set, int64_t &row_count, ObNewR
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("Argument passed in is NULL", K(result_set), K(ret));
|
||||
} else {
|
||||
observer::ObInnerSQLResult *inner_result =
|
||||
static_cast<observer::ObInnerSQLResult*>(result_set);
|
||||
if (OB_FAIL(inner_result->next())) {
|
||||
ObResultSet *ob_result_set = static_cast<ObResultSet*>(result_set);
|
||||
const ObNewRow *row = NULL;
|
||||
if (OB_FAIL(ob_result_set->get_next_row(row))) {
|
||||
//上层判断返回值,这里不打印信息
|
||||
} else if (OB_ISNULL(inner_result->get_row())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get a invalid row", K(ret));
|
||||
} else {
|
||||
cur_row = *inner_result->get_row();
|
||||
cur_row = *row;
|
||||
++row_count;
|
||||
}
|
||||
}
|
||||
@ -336,7 +337,8 @@ OB_DEF_SERIALIZE(ObExprPlSubQueryInfo)
|
||||
type_,
|
||||
route_sql_,
|
||||
result_type_,
|
||||
is_ignore_fail_);
|
||||
is_ignore_fail_,
|
||||
ps_sql_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -348,7 +350,8 @@ OB_DEF_DESERIALIZE(ObExprPlSubQueryInfo)
|
||||
type_,
|
||||
route_sql_,
|
||||
result_type_,
|
||||
is_ignore_fail_);
|
||||
is_ignore_fail_,
|
||||
ps_sql_);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -360,7 +363,8 @@ OB_DEF_SERIALIZE_SIZE(ObExprPlSubQueryInfo)
|
||||
type_,
|
||||
route_sql_,
|
||||
result_type_,
|
||||
is_ignore_fail_);
|
||||
is_ignore_fail_,
|
||||
ps_sql_);
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -371,13 +375,12 @@ int ObExprPlSubQueryInfo::deep_copy(common::ObIAllocator &allocator,
|
||||
int ret = common::OB_SUCCESS;
|
||||
OZ(ObExprExtraInfoFactory::alloc(allocator, type, copied_info));
|
||||
ObExprPlSubQueryInfo &other = *static_cast<ObExprPlSubQueryInfo *>(copied_info);
|
||||
other.id_ = id_;
|
||||
other.type_ = type_;
|
||||
other.result_type_ = result_type_;
|
||||
other.is_ignore_fail_ = is_ignore_fail_;
|
||||
|
||||
OZ(ob_write_string(allocator, route_sql_, other.route_sql_, true));
|
||||
|
||||
OZ(ob_write_string(allocator, ps_sql_, other.ps_sql_, true));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -388,12 +391,13 @@ int ObExprPlSubQueryInfo::from_raw_expr(RE &raw_expr, ObIAllocator &alloc)
|
||||
ObPlQueryRefRawExpr &subquery_expr =
|
||||
const_cast<ObPlQueryRefRawExpr &> (static_cast<const ObPlQueryRefRawExpr&>(raw_expr));
|
||||
|
||||
id_ = subquery_expr.get_ps_id();
|
||||
id_ = common::OB_INVALID_ID;
|
||||
type_ = subquery_expr.get_stmt_type();
|
||||
result_type_ = subquery_expr.get_result_type();
|
||||
is_ignore_fail_ = subquery_expr.is_ignore_fail();
|
||||
|
||||
OZ(ob_write_string(alloc, subquery_expr.get_route_sql(), route_sql_, true));
|
||||
OZ(ob_write_string(alloc, subquery_expr.get_route_sql(), ps_sql_, true));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user