fix subquery pullup bug and fix select into plan bug

This commit is contained in:
zzg19950727
2023-02-06 17:32:09 +08:00
committed by ob-robot
parent 41a9e671ee
commit 998db59e91
4 changed files with 45 additions and 9 deletions

View File

@ -56,3 +56,23 @@ int ObLogSelectInto::compute_plan_type()
} else { /*do nothing*/ }
return ret;
}
int ObLogSelectInto::get_op_exprs(ObIArray<ObRawExpr*> &all_exprs)
{
int ret = OB_SUCCESS;
const ObDMLStmt *stmt = NULL;
const ObSelectStmt *sel_stmt = NULL;
if (OB_ISNULL(get_plan()) || OB_ISNULL(stmt = get_plan()->get_stmt())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret));
} else if (!stmt->is_select_stmt()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected stmt type", K(ret));
} else if (OB_FALSE_IT(sel_stmt = static_cast<const ObSelectStmt*>(stmt))) {
} else if (OB_FAIL(sel_stmt->get_select_exprs(output_exprs_))) {
LOG_WARN("failed to get select exprs", K(ret));
} else if (OB_FAIL(ObLogicalOperator::get_op_exprs(all_exprs))) {
LOG_WARN("failed to get op exprs", K(ret));
} else { /*do nothing*/ }
return ret;
}

View File

@ -99,6 +99,7 @@ public:
}
virtual int est_cost() override;
virtual int compute_plan_type() override;
virtual int get_op_exprs(ObIArray<ObRawExpr*> &all_exprs) override;
private:
ObItemType into_type_;
common::ObObj outfile_name_;

View File

@ -11310,13 +11310,21 @@ int ObTransformUtils::replace_none_correlated_expr(ObRawExpr *&expr,
is_correlated))) {
LOG_WARN("failed to check is correlated expr", K(ret));
} else if (!is_correlated) {
if (pos >= new_column_list.count()) {
if (expr->is_exec_param_expr()) {
//do nothing
} else if (pos >= new_column_list.count()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpect array pos", K(pos), K(new_column_list), K(ret));
} else {
expr = new_column_list.at(pos);
++pos;
}
} else if (T_OP_EXISTS == expr->get_expr_type() ||
T_OP_NOT_EXISTS == expr->get_expr_type() ||
IS_SUBQUERY_COMPARISON_OP(expr->get_expr_type()) ||
T_FUN_SYS_CAST == expr->get_expr_type()) {
//exists(subquery)、cast(expr as type)、c1 > any(subquery)
//do nothing
} else {
int64_t N = expr->get_param_count();
for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) {
@ -11368,22 +11376,21 @@ int ObTransformUtils::pullup_correlated_expr(const ObQueryRefRawExpr &query_ref,
} else if (OB_FAIL(new_select_list.push_back(expr))) {
LOG_WARN("failed to push back expr", K(ret));
}
} else if (T_OP_EXISTS == expr->get_expr_type() ||
T_OP_NOT_EXISTS == expr->get_expr_type() ||
IS_SUBQUERY_COMPARISON_OP(expr->get_expr_type()) ||
T_FUN_SYS_CAST == expr->get_expr_type()) {
//exists(subquery)、cast(expr as type)、c1 > any(subquery)
//do nothing
} else {
int64_t N = expr->get_param_count();
bool param_correlated = false;
for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) {
bool param_correlated = false;
if (OB_FAIL(SMART_CALL(pullup_correlated_expr(query_ref,
expr->get_param_expr(i),
new_select_list,
param_correlated)))) {
LOG_WARN("failed to pullup correlated expr", K(ret));
} else {
is_correlated = param_correlated || is_correlated;
}
}
if (OB_SUCC(ret) && !is_correlated) {
if (OB_FAIL(new_select_list.push_back(expr))) {
LOG_WARN("failed to push back expr", K(ret));
}
}
}

View File

@ -585,6 +585,10 @@ int ObWhereSubQueryPullup::pullup_correlated_subquery_as_view(ObDMLStmt *stmt,
LOG_WARN("failed to decorrelate semi conditions", K(ret));
} else if (OB_FAIL(generate_semi_info(stmt, expr, right_table, semi_conds, info))) {
LOG_WARN("failed to generate semi info", K(ret));
} else if (OB_FAIL(stmt->adjust_subquery_list())) {
LOG_WARN("failed to adjust subquery list", K(ret));
} else if (OB_FAIL(subquery->adjust_subquery_list())) {
LOG_WARN("failed to adjust subquery list", K(ret));
} else if (OB_FAIL(subquery->formalize_stmt(ctx_->session_info_))) {
LOG_WARN("formalize child stmt failed", K(ret));
}
@ -1014,6 +1018,10 @@ int ObWhereSubQueryPullup::pullup_non_correlated_subquery_as_view(ObDMLStmt *stm
LOG_WARN("failed to generate new condition exprs", K(ret));
} else if (OB_FAIL(generate_semi_info(stmt, expr, table_item, new_conditions, info))) {
LOG_WARN("generate semi info failed", K(ret));
} else if (OB_FAIL(stmt->adjust_subquery_list())) {
LOG_WARN("failed to adjust subquery list", K(ret));
} else if (OB_FAIL(subquery->adjust_subquery_list())) {
LOG_WARN("failed to adjust subquery list", K(ret));
} else if (OB_FAIL(subquery->formalize_stmt(ctx_->session_info_))) {
LOG_WARN("formalize child stmt failed", K(ret));
}