[CP] Fix shared expr bug and datetime bug
This commit is contained in:
@ -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;
|
||||
|
||||
Reference in New Issue
Block a user