[CP] fixbug: Error 4109 reported when renaming both the foreign key master and slave tables simultaneously

This commit is contained in:
obdev
2024-02-27 05:51:23 +00:00
committed by ob-robot
parent 94b823f86f
commit e1e2dc75a6
2 changed files with 63 additions and 58 deletions

View File

@ -6712,45 +6712,52 @@ int ObResolverUtils::check_foreign_key_columns_type(const bool is_mysql_compat_m
LOG_USER_ERROR(OB_ERR_TOO_MANY_ROWKEY_COLUMNS, OB_USER_MAX_ROWKEY_COLUMN_NUMBER);
LOG_WARN("the count of foreign key columns should be between [1,64]", K(ret), K(child_columns.count()), K(parent_columns.count()));
} else {
uint64_t child_table_id = child_table_schema.get_table_id();
uint64_t parent_table_id = parent_table_schema.get_table_id();
for (int64_t i = 0; OB_SUCC(ret) && i < parent_columns.count(); ++i) {
const ObColumnSchemaV2 *child_col = NULL;
const ObColumnSchemaV2 *parent_col = parent_table_schema.get_column_schema(parent_columns.at(i));
if (NULL == column) { // table-level fk
child_col = child_table_schema.get_column_schema(child_columns.at(i));
} else { // column level fk
child_col = column;
}
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(child_col)) {
ret = OB_ERR_COLUMN_NOT_FOUND;
LOG_WARN("child column is not exist", K(ret));
} else if (OB_ISNULL(parent_col)) {
ret = OB_ERR_COLUMN_NOT_FOUND;
LOG_WARN("parent column is not exist", K(ret));
} else if ((child_col->get_data_type() != parent_col->get_data_type())
&& !is_synonymous_type(child_col->get_data_type(),
parent_col->get_data_type())) {
// 这里类型必须相同的
if (child_table_id == parent_table_id && 0 == parent_columns.at(i).compare(child_columns.at(i))) {
ret = OB_ERR_CANNOT_ADD_FOREIGN;
LOG_WARN("Column data types between child table and parent table are different", K(ret),
K(child_col->get_data_type()),
K(parent_col->get_data_type()));
} else if (ob_is_string_type(child_col->get_data_type())) {
// 列类型一致,对于数据宽度要求子表大于父表, 目前只考虑 string 类型,
if (child_col->get_collation_type() != parent_col->get_collation_type()) {
LOG_WARN("Child table is same as parent table and child column is same as parant column", K(ret), K(child_table_id), K(parent_table_id), K(parent_columns.at(i)), K(child_columns.at(i)));
} else {
const ObColumnSchemaV2 *child_col = NULL;
const ObColumnSchemaV2 *parent_col = parent_table_schema.get_column_schema(parent_columns.at(i));
if (NULL == column) { // table-level fk
child_col = child_table_schema.get_column_schema(child_columns.at(i));
} else { // column level fk
child_col = column;
}
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(child_col)) {
ret = OB_ERR_COLUMN_NOT_FOUND;
LOG_WARN("child column is not exist", K(ret));
} else if (OB_ISNULL(parent_col)) {
ret = OB_ERR_COLUMN_NOT_FOUND;
LOG_WARN("parent column is not exist", K(ret));
} else if ((child_col->get_data_type() != parent_col->get_data_type())
&& !is_synonymous_type(child_col->get_data_type(),
parent_col->get_data_type())) {
// 这里类型必须相同的
ret = OB_ERR_CANNOT_ADD_FOREIGN;
LOG_WARN("The collation types are different", K(ret),
K(child_col->get_collation_type()),
K(parent_col->get_collation_type()));
} else if (is_mysql_compat_mode &&
(child_col->get_data_length() < parent_col->get_data_length())) {
ret = OB_ERR_INVALID_CHILD_COLUMN_LENGTH_FK;
LOG_USER_ERROR(OB_ERR_INVALID_CHILD_COLUMN_LENGTH_FK,
child_col->get_column_name_str().length(),
child_col->get_column_name_str().ptr(),
parent_col->get_column_name_str().length(),
parent_col->get_column_name_str().ptr());
} else { } // 对于其他bit/int/number /datetime/time/year 不做data_length要求
LOG_WARN("Column data types between child table and parent table are different", K(ret),
K(child_col->get_data_type()),
K(parent_col->get_data_type()));
} else if (ob_is_string_type(child_col->get_data_type())) {
// 列类型一致,对于数据宽度要求子表大于父表, 目前只考虑 string 类型,
if (child_col->get_collation_type() != parent_col->get_collation_type()) {
ret = OB_ERR_CANNOT_ADD_FOREIGN;
LOG_WARN("The collation types are different", K(ret),
K(child_col->get_collation_type()),
K(parent_col->get_collation_type()));
} else if (is_mysql_compat_mode &&
(child_col->get_data_length() < parent_col->get_data_length())) {
ret = OB_ERR_INVALID_CHILD_COLUMN_LENGTH_FK;
LOG_USER_ERROR(OB_ERR_INVALID_CHILD_COLUMN_LENGTH_FK,
child_col->get_column_name_str().length(),
child_col->get_column_name_str().ptr(),
parent_col->get_column_name_str().length(),
parent_col->get_column_name_str().ptr());
} else { } // 对于其他bit/int/number /datetime/time/year 不做data_length要求
}
}
}
}