fix: decimal int not handled properly for values stmt

This commit is contained in:
PatZhuang 2024-11-15 11:18:38 +00:00 committed by ob-robot
parent 4148bbff34
commit e17fa92572
4 changed files with 31 additions and 5 deletions

View File

@ -245,10 +245,22 @@ int ObValuesTableAccessOp::calc_datum_from_param(const ObObj &src_obj, ObExpr *d
ObDatum &dst_datum = dst_expr->locate_datum_for_write(eval_ctx_);
const ObObjType &src_type = src_obj.get_type();
const ObObjType &dst_type = dst_expr->obj_meta_.get_type();
if (ob_is_decimal_int_tc(src_type) && ob_is_number_tc(dst_type)) {
const ObObjParam src_obj_param = static_cast<const ObObjParam>(src_obj);
bool need_adjust_decimal_int = ob_is_decimal_int_tc(src_type)
&& ob_is_decimal_int_tc(dst_expr->datum_meta_.type_)
&& ObDatumCast::need_scale_decimalint(src_obj_param.get_scale(),
src_obj_param.get_precision(),
dst_expr->datum_meta_.scale_,
dst_expr->datum_meta_.precision_);
if (ob_is_decimal_int_tc(src_type) && (ob_is_number_tc(dst_type) || need_adjust_decimal_int)) {
ObObj dst_obj;
const ObDataTypeCastParams dtc_params = ObBasicSessionInfo::create_dtc_params(GET_MY_SESSION(ctx_));
ObCastCtx cast_ctx(&eval_ctx_.exec_ctx_.get_allocator(), &dtc_params, cm_, dst_expr->obj_meta_.get_collation_type());
ObAccuracy dst_accuracy = ObAccuracy::DDL_DEFAULT_ACCURACY2[is_oracle_mode()][dst_type];
if (ob_is_decimal_int_tc(dst_type)) {
dst_accuracy.set_scale(dst_expr->datum_meta_.scale_);
dst_accuracy.set_precision(dst_expr->datum_meta_.precision_);
}
ObCastCtx cast_ctx(&eval_ctx_.exec_ctx_.get_allocator(), &dtc_params, cm_, dst_expr->obj_meta_.get_collation_type(), &dst_accuracy);
cast_ctx.exec_ctx_ = &eval_ctx_.exec_ctx_;
if (OB_FAIL(ObObjCaster::to_type(dst_type, dst_expr->obj_meta_.get_collation_type(), cast_ctx,
src_obj, dst_obj))) {

View File

@ -95,6 +95,7 @@ int ObPlanCacheObject::set_params_info(const ParamStore &params)
} else {
param_info.ext_real_type_ = data_type.get_obj_type();
param_info.scale_ = data_type.get_scale();
param_info.precision_ = data_type.get_precision();
}
LOG_DEBUG("ext params info", K(data_type), K(param_info), K(params.at(i)));
} else if (params.at(i).get_param_meta().is_ext() || params.at(i).is_user_defined_sql_type() || params.at(i).is_collection_sql_type()) {

View File

@ -272,6 +272,10 @@ int ObPlanSet::match_param_info(const ObParamInfo &param_info,
// do nothing
} else if (OB_FAIL(ObSQLUtils::get_ext_obj_data_type(param, data_type))) {
LOG_WARN("fail to get obj data_type", K(ret), K(param));
} else if (data_type.get_obj_type() == ObDecimalIntType) {
is_same = param_info.ext_real_type_ == ObDecimalIntType
&& data_type.get_scale() == param_info.scale_
&& match_decint_precision(param_info, data_type.get_precision());
} else if (data_type.get_scale() == param_info.scale_ &&
data_type.get_obj_type() == param_info.ext_real_type_) {
is_same = true;
@ -2469,6 +2473,9 @@ bool ObPlanSet::match_decint_precision(const ObParamInfo &param_info, ObPrecisio
bool ret = false;
if (ob_is_decimal_int(param_info.type_)) {
ret = (param_info.precision_ == other_prec);
} else if (ob_is_extend(param_info.type_) && ob_is_decimal_int(param_info.ext_real_type_)) {
ret = wide::ObDecimalIntConstValue::get_int_bytes_by_precision(param_info.precision_)
== wide::ObDecimalIntConstValue::get_int_bytes_by_precision(other_prec);
} else {
// not decimal_int, return true
ret = true;

View File

@ -171,9 +171,15 @@ int ObInListResolver::check_inlist_rewrite_enable(const ParseNode &in_list,
if (OB_ISNULL(session_info)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get unexpected null", K(ret), KP(session_info));
} else if (T_WHERE_SCOPE != scope || !is_root_condition || T_OP_IN != op_type ||
T_EXPR_LIST != in_list.type_ || is_need_print || session_info->is_varparams_sql_prepare() ||
(NULL != stmt && stmt->is_select_stmt() && static_cast<const ObSelectStmt *>(stmt)->is_hierarchical_query())) {
} else if (T_WHERE_SCOPE != scope
|| !is_root_condition
|| (T_OP_IN != op_type && T_OP_NOT_IN != op_type)
|| T_EXPR_LIST != in_list.type_
|| is_need_print
|| session_info->is_varparams_sql_prepare()
|| (NULL != stmt
&& stmt->is_select_stmt()
&& static_cast<const ObSelectStmt *>(stmt)->is_hierarchical_query())) {
LOG_TRACE("no need rewrite inlist", K(is_root_condition), K(scope), K(in_list.type_),
K(op_type), K(is_need_print), K(session_info->is_varparams_sql_prepare()));
} else {