[CP] Fix type deduce bugs

This commit is contained in:
hezuojiao
2024-11-18 13:14:40 +00:00
committed by ob-robot
parent 4abe952fd6
commit a1126f904d
5 changed files with 34 additions and 19 deletions

View File

@ -71,18 +71,30 @@ int ObExprLeastGreatest::calc_result_typeN_oracle(ObExprResType &type,
ObExprResType &first_type = types[0];
type = first_type;
ObObjTypeClass first_type_class = first_type.get_type_class();
/**
* number类型和其它类型行为不一致,单独处理
*/
if (ObIntTC == first_type_class
|| ObUIntTC == first_type_class
|| ObNumberTC == first_type_class
|| ObDecimalIntTC == first_type_class) {
type.set_type(ObNumberType);
type.set_calc_type(ObNumberType);
// scale和precision信息设置为unknown,兼容oracle的number行为
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
type.set_precision(PRECISION_UNKNOWN_YET);
if (ob_is_numeric_tc(first_type_class)) {
ObObjType highest_numeric_type = ObNumberType;
for (int64_t i = 0; i < param_num; ++i) {
if (ob_is_float_tc(types[i].get_type())) {
highest_numeric_type = ObFloatType;
} else if (ob_is_double_tc(types[i].get_type())) {
// binary double in oracle is the highest numeric type
highest_numeric_type = ObDoubleType;
break;
}
}
/**
* number类型和其它类型行为不一致,单独处理
*/
if (ObNumberType == highest_numeric_type) {
type.set_type(ObNumberType);
type.set_calc_type(ObNumberType);
// scale和precision信息设置为unknown,兼容oracle的number行为
type.set_scale(ORA_NUMBER_SCALE_UNKNOWN_YET);
type.set_precision(PRECISION_UNKNOWN_YET);
} else {
type.set_type(highest_numeric_type);
type.set_calc_type(highest_numeric_type);
}
} else if (ObLongTextType == type.get_type()) {
ret = OB_ERR_INVALID_TYPE_FOR_OP;
LOG_WARN("lob type parameter not expected", K(ret));

View File

@ -82,9 +82,7 @@ int ObExprToBase64::calc_result_type1(ObExprResType &type,
LOG_WARN("fail to get mbmaxlen", K(str.get_collation_type()), K(ret));
} else {
max_result_length = (base64_needed_encoded_length(str.get_length()) - 1) * mbmaxlen;
if (max_result_length > OB_MAX_BLOB_WIDTH) {
max_result_length = OB_MAX_BLOB_WIDTH;
}
max_result_length = MIN(MAX(0, max_result_length), OB_MAX_BLOB_WIDTH);
int64_t max_l = max_result_length / mbmaxlen;
int64_t max_deduce_length = max_l * mbmaxlen;
if (max_deduce_length < OB_MAX_MYSQL_VARCHAR_LENGTH) {

View File

@ -318,7 +318,9 @@ int ObExprSetToStr::inner_to_str(const ObCollationType cs_type,
++i, index = index << 1) {
if (set_val & (index)) {
const ObString &element_val = str_values.at(i);
if (OB_FAIL(text_result.append(element_val))) {
if (OB_UNLIKELY(element_val.empty())) {
// skip empty string and its separator
} else if (OB_FAIL(text_result.append(element_val))) {
LOG_WARN("fail to append str to lob result", K(ret), K(element_val));
} else if ((i + 1) < element_num && (i + 1) < EFFECTIVE_COUNT &&
((index << 1) <= set_val)) {

View File

@ -1203,7 +1203,7 @@ int ObRawExprDeduceType::check_expr_param(ObOpRawExpr &expr)
}
}
} else if (lib::is_oracle_mode()
&& (T_OP_EQ == expr.get_expr_type() || T_OP_NE == expr.get_expr_type())
&& (MAYBE_ROW_OP(expr.get_expr_type()))
&& (T_OP_ROW == expr.get_param_expr(0)->get_expr_type() ||
T_OP_ROW == expr.get_param_expr(1)->get_expr_type())) {
if (expr.get_param_expr(0)->get_expr_type() != T_OP_ROW
@ -3896,8 +3896,10 @@ int ObRawExprDeduceType::add_implicit_cast(ObOpRawExpr &parent,
ele_cnt = ele_cnt * child_ptr->get_param_expr(0)->get_param_count();
}
}
CK(idx + ele_cnt <= input_types.count());
if (OB_FAIL(ret)) {
} else if (OB_UNLIKELY(idx + ele_cnt > input_types.count())) {
ret = OB_INVALID_ARGUMENT_NUM;
LOG_WARN("invalid argument num", K(idx), K(ele_cnt), K(input_types.count()));
} else if (OB_FAIL(add_implicit_cast_for_op_row(
child_ptr,
ObExprTypeArrayHelper(

View File

@ -1330,7 +1330,8 @@ int ObResolver::resolve(IsPrepared if_prepared, const ParseNode &parse_tree, ObS
// todo yanli:检查主备库
}
if (OB_SUCC(ret) && stmt->is_dml_stmt() && !params_.session_info_->is_varparams_sql_prepare()) {
if (OB_SUCC(ret) && stmt->is_dml_stmt() && !params_.session_info_->is_varparams_sql_prepare()
&& lib::is_mysql_mode()) {
ObDMLStmt *dml_stmt = static_cast<ObDMLStmt*>(stmt);
ObRawExprWrapEnumSet enum_set_wrapper(*params_.expr_factory_, params_.session_info_);
if (OB_FAIL(enum_set_wrapper.wrap_enum_set(*dml_stmt))) {