[CP] Fix shared expr bug and datetime bug
This commit is contained in:
parent
385bda30b9
commit
9da9109c53
@ -2119,14 +2119,52 @@ int ObRelationalExprOperator::deduce_cmp_type(const ObExprOperator &expr,
|
||||
ObExprOperator::calc_result_flag2(type, type1, type2);
|
||||
bool need_no_cast = can_cmp_without_cast(
|
||||
type1, type2, get_cmp_op(expr.get_type()), *type_ctx.get_session());
|
||||
type1.set_calc_type(need_no_cast ? type1.get_type() : cmp_type.get_calc_type());
|
||||
type2.set_calc_type(need_no_cast ? type2.get_type() : cmp_type.get_calc_type());
|
||||
if (ob_is_string_or_lob_type(cmp_type.get_calc_type())) {
|
||||
type1.set_calc_collation_type(cmp_type.get_calc_collation_type());
|
||||
type2.set_calc_collation_type(cmp_type.get_calc_collation_type());
|
||||
} else if (ObRawType == cmp_type.get_calc_type()) {
|
||||
type1.set_calc_collation_type(CS_TYPE_BINARY);
|
||||
type2.set_calc_collation_type(CS_TYPE_BINARY);
|
||||
if (!need_no_cast && is_mysql_mode()) {
|
||||
// to be compatiable with mysql:
|
||||
// if c1 is date or datetime, convert 'c1 = c2+1'to cast (c1 as double) = cast (c2+1 as double)
|
||||
const ObRawExpr* cmp_expr = type_ctx.get_raw_expr();
|
||||
const ObRawExpr* date_expr = cmp_expr->get_param_expr(0);
|
||||
const ObRawExpr* other_expr = cmp_expr->get_param_expr(1);
|
||||
ObObjType other_expr_type = ObMaxType;
|
||||
bool is_date_op_other = false;
|
||||
if (OB_ISNULL(cmp_expr) || OB_ISNULL(date_expr) || OB_ISNULL(other_expr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret), K(cmp_expr));
|
||||
} else if (date_expr->get_result_type().get_type() == ObDateType ||
|
||||
date_expr->get_result_type().get_type() == ObDateTimeType) {
|
||||
other_expr_type = other_expr->get_result_type().get_type();
|
||||
is_date_op_other = true;
|
||||
} else if (other_expr->get_result_type().get_type() == ObDateType ||
|
||||
other_expr->get_result_type().get_type() == ObDateTimeType) {
|
||||
const ObRawExpr *tmp_expr = date_expr;
|
||||
date_expr = other_expr;
|
||||
other_expr = tmp_expr;
|
||||
other_expr_type = other_expr->get_result_type().get_type();
|
||||
is_date_op_other = true;
|
||||
} else {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret) &&
|
||||
is_mysql_mode() &&
|
||||
is_date_op_other &&
|
||||
(ob_is_accurate_numeric_type(other_expr_type) || ob_is_real_type(other_expr_type)) &&
|
||||
!(other_expr->is_const_expr() && !date_expr->is_const_expr())) {
|
||||
cmp_type.set_calc_type(ObDoubleType);
|
||||
type.set_calc_collation(cmp_type);
|
||||
type.set_calc_type(cmp_type.get_calc_type());
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
type1.set_calc_type(need_no_cast ? type1.get_type() : cmp_type.get_calc_type());
|
||||
type2.set_calc_type(need_no_cast ? type2.get_type() : cmp_type.get_calc_type());
|
||||
if (ob_is_string_or_lob_type(cmp_type.get_calc_type())) {
|
||||
type1.set_calc_collation_type(cmp_type.get_calc_collation_type());
|
||||
type2.set_calc_collation_type(cmp_type.get_calc_collation_type());
|
||||
} else if (ObRawType == cmp_type.get_calc_type()) {
|
||||
type1.set_calc_collation_type(CS_TYPE_BINARY);
|
||||
type2.set_calc_collation_type(CS_TYPE_BINARY);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -856,13 +856,34 @@ int ObSelectResolver::check_group_by()
|
||||
// 1. select item/having/order item中的表达式树(子树)需要每个都在group by列中找到
|
||||
// 2. 递归查找是否在groupby列中,将在groupby的列的指针替换。
|
||||
if (OB_SUCC(ret)) {
|
||||
if (ObTransformUtils::replace_stmt_expr_with_groupby_exprs(select_stmt)) {
|
||||
if (OB_FAIL(replace_stmt_expr_with_groupby_exprs(select_stmt, params_.query_ctx_))) {
|
||||
LOG_WARN("failed to replace stmt expr with groupby columns", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObSelectResolver::replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
ObQueryCtx *query_ctx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSEArray<ObPCConstParamInfo, 4> pc_constraints;
|
||||
ObSEArray<ObPCParamEqualInfo, 4> eq_constraints;
|
||||
if (OB_ISNULL(query_ctx)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("unexpected null", K(ret), K(query_ctx));
|
||||
} else if (OB_FAIL(ObTransformUtils::inner_replace_stmt_expr_with_groupby_exprs(select_stmt, params_.param_list_, pc_constraints, eq_constraints))) {
|
||||
LOG_WARN("failed to replace stmt expr with groupby columns", K(ret));
|
||||
} else if (OB_FAIL(append_array_no_dup(query_ctx->all_plan_const_param_constraints_, pc_constraints))) {
|
||||
LOG_WARN("failed to append const param info", K(ret));
|
||||
} else if (OB_FAIL(append_array_no_dup(query_ctx->all_possible_const_param_constraints_, pc_constraints))) {
|
||||
LOG_WARN("failed to append const param info", K(ret));
|
||||
} else if (OB_FAIL(append_array_no_dup(query_ctx->all_equal_param_constraints_, eq_constraints))) {
|
||||
LOG_WARN("failed to append const param info", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 1. lob type can't be ordered
|
||||
// 2. the order item should be exists in select items if has distinct
|
||||
int ObSelectResolver::check_order_by()
|
||||
|
@ -428,6 +428,8 @@ private:
|
||||
int add_name_for_anonymous_view();
|
||||
int add_name_for_anonymous_view_recursive(TableItem *table_item);
|
||||
|
||||
int replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_stmt, ObQueryCtx *query_ctx);
|
||||
|
||||
protected:
|
||||
// data members
|
||||
/*these member is only for with clause*/
|
||||
|
@ -1229,7 +1229,7 @@ int ObTransformPreProcess::create_set_view_stmt(ObSelectStmt *origin_stmt,
|
||||
1
|
||||
so that 1 in "select c1-1 from t1 group by grouping sets(c1,1);" share same expr.
|
||||
*/
|
||||
if (OB_FAIL(ObTransformUtils::replace_stmt_expr_with_groupby_exprs(origin_stmt, ctx_))) {
|
||||
if (OB_FAIL(ObTransformUtils::replace_stmt_expr_with_groupby_exprs(origin_stmt, ctx_, true))) {
|
||||
LOG_WARN("failed to replace stmt expr with groupby columns", K(ret));
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < count; i++) {
|
||||
@ -1269,7 +1269,7 @@ int ObTransformPreProcess::create_set_view_stmt(ObSelectStmt *origin_stmt,
|
||||
groupby_stmt->get_window_func_exprs().reset();
|
||||
ObSEArray<ObRawExpr*, 4> old_exprs;
|
||||
ObSEArray<ObRawExpr*, 4> new_exprs;
|
||||
if (OB_FAIL(ObTransformUtils::replace_stmt_expr_with_groupby_exprs(groupby_stmt))) {
|
||||
if (OB_FAIL(ObTransformUtils::replace_stmt_expr_with_groupby_exprs(groupby_stmt, ctx_))) {
|
||||
LOG_WARN("failed to replace stmt expr with groupby columns", K(ret));
|
||||
} else if (OB_FAIL(create_select_list_from_grouping_sets(groupby_stmt,
|
||||
groupby_exprs_list,
|
||||
|
@ -9116,7 +9116,7 @@ int ObTransformUtils::add_const_param_constraints(ObRawExpr *expr,
|
||||
} else {
|
||||
ObPCConstParamInfo param_info;
|
||||
ObObj target_obj;
|
||||
ObConstRawExpr *const_expr = static_cast<ObConstRawExpr*>(params.at(0));
|
||||
ObConstRawExpr *const_expr = static_cast<ObConstRawExpr*>(params.at(i));
|
||||
int64_t param_idx = const_expr->get_value().get_unknown();
|
||||
if (OB_UNLIKELY(param_idx < 0 || param_idx >= plan_ctx->get_param_store().count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
@ -9137,18 +9137,45 @@ int ObTransformUtils::add_const_param_constraints(ObRawExpr *expr,
|
||||
}
|
||||
|
||||
int ObTransformUtils::replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
ObTransformerCtx *trans_ctx,
|
||||
bool need_check_add_expr) {
|
||||
int ret = OB_SUCCESS;
|
||||
ObPhysicalPlanCtx *plan_ctx = NULL;
|
||||
ObSEArray<ObPCConstParamInfo, 4> pc_constraints;
|
||||
ObSEArray<ObPCParamEqualInfo, 4> eq_constraints;
|
||||
if (OB_ISNULL(trans_ctx) || OB_ISNULL(trans_ctx->exec_ctx_) || OB_ISNULL(plan_ctx = trans_ctx->exec_ctx_->get_physical_plan_ctx())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret), K(trans_ctx), K(plan_ctx));
|
||||
} else if (OB_FAIL(inner_replace_stmt_expr_with_groupby_exprs(select_stmt, &plan_ctx->get_param_store(), pc_constraints, eq_constraints, need_check_add_expr ? trans_ctx : NULL))) {
|
||||
LOG_WARN("fail to replace stmt expr with group by exprs", K(ret));
|
||||
} else if (OB_FAIL(append_array_no_dup(trans_ctx->plan_const_param_constraints_, pc_constraints))) {
|
||||
LOG_WARN("failed to append const param info", K(ret));
|
||||
} else if (OB_FAIL(append_array_no_dup(trans_ctx->equal_param_constraints_, eq_constraints))) {
|
||||
LOG_WARN("failed to append const param info", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//pc_constraints are for non-paramlized groupby exprs while eq_constraints are for paramlized groupby exprs
|
||||
int ObTransformUtils::inner_replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
const ParamStore *param_store,
|
||||
ObIArray<ObPCConstParamInfo>& pc_constraints,
|
||||
ObIArray<ObPCParamEqualInfo> & eq_constraints,
|
||||
ObTransformerCtx *trans_ctx/*default null*/)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_ISNULL(select_stmt)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret));
|
||||
LOG_WARN("get unexpected null", K(ret), K(select_stmt));
|
||||
} else {
|
||||
common::ObIArray<SelectItem>& select_items = select_stmt->get_select_items();
|
||||
ObSEArray<int64_t, 4> param_expr_idxs;
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < select_items.count(); i++) {
|
||||
if (OB_FAIL(replace_with_groupby_exprs(select_stmt,
|
||||
select_items.at(i).expr_,
|
||||
true,
|
||||
param_expr_idxs,
|
||||
eq_constraints,
|
||||
trans_ctx))) {
|
||||
LOG_WARN("failed to replace with groupby columns.", K(ret));
|
||||
} else { /*do nothing.*/ }
|
||||
@ -9158,6 +9185,8 @@ int ObTransformUtils::replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_
|
||||
if (OB_FAIL(replace_with_groupby_exprs(select_stmt,
|
||||
having_exprs.at(i),
|
||||
true,
|
||||
param_expr_idxs,
|
||||
eq_constraints,
|
||||
trans_ctx))) {
|
||||
LOG_WARN("failed to replace with groupby columns.", K(ret));
|
||||
} else { /*do nothing.*/ }
|
||||
@ -9167,10 +9196,35 @@ int ObTransformUtils::replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_
|
||||
if (OB_FAIL(replace_with_groupby_exprs(select_stmt,
|
||||
order_items.at(i).expr_,
|
||||
false,
|
||||
param_expr_idxs,
|
||||
eq_constraints,
|
||||
trans_ctx))) {
|
||||
LOG_WARN("failed to replace with groupby columns.", K(ret));
|
||||
} else { /*do nothing.*/ }
|
||||
}
|
||||
if (OB_SUCC(ret) && param_expr_idxs.count() > 0) {
|
||||
//build pc_constraints
|
||||
if (OB_ISNULL(param_store)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected null", K(ret), K(param_store));
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < param_expr_idxs.count(); i++) {
|
||||
ObPCConstParamInfo const_param_info;
|
||||
int64_t param_idx = param_expr_idxs.at(i);
|
||||
if (OB_UNLIKELY(param_idx < 0 || param_idx >= param_store->count())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected error", K(ret), K(param_idx),
|
||||
K(param_store->count()));
|
||||
} else if (OB_FAIL(const_param_info.const_idx_.push_back(param_idx))) {
|
||||
LOG_WARN("failed to push back param idx", K(ret));
|
||||
} else if (OB_FAIL(const_param_info.const_params_.push_back(param_store->at(param_idx)))) {
|
||||
LOG_WARN("failed to push back value", K(ret));
|
||||
} else if (OB_FAIL(pc_constraints.push_back(const_param_info))) {
|
||||
LOG_WARN("failed to push back param info", K(ret));
|
||||
} else {/*do nothing*/}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -9178,7 +9232,9 @@ int ObTransformUtils::replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_
|
||||
int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
ObRawExpr *&expr,
|
||||
bool need_query_compare,
|
||||
ObTransformerCtx *trans_ctx/*default null*/,
|
||||
ObIArray<int64_t> & param_expr_idxs,
|
||||
ObIArray<ObPCParamEqualInfo> & eq_constraints,
|
||||
ObTransformerCtx *trans_ctx,
|
||||
bool in_add_expr/*default false*/)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
@ -9186,6 +9242,8 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
check_context.reset();
|
||||
check_context.override_const_compare_ = true;
|
||||
check_context.override_query_compare_ = need_query_compare;
|
||||
common::ObSEArray<ObExprEqualCheckContext::ParamExprPair, 4> param_exprs_local;
|
||||
common::ObSEArray<ObPCParamEqualInfo, 4> equal_params_local;
|
||||
if (OB_ISNULL(expr) || OB_ISNULL(select_stmt) || OB_ISNULL(select_stmt->get_query_ctx())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("got an unexpected null", K(ret));
|
||||
@ -9203,6 +9261,8 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
if (OB_FAIL(SMART_CALL(replace_with_groupby_exprs(select_stmt,
|
||||
expr->get_param_expr(i),
|
||||
need_query_compare,
|
||||
param_expr_idxs,
|
||||
eq_constraints,
|
||||
trans_ctx,
|
||||
T_OP_ADD == expr->get_expr_type())))) {
|
||||
LOG_WARN("failed to replace with groupby columns.", K(ret));
|
||||
@ -9214,22 +9274,40 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
ObIArray<ObGroupingSetsItem> &grouping_sets_items = select_stmt->get_grouping_sets_items();
|
||||
ObIArray<ObMultiRollupItem> &multi_rollup_items = select_stmt->get_multi_rollup_items();
|
||||
for (int64_t i = 0; OB_SUCC(ret) && !is_existed && i < groupby_exprs.count(); i++) {
|
||||
check_context.param_expr_.reset();
|
||||
check_context.equal_param_info_.reset();
|
||||
if (OB_ISNULL(groupby_exprs.at(i))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("got an unexpected null", K(ret));
|
||||
} else if (groupby_exprs.at(i)->same_as(*expr, &check_context)) {
|
||||
expr = groupby_exprs.at(i);
|
||||
is_existed = true;
|
||||
// add_var_to_array_no_dup
|
||||
if (OB_FAIL(append(param_exprs_local, check_context.param_expr_))) {
|
||||
LOG_WARN("fail to append param expr", K(ret));
|
||||
} else if (OB_FAIL(append(equal_params_local, check_context.equal_param_info_))) {
|
||||
LOG_WARN("fail to append equal param info", K(ret));
|
||||
} else {
|
||||
expr = groupby_exprs.at(i);
|
||||
is_existed = true;
|
||||
}
|
||||
} else { /*do nothing.*/ }
|
||||
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && !is_existed && i < rollup_exprs.count(); i++) {
|
||||
check_context.param_expr_.reset();
|
||||
check_context.equal_param_info_.reset();
|
||||
if (OB_ISNULL(rollup_exprs.at(i))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("got an unexpected null", K(ret));
|
||||
} else if (rollup_exprs.at(i)->same_as(*expr, &check_context) &&
|
||||
(lib::is_mysql_mode() || !expr->is_const_expr())) {
|
||||
expr = rollup_exprs.at(i);
|
||||
is_existed = true;
|
||||
if (OB_FAIL(append(param_exprs_local, check_context.param_expr_))) {
|
||||
LOG_WARN("fail to append param expr", K(ret));
|
||||
} else if (OB_FAIL(append(equal_params_local, check_context.equal_param_info_))) {
|
||||
LOG_WARN("fail to append equal param info", K(ret));
|
||||
} else {
|
||||
expr = rollup_exprs.at(i);
|
||||
is_existed = true;
|
||||
}
|
||||
} else { /*do nothing.*/ }
|
||||
}
|
||||
for (int64_t i = 0; OB_SUCC(ret) && !is_existed && i < grouping_sets_items.count(); i++) {
|
||||
@ -9237,12 +9315,20 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
for (int64_t j = 0; OB_SUCC(ret) && !is_existed && j < grouping_sets_exprs.count(); j++) {
|
||||
ObIArray<ObRawExpr*> &groupby_exprs = grouping_sets_exprs.at(j).groupby_exprs_;
|
||||
for (int64_t k = 0; OB_SUCC(ret) && !is_existed && k < groupby_exprs.count(); k++) {
|
||||
check_context.param_expr_.reset();
|
||||
check_context.equal_param_info_.reset();
|
||||
if (OB_ISNULL(groupby_exprs.at(k))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("got an unexpected null", K(ret));
|
||||
} else if (groupby_exprs.at(k)->same_as(*expr, &check_context)) {
|
||||
expr = groupby_exprs.at(k);
|
||||
is_existed = true;
|
||||
if (OB_FAIL(append(param_exprs_local, check_context.param_expr_))) {
|
||||
LOG_WARN("fail to append param expr", K(ret));
|
||||
} else if (OB_FAIL(append(equal_params_local, check_context.equal_param_info_))) {
|
||||
LOG_WARN("fail to append equal param info", K(ret));
|
||||
} else {
|
||||
expr = groupby_exprs.at(k);
|
||||
is_existed = true;
|
||||
}
|
||||
} else if (trans_ctx != NULL && in_add_expr &&
|
||||
expr->get_expr_type() == T_QUESTIONMARK &&
|
||||
groupby_exprs.at(k)->get_expr_type() == T_QUESTIONMARK &&
|
||||
@ -9258,6 +9344,7 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
if (OB_FAIL(replace_add_exprs_with_groupby_exprs(expr,
|
||||
groupby_exprs.at(k),
|
||||
trans_ctx,
|
||||
equal_params_local,
|
||||
is_existed))) {
|
||||
LOG_WARN("replace exprs in add failed", K(ret));
|
||||
}
|
||||
@ -9271,12 +9358,20 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
for (int64_t k = 0; OB_SUCC(ret) && !is_existed && k < rollup_list_exprs.count(); k++) {
|
||||
ObIArray<ObRawExpr*> &groupby_exprs = rollup_list_exprs.at(k).groupby_exprs_;
|
||||
for (int64_t m = 0; OB_SUCC(ret) && !is_existed && m < groupby_exprs.count(); m++) {
|
||||
check_context.param_expr_.reset();
|
||||
check_context.equal_param_info_.reset();
|
||||
if (OB_ISNULL(groupby_exprs.at(m))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("got an unexpected null", K(ret));
|
||||
} else if (groupby_exprs.at(m)->same_as(*expr, &check_context)) {
|
||||
expr = groupby_exprs.at(m);
|
||||
is_existed = true;
|
||||
if (OB_FAIL(append(param_exprs_local, check_context.param_expr_))) {
|
||||
LOG_WARN("fail to append param expr", K(ret));
|
||||
} else if (OB_FAIL(append(equal_params_local, check_context.equal_param_info_))) {
|
||||
LOG_WARN("fail to append equal param info", K(ret));
|
||||
} else {
|
||||
expr = groupby_exprs.at(m);
|
||||
is_existed = true;
|
||||
}
|
||||
} else { /*do nothing.*/ }
|
||||
}
|
||||
}
|
||||
@ -9289,17 +9384,36 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
for (int64_t j = 0; OB_SUCC(ret) && !is_existed && j < rollup_list_exprs.count(); j++) {
|
||||
ObIArray<ObRawExpr*> &groupby_exprs = rollup_list_exprs.at(j).groupby_exprs_;
|
||||
for (int64_t k = 0; OB_SUCC(ret) && !is_existed && k < groupby_exprs.count(); k++) {
|
||||
check_context.param_expr_.reset();
|
||||
check_context.equal_param_info_.reset();
|
||||
if (OB_ISNULL(groupby_exprs.at(k))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("got an unexpected null", K(ret));
|
||||
} else if (groupby_exprs.at(k)->same_as(*expr, &check_context)) {
|
||||
expr = groupby_exprs.at(k);
|
||||
is_existed = true;
|
||||
if (OB_FAIL(append(param_exprs_local, check_context.param_expr_))) {
|
||||
LOG_WARN("fail to append param expr", K(ret));
|
||||
} else if (OB_FAIL(append(equal_params_local, check_context.equal_param_info_))) {
|
||||
LOG_WARN("fail to append equal param info", K(ret));
|
||||
} else {
|
||||
expr = groupby_exprs.at(k);
|
||||
is_existed = true;
|
||||
}
|
||||
} else { /*do nothing.*/ }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
if (OB_FAIL(append_array_no_dup(eq_constraints, equal_params_local))) {
|
||||
LOG_WARN("fail to append equal param info", K(ret));
|
||||
} else {
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < param_exprs_local.count(); ++i) {
|
||||
if (OB_FAIL(add_var_to_array_no_dup(param_expr_idxs, param_exprs_local.at(i).param_idx_))) {
|
||||
LOG_WARN("fail to append equal param constraints", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -9307,6 +9421,7 @@ int ObTransformUtils::replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
int ObTransformUtils::replace_add_exprs_with_groupby_exprs(ObRawExpr *&expr_l,
|
||||
ObRawExpr *expr_r,
|
||||
ObTransformerCtx *trans_ctx,
|
||||
ObIArray<ObPCParamEqualInfo> & eq_constraints,
|
||||
bool &is_existed)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
@ -9339,8 +9454,14 @@ int ObTransformUtils::replace_add_exprs_with_groupby_exprs(ObRawExpr *&expr_l,
|
||||
} else if (check_objparam_negative(left_param) && !check_objparam_negative(right_param)) {
|
||||
// replace the expr with a T_OP_NEG expr who's child is groupby_exprs.at(k);
|
||||
ObOpRawExpr *neg = NULL;
|
||||
ObPCParamEqualInfo eq_info;
|
||||
eq_info.first_param_idx_ = idx_left;
|
||||
eq_info.first_param_idx_ = idx_right;
|
||||
eq_info.use_abs_cmp_ = true;
|
||||
if (OB_FAIL(expr_factory->create_raw_expr(T_OP_NEG, neg))) {
|
||||
LOG_WARN("failed to create neg expr", K(ret));
|
||||
} else if (OB_FAIL(eq_constraints.push_back(eq_info))) {
|
||||
LOG_WARN("failed to push back equal param", K(ret));
|
||||
} else if (OB_ISNULL(expr_l = neg)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("neg expr is NULL", K(ret));
|
||||
|
@ -1338,12 +1338,20 @@ public:
|
||||
static int add_const_param_constraints(ObRawExpr *expr,
|
||||
ObTransformerCtx *ctx);
|
||||
|
||||
static int replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
static int inner_replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
const ParamStore *param_store,
|
||||
ObIArray<ObPCConstParamInfo>& pc_constrants,
|
||||
ObIArray<ObPCParamEqualInfo> & eq_constraints,
|
||||
ObTransformerCtx *trans_ctx = NULL);
|
||||
|
||||
static int replace_stmt_expr_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
ObTransformerCtx *trans_ctx,
|
||||
bool need_check_add_expr = false);
|
||||
|
||||
static int replace_add_exprs_with_groupby_exprs(ObRawExpr *&expr_l,
|
||||
ObRawExpr *expr_r,
|
||||
ObTransformerCtx *trans_ctx,
|
||||
ObIArray<ObPCParamEqualInfo> & eq_constraints,
|
||||
bool &is_existed);
|
||||
|
||||
static bool check_objparam_abs_equal(const ObObjParam &obj1, const ObObjParam &obj2);
|
||||
@ -1357,8 +1365,11 @@ public:
|
||||
static int replace_with_groupby_exprs(ObSelectStmt *select_stmt,
|
||||
ObRawExpr *&expr,
|
||||
bool need_query_compare,
|
||||
ObIArray<int64_t>& param_expr_idxs,
|
||||
ObIArray<ObPCParamEqualInfo> & eq_constraints,
|
||||
ObTransformerCtx *tran_ctx = NULL,
|
||||
bool in_add_expr = false);
|
||||
static int add_constraint_for_groupby_expr(ObTransformerCtx *trans_ctx, ObSelectStmt *select_stmt, ObRawExpr* groupby_expr, ObRawExpr* old_expr);
|
||||
|
||||
static int add_param_not_null_constraint(ObTransformerCtx &ctx,
|
||||
ObIArray<ObRawExpr *> ¬_null_exprs);
|
||||
|
@ -950,7 +950,7 @@ Query Plan
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([cast(t.tinyint_t, DATETIME(-1, -1)) = t.datetime_t]), filter(nil), rowset=256,
|
||||
0 - output([cast(t.tinyint_t, DOUBLE(-1, -1)) = cast(t.datetime_t, DOUBLE(-1, -1))]), filter(nil), rowset=256,
|
||||
access([t.tinyint_t], [t.datetime_t]), partitions(p0),
|
||||
limit(1), offset(nil)
|
||||
|
||||
@ -990,7 +990,7 @@ Query Plan
|
||||
|
||||
Outputs & filters:
|
||||
-------------------------------------
|
||||
0 - output([cast(t.tinyint_t, DATE(-1, -1)) = t.date_t]), filter(nil), rowset=256,
|
||||
0 - output([cast(t.tinyint_t, DOUBLE(-1, -1)) = cast(t.date_t, DOUBLE(-1, -1))]), filter(nil), rowset=256,
|
||||
access([t.tinyint_t], [t.date_t]), partitions(p0),
|
||||
limit(1), offset(nil)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user