fix the bug of not check collation valid when set session variable

This commit is contained in:
qingzhu521 2024-11-29 07:19:30 +00:00 committed by ob-robot
parent 8e70a77d11
commit 325dc0031d
2 changed files with 51 additions and 8 deletions

View File

@ -1881,7 +1881,11 @@ int ObSysVarOnCheckFuncs::check_and_convert_charset(ObExecContext &ctx,
UNUSED(ctx);
int ret = OB_SUCCESS;
ObString cs_name;
if (true == set_var.is_set_default_) {
ObSQLSessionInfo *session = NULL;
if (OB_ISNULL(session = ctx.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session is NULL", K(ret));
} else if (true == set_var.is_set_default_) {
// do nothing
} else if (true == in_val.is_null()) {
// do nothing
@ -1899,6 +1903,12 @@ int ObSysVarOnCheckFuncs::check_and_convert_charset(ObExecContext &ctx,
ret = OB_ERR_UNEXPECTED;
LOG_ERROR("charset is valid, but it has no default collation", K(ret),
K(cs_name), K(cs_type));
} else if (OB_FAIL(sql::ObSQLUtils::is_charset_data_version_valid(static_cast<ObCharsetType>(cs_type),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to check charset data version valid", K(ret));
} else if (OB_FAIL(sql::ObSQLUtils::is_collation_data_version_valid(static_cast<ObCollationType>(coll_type),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to check collation data version valid", K(ret));
} else {
out_val.set_int(static_cast<int64_t>(coll_type));
}
@ -1917,6 +1927,12 @@ int ObSysVarOnCheckFuncs::check_and_convert_charset(ObExecContext &ctx,
ObString cs_name_str(val_buf);
LOG_USER_ERROR(OB_ERR_UNKNOWN_CHARSET, cs_name_str.length(), cs_name_str.ptr());
}
} else if (OB_FAIL(sql::ObSQLUtils::is_charset_data_version_valid(common::ObCharset::charset_type_by_coll(static_cast<ObCollationType>(int64_val)),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to check charset data version valid", K(ret));
} else if (OB_FAIL(sql::ObSQLUtils::is_collation_data_version_valid(static_cast<ObCollationType>(int64_val),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to check collation data version valid", K(ret));
} else {
out_val = in_val;
}
@ -1976,7 +1992,11 @@ int ObSysVarOnCheckFuncs::check_and_convert_collation_not_null(ObExecContext &ct
UNUSED(sys_var);
UNUSED(ctx);
int ret = OB_SUCCESS;
if (true == set_var.is_set_default_) {
ObSQLSessionInfo *session = NULL;
if (OB_ISNULL(session = ctx.get_my_session())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("session is NULL", K(ret));
} else if (true == set_var.is_set_default_) {
// do nothing
} else if (true == in_val.is_null()) {
ret = OB_ERR_WRONG_VALUE_FOR_VAR;
@ -2008,6 +2028,12 @@ int ObSysVarOnCheckFuncs::check_and_convert_collation_not_null(ObExecContext &ct
ObString coll_name_str(val_buf);
LOG_USER_ERROR(OB_ERR_UNKNOWN_COLLATION, coll_name_str.length(), coll_name_str.ptr());
}
} else if (OB_FAIL(sql::ObSQLUtils::is_charset_data_version_valid(common::ObCharset::charset_type_by_coll(static_cast<ObCollationType>(int64_val)),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to check charset data version valid", K(ret));
} else if (OB_FAIL(sql::ObSQLUtils::is_collation_data_version_valid(static_cast<ObCollationType>(int64_val),
session->get_effective_tenant_id()))) {
LOG_WARN("failed to check collation data version valid", K(ret));
} else {
out_val = in_val;
}

View File

@ -669,16 +669,33 @@ int ObSQLUtils::is_collation_data_version_valid(ObCollationType collation_type,
ret = OB_NOT_SUPPORTED;
SQL_LOG(WARN, "Unicode collation not supported when data_version < 4_2_4_0 or between [430,433)", K(collation_type), K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Unicode collation not supported when data_version < 4_2_4_0 or between [430,433), unicode collation is");
} else if ((data_version < MOCK_DATA_VERSION_4_2_5_0
|| (data_version >= DATA_VERSION_4_3_0_0 && data_version < DATA_VERSION_4_3_4_0))
&& (CS_TYPE_UTF8MB4_ZH_0900_AS_CS != collation_type &&
} else if ((
data_version < MOCK_DATA_VERSION_4_2_5_0 ||
(data_version >= DATA_VERSION_4_3_0_0 && data_version < DATA_VERSION_4_3_4_0)
)
&&
(
CS_TYPE_UTF8MB4_ZH_0900_AS_CS != collation_type &&
CS_TYPE_UTF8MB4_CROATIAN_UCA_CI != collation_type &&
CS_TYPE_UTF8MB4_UNICODE_520_CI != collation_type &&
CS_TYPE_UTF8MB4_CZECH_UCA_CI != collation_type &&
CS_TYPE_UTF8MB4_0900_AI_CI != collation_type &&
((CS_TYPE_UTF8MB4_0900_AI_CI <= collation_type && collation_type <= CS_TYPE_UTF8MB4_MN_CYRL_0900_AS_CS)
|| (CS_TYPE_UTF16_ICELANDIC_UCA_CI <= collation_type && collation_type <= CS_TYPE_UTF16_VIETNAMESE_CI)
|| (CS_TYPE_UTF8MB4_ICELANDIC_UCA_CI <= collation_type && collation_type <= CS_TYPE_UTF8MB4_VIETNAMESE_CI)))) {
((CS_TYPE_UTF8MB4_0900_AI_CI <= collation_type && collation_type <= CS_TYPE_UTF8MB4_MN_CYRL_0900_AS_CS)
|| (CS_TYPE_UTF16_ICELANDIC_UCA_CI <= collation_type && collation_type <= CS_TYPE_UTF16_VIETNAMESE_CI)
|| (CS_TYPE_UTF8MB4_ICELANDIC_UCA_CI <= collation_type && collation_type <= CS_TYPE_UTF8MB4_VIETNAMESE_CI)
|| CS_TYPE_BIG5_BIN == collation_type
|| CS_TYPE_BIG5_CHINESE_CI == collation_type
|| CS_TYPE_LATIN1_GERMAN2_CI == collation_type
|| CS_TYPE_LATIN1_GERMAN1_CI == collation_type
|| CS_TYPE_LATIN1_SWEDISH_CI == collation_type
|| CS_TYPE_LATIN1_DANISH_CI == collation_type
|| CS_TYPE_LATIN1_SPANISH_CI == collation_type
|| CS_TYPE_HKSCS31_BIN == collation_type
|| CS_TYPE_HKSCS_BIN == collation_type
|| CS_TYPE_DEC8_BIN == collation_type
|| CS_TYPE_DEC8_SWEDISH_CI == collation_type
)
)) {
ret = OB_NOT_SUPPORTED;
SQL_LOG(WARN, "Unicode collation not supported when data_version < 4_2_5_0 or between [430,434)", K(collation_type), K(ret));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Unicode collation not supported when data_version < 4_2_5_0 or between [430,434), unicode collation is");