fix transform distinct aggregate with const distinct param
This commit is contained in:
parent
5bdc2c4c5e
commit
07d31c9703
@ -103,9 +103,10 @@ int ObTransformDistinctAggregate::check_transform_validity(const ObDMLStmt *stmt
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("agg expr is null", K(ret), K(i));
|
||||
} else if (aggr_expr->is_param_distinct()) {
|
||||
if (1 < aggr_expr->get_real_param_count()
|
||||
&& T_FUN_COUNT != aggr_expr->get_expr_type()
|
||||
&& T_FUN_GROUP_CONCAT != aggr_expr->get_expr_type()) {
|
||||
if (1 > aggr_expr->get_real_param_count()
|
||||
|| (1 < aggr_expr->get_real_param_count()
|
||||
&& T_FUN_COUNT != aggr_expr->get_expr_type()
|
||||
&& T_FUN_GROUP_CONCAT != aggr_expr->get_expr_type())) {
|
||||
is_valid = false;
|
||||
OPT_TRACE("can not do transform, stmt has distinct aggregate functions with more than one params");
|
||||
} else if (!aggr_expr->get_order_items().empty() || aggr_expr->contain_nested_aggr()) {
|
||||
@ -294,12 +295,22 @@ int ObTransformDistinctAggregate::construct_view_group_exprs(const ObIArray<ObRa
|
||||
if (OB_ISNULL(param_expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("param expr is null", K(ret), K(i), KPC(distinct_aggr.at(0)));
|
||||
} else if (param_expr->is_static_const_expr()) {
|
||||
} else if (param_expr->is_static_scalar_const_expr()) {
|
||||
// do nothing, do not need to add static const expr into group exprs
|
||||
} else if (OB_FAIL(add_var_to_array_no_dup(view_group_exprs, param_expr))) {
|
||||
LOG_WARN("failed to add distinct aggr param", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret) && view_group_exprs.empty()) {
|
||||
// If all of the distinct params are static const exprs, we need to add one
|
||||
// param expr into view_group_exprs to keep the aggregate semantics.
|
||||
if (OB_UNLIKELY(1 > distinct_aggr.at(0)->get_real_param_count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("distinct aggr does not have param", K(ret), KPC(distinct_aggr.at(0)));
|
||||
} else if (OB_FAIL(view_group_exprs.push_back(distinct_aggr.at(0)->get_real_param_exprs().at(0)))) {
|
||||
LOG_WARN("failed to push back group exprs", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -4444,7 +4444,7 @@ int ObTransformUtils::compute_set_stmt_property(const ObSelectStmt *stmt,
|
||||
check_helper.session_info_,
|
||||
stmt, set_exprs, equal_conds))) {
|
||||
LOG_WARN("failed to get equal set conditions", K(ret));
|
||||
} else if (FALSE_IT(res_info.equal_sets_.reuse())) {
|
||||
} else if (FALSE_IT(res_info.equal_sets_.reset())) {
|
||||
} else if (OB_FAIL(ObEqualAnalysis::compute_equal_set(check_helper.alloc_, equal_conds,
|
||||
tmp_equal_sets, res_info.equal_sets_))) {
|
||||
LOG_WARN("failed to compute compute equal set", K(ret));
|
||||
@ -4598,7 +4598,7 @@ void ObTransformUtils::UniqueCheckInfo::reset()
|
||||
{
|
||||
table_set_.clear_all();
|
||||
const_exprs_.reuse();
|
||||
equal_sets_.reuse();
|
||||
equal_sets_.reset();
|
||||
fd_sets_.reuse();
|
||||
candi_fd_sets_.reuse();
|
||||
not_null_.reuse();
|
||||
@ -16707,7 +16707,7 @@ int ObTransformUtils::check_const_select(ObTransformerCtx *ctx,
|
||||
if (OB_ISNULL(ctx) || OB_ISNULL(stmt)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret), K(ctx), K(stmt));
|
||||
} else if (OB_FALSE_IT(ctx->equal_sets_.reuse())) {
|
||||
} else if (OB_FALSE_IT(ctx->equal_sets_.reset())) {
|
||||
} else if (OB_FAIL(stmt->get_stmt_equal_sets(ctx->equal_sets_, alloc, true, true))) {
|
||||
LOG_WARN("failed to get stmt equal sets", K(ret));
|
||||
} else if (OB_FAIL(ObOptimizerUtil::compute_const_exprs(stmt->get_condition_exprs(),
|
||||
@ -16723,7 +16723,7 @@ int ObTransformUtils::check_const_select(ObTransformerCtx *ctx,
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
ctx->equal_sets_.reuse();
|
||||
ctx->equal_sets_.reset();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user