diff --git a/deps/oblib/src/common/object/ob_object.cpp b/deps/oblib/src/common/object/ob_object.cpp index 9e98c4f1d3..6e9f646533 100644 --- a/deps/oblib/src/common/object/ob_object.cpp +++ b/deps/oblib/src/common/object/ob_object.cpp @@ -1050,7 +1050,7 @@ bool ObObj::is_zero() const return ret; } -int ObObj::build_not_strict_default_value() +int ObObj::build_not_strict_default_value(int16_t precision) { int ret = OB_SUCCESS; const ObObjType &data_type = meta_.get_type(); @@ -1190,7 +1190,14 @@ int ObObj::build_not_strict_default_value() break; } case ObDecimalIntType: { - set_decimal_int(0, 0, nullptr); + const ObDecimalInt *decint = nullptr; + int32_t int_bytes = 0; + if (OB_FAIL(wide::ObDecimalIntConstValue::get_zero_value_byte_precision(precision, decint, + int_bytes))) { + _OB_LOG(WARN, "get zero value failed, ret=%u", ret); + } else { + set_decimal_int(int_bytes, 0, const_cast(decint)); + } break; } default: diff --git a/deps/oblib/src/common/object/ob_object.h b/deps/oblib/src/common/object/ob_object.h index c65b10d15e..d6d3ebe715 100644 --- a/deps/oblib/src/common/object/ob_object.h +++ b/deps/oblib/src/common/object/ob_object.h @@ -1219,7 +1219,7 @@ public: explicit ObObj(ObObjType type); inline void reset(); //when in not strict sql mode, build default value refer to data type - int build_not_strict_default_value(); + int build_not_strict_default_value(int16_t precision); static ObObj make_min_obj(); static ObObj make_max_obj(); static ObObj make_nop_obj(); diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h b/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h index e09df421f5..8bba26a285 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_result.h @@ -1063,7 +1063,7 @@ { \ def_obj.set_type(data_type); \ if (is_mysql_mode()) { \ - if (OB_FAIL(def_obj.build_not_strict_default_value())) { \ + if (OB_FAIL(def_obj.build_not_strict_default_value(column.get_data_precision()))) { \ SQL_LOG(WARN, "failed to build not strict default json value", K(ret)); \ } else { \ res_obj.set_json_value(data_type, def_obj.get_string().ptr(), \ diff --git a/deps/oblib/src/lib/wide_integer/ob_wide_integer.cpp b/deps/oblib/src/lib/wide_integer/ob_wide_integer.cpp index cd26af86dc..3b6195aae5 100644 --- a/deps/oblib/src/lib/wide_integer/ob_wide_integer.cpp +++ b/deps/oblib/src/lib/wide_integer/ob_wide_integer.cpp @@ -84,6 +84,8 @@ const ObDecimalInt *ObDecimalIntConstValue::MAX_DECINT[OB_MAX_DECIMAL_POSSIBLE_P const ObDecimalInt *ObDecimalIntConstValue::MAX_UPPER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1] = {nullptr}; const ObDecimalInt *ObDecimalIntConstValue::MIN_LOWER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1] = {nullptr}; +const ObDecimalInt *ObDecimalIntConstValue::ZERO_VALUES[5] = {nullptr}; + // init ObDecimalIntConstValue int ObDecimalIntConstValue::init_const_values(ObIAllocator &alloc, const lib::ObMemAttr &attr) { @@ -143,6 +145,20 @@ int ObDecimalIntConstValue::init_const_values(ObIAllocator &alloc, const lib::Ob MAX_UPPER[precision] = max_decint; } } // for end + // init zero values + char *zero_buf = nullptr; + int buf_size = sizeof(int32_t) + sizeof(int64_t) + sizeof(int128_t) + sizeof(int256_t) + sizeof(int512_t); + if (OB_ISNULL(zero_buf = (char *)allocator.alloc(buf_size))) { + ret = OB_ALLOCATE_MEMORY_FAILED; + COMMON_LOG(WARN, "allocate memory failed", K(ret)); + } else { + MEMSET(zero_buf, 0, buf_size); + ZERO_VALUES[0] = reinterpret_cast(zero_buf); + ZERO_VALUES[1] = reinterpret_cast(zero_buf + sizeof(int32_t)); + ZERO_VALUES[2] = reinterpret_cast(zero_buf + sizeof(int32_t) + sizeof(int64_t)); + ZERO_VALUES[3] = reinterpret_cast(zero_buf + sizeof(int32_t) + sizeof(int64_t) + sizeof(int128_t)); + ZERO_VALUES[3] = reinterpret_cast(zero_buf + sizeof(int32_t) + sizeof(int64_t) + sizeof(int128_t) + sizeof(int256_t)); + } return ret; } diff --git a/deps/oblib/src/lib/wide_integer/ob_wide_integer_helper.h b/deps/oblib/src/lib/wide_integer/ob_wide_integer_helper.h index 9b62000bb1..d1012eb240 100644 --- a/deps/oblib/src/lib/wide_integer/ob_wide_integer_helper.h +++ b/deps/oblib/src/lib/wide_integer/ob_wide_integer_helper.h @@ -431,6 +431,20 @@ public: } } + inline static int get_zero_value_byte_precision(int16_t precision, const ObDecimalInt *&decint, int32_t &int_bytes) + { + int ret = OB_SUCCESS; + ObDecimalIntWideType dec_type = get_decimalint_type(precision); + if (OB_UNLIKELY(dec_type == DECIMAL_INT_MAX)) { + ret = OB_ERR_UNEXPECTED; + COMMON_LOG(WARN, "invalid precision", K(precision)); + } else { + decint = ZERO_VALUES[dec_type]; + int_bytes = ((int32_t(1)) << dec_type) * sizeof(int32_t); + } + return ret; + } + inline static const ObDecimalInt* get_max_upper(ObPrecision prec) { OB_ASSERT(prec <= OB_MAX_DECIMAL_POSSIBLE_PRECISION); @@ -463,6 +477,8 @@ private: static const ObDecimalInt *MAX_UPPER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1]; // MYSQL_MIN_LOWER static const ObDecimalInt *MIN_LOWER[OB_MAX_DECIMAL_POSSIBLE_PRECISION + 1]; + + static const ObDecimalInt *ZERO_VALUES[5]; }; // helper functions diff --git a/src/rootserver/ob_ddl_service.cpp b/src/rootserver/ob_ddl_service.cpp index 594accab1a..0dee5c5b7c 100755 --- a/src/rootserver/ob_ddl_service.cpp +++ b/src/rootserver/ob_ddl_service.cpp @@ -6611,7 +6611,7 @@ int ObDDLService::resolve_orig_default_value(ObColumnSchemaV2 &alter_column_sche } else { ObObj default_value; default_value.set_type(alter_column_schema.get_data_type()); - if (OB_FAIL(default_value.build_not_strict_default_value())) { + if (OB_FAIL(default_value.build_not_strict_default_value(alter_column_schema.get_accuracy().get_precision()))) { LOG_WARN("failed to build not strict default value", K(ret)); } else if (OB_FAIL(alter_column_schema.set_orig_default_value(default_value))) { LOG_WARN("failed to set orig default value", K(ret)); diff --git a/src/sql/resolver/dml/ob_default_value_utils.cpp b/src/sql/resolver/dml/ob_default_value_utils.cpp index 20e351fac9..fdd6b07f1c 100644 --- a/src/sql/resolver/dml/ob_default_value_utils.cpp +++ b/src/sql/resolver/dml/ob_default_value_utils.cpp @@ -755,7 +755,7 @@ int ObDefaultValueUtils::build_default_expr_not_strict_static( default_value.set_null(); } else { default_value.set_type(column_schema->get_data_type()); - if (OB_FAIL(default_value.build_not_strict_default_value())) { + if (OB_FAIL(default_value.build_not_strict_default_value(column_schema->get_accuracy().get_precision()))) { LOG_WARN("failed to build not strict default value info", K(column_schema), K(ret)); } else if (default_value.is_string_type()) { default_value.set_collation_level(CS_LEVEL_IMPLICIT); @@ -810,7 +810,7 @@ int ObDefaultValueUtils::build_default_expr_not_strict(const ColumnItem *column, default_value.set_null(); } else { default_value.set_type(column->get_column_type()->get_type()); - if (OB_FAIL(default_value.build_not_strict_default_value())) { + if (OB_FAIL(default_value.build_not_strict_default_value(column->get_column_type()->get_accuracy().get_precision()))) { LOG_WARN("failed to build not strict default value info", K(column), K(ret)); } else if (default_value.is_string_type()) { default_value.set_collation_level(CS_LEVEL_IMPLICIT);