From d4730c71fe28f6ea319eaef3887cff5501bf109f Mon Sep 17 00:00:00 2001 From: obdev Date: Wed, 25 Oct 2023 06:43:15 +0000 Subject: [PATCH] fix bug, drop hash key has not same error code like mysql and oracle --- src/share/ob_errno.cpp | 6 ++-- src/share/ob_errno.def | 3 +- src/share/ob_errno.h | 2 +- .../resolver/ddl/ob_alter_table_resolver.cpp | 29 +++++++++++++++++++ .../resolver/ddl/ob_alter_table_resolver.h | 3 ++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/share/ob_errno.cpp b/src/share/ob_errno.cpp index eb9cf44df..3cec611e6 100755 --- a/src/share/ob_errno.cpp +++ b/src/share/ob_errno.cpp @@ -12365,9 +12365,9 @@ static const _error _error_OB_ERR_DEPENDENT_BY_PARTITION_FUNC = { .sqlstate = "HY000", .str_error = "Column has a partitioning function dependency and cannot be dropped or renamed.", .str_user_error = "Column '%.*s' has a partitioning function dependency and cannot be dropped or renamed.", - .oracle_errno = 600, - .oracle_str_error = "ORA-00600: internal error code, arguments: -5502, Column has a partitioning function dependency and cannot be dropped or renamed.", - .oracle_str_user_error = "ORA-00600: internal error code, arguments: -5502, Column '%.*s' has a partitioning function dependency and cannot be dropped or renamed." + .oracle_errno = 12984, + .oracle_str_error = "ORA-12984: cannot drop partitioning column", + .oracle_str_user_error = "ORA-12984: cannot drop partitioning column '%.*s'" }; static const _error _error_OB_ERR_VIEW_SELECT_CONTAIN_INTO = { .error_name = "OB_ERR_VIEW_SELECT_CONTAIN_INTO", diff --git a/src/share/ob_errno.def b/src/share/ob_errno.def index 444e91365..cc8b8d057 100755 --- a/src/share/ob_errno.def +++ b/src/share/ob_errno.def @@ -1150,8 +1150,7 @@ DEFINE_ERROR(OB_ERR_GENCOL_LEGIT_CHECK_FAILED, -5500, -1, "HY000", "Legitimacy c DEFINE_ORACLE_ERROR(OB_ERR_GROUPING_FUNC_WITHOUT_GROUP_BY, -5501, -1, "42000", "GROUPING function only supported with GROUP BY CUBE or ROLLUP", 30481, "GROUPING function only supported with GROUP BY CUBE or ROLLUP"); // for rename column in mysql mode -DEFINE_ERROR_EXT(OB_ERR_DEPENDENT_BY_PARTITION_FUNC, -5502, ER_DEPENDENT_BY_PARTITION_FUNC, "HY000", "Column has a partitioning function dependency and cannot be dropped or renamed.", "Column '%.*s' has a partitioning function dependency and cannot be dropped or renamed."); - +DEFINE_ORACLE_ERROR_EXT(OB_ERR_DEPENDENT_BY_PARTITION_FUNC, -5502, ER_DEPENDENT_BY_PARTITION_FUNC, "HY000", "Column has a partitioning function dependency and cannot be dropped or renamed.", "Column '%.*s' has a partitioning function dependency and cannot be dropped or renamed.", 12984, "cannot drop partitioning column", "cannot drop partitioning column '%.*s'"); DEFINE_ERROR(OB_ERR_VIEW_SELECT_CONTAIN_INTO, -5503, ER_VIEW_SELECT_CLAUSE, "HY000", "View's SELECT contains a 'INTO' clause."); DEFINE_ORACLE_ERROR(OB_ERR_DEFAULT_NOT_ALLOWED, -5504, -1, "HY000", "Virtual column cannot have a default value", 54025, "Virtual column cannot have a default value"); DEFINE_ORACLE_ERROR(OB_ERR_MODIFY_REALCOL_TO_GENCOL, -5505, -1, "HY000", "Real column cannot have an expression", 54026, "Real column cannot have an expression"); diff --git a/src/share/ob_errno.h b/src/share/ob_errno.h index 5cfbf1bf1..f8da2cb0e 100755 --- a/src/share/ob_errno.h +++ b/src/share/ob_errno.h @@ -4958,7 +4958,7 @@ constexpr int OB_ERR_INVALID_DATE_MSG_FMT_V2 = -4219; #define OB_ERR_FUNCTIONAL_INDEX_ON_FIELD__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5499, Functional index on a column is not supported. Consider using a regular index instead." #define OB_ERR_GENCOL_LEGIT_CHECK_FAILED__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5500, Legitimacy check failed for generated columns." #define OB_ERR_GROUPING_FUNC_WITHOUT_GROUP_BY__ORA_USER_ERROR_MSG "ORA-30481: GROUPING function only supported with GROUP BY CUBE or ROLLUP" -#define OB_ERR_DEPENDENT_BY_PARTITION_FUNC__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5502, Column '%.*s' has a partitioning function dependency and cannot be dropped or renamed." +#define OB_ERR_DEPENDENT_BY_PARTITION_FUNC__ORA_USER_ERROR_MSG "ORA-12984: cannot drop partitioning column '%.*s'" #define OB_ERR_VIEW_SELECT_CONTAIN_INTO__ORA_USER_ERROR_MSG "ORA-00600: internal error code, arguments: -5503, View's SELECT contains a 'INTO' clause." #define OB_ERR_DEFAULT_NOT_ALLOWED__ORA_USER_ERROR_MSG "ORA-54025: Virtual column cannot have a default value" #define OB_ERR_MODIFY_REALCOL_TO_GENCOL__ORA_USER_ERROR_MSG "ORA-54026: Real column cannot have an expression" diff --git a/src/sql/resolver/ddl/ob_alter_table_resolver.cpp b/src/sql/resolver/ddl/ob_alter_table_resolver.cpp index 9dcc66dfd..8573c79b9 100644 --- a/src/sql/resolver/ddl/ob_alter_table_resolver.cpp +++ b/src/sql/resolver/ddl/ob_alter_table_resolver.cpp @@ -5638,6 +5638,9 @@ int ObAlterTableResolver::resolve_drop_column(const ParseNode &node, ObReducedVi alter_column_schema.get_origin_column_name(), alter_table_stmt))) { SQL_RESV_LOG(WARN, "failed to check column in foreign key for oracle mode", K(ret)); + } else if (OB_FAIL(check_drop_column_is_partition_key(*table_schema_, + alter_column_schema.get_origin_column_name()))) { + SQL_RESV_LOG(WARN, "failed to check column in parition key", K(ret)); } else if (OB_FAIL(check_column_in_check_constraint( *table_schema_, alter_column_schema.get_origin_column_name(), @@ -5969,5 +5972,31 @@ int ObAlterTableResolver::check_mysql_rename_column(const AlterColumnSchema &alt return ret; } +/* +* chech the droped column is partition key, +* if ture, forbid the action +*/ +int ObAlterTableResolver::check_drop_column_is_partition_key(const ObTableSchema &table_schema, const ObString &column_name) +{ + int ret=OB_SUCCESS; + if (!table_schema.is_valid()) { + ret = OB_INVALID_ARGUMENT; + SQL_RESV_LOG(WARN, "invalid arguemnt", K(ret), K(table_schema)); + } else { + const ObColumnSchemaV2 *origin_column = table_schema.get_column_schema(column_name); + if (OB_ISNULL(origin_column)) { + // do nothing + // 根据列名查不到列是因为表中不存在该列,后面会在 RS 端再检查一遍表中是否存在该列,并在 RS 端根据操作的不同报不同的错误 + } else if (origin_column->is_tbl_part_key_column()){ + ret = OB_ERR_DEPENDENT_BY_PARTITION_FUNC; + LOG_USER_ERROR(OB_ERR_DEPENDENT_BY_PARTITION_FUNC, + column_name.length(), + column_name.ptr()); + LOG_WARN("alter column has table part key deps", K(ret), K(origin_column)); + } + } + return ret; +} + } //namespace common } //namespace oceanbase diff --git a/src/sql/resolver/ddl/ob_alter_table_resolver.h b/src/sql/resolver/ddl/ob_alter_table_resolver.h index e2a4ada71..1d76da95b 100644 --- a/src/sql/resolver/ddl/ob_alter_table_resolver.h +++ b/src/sql/resolver/ddl/ob_alter_table_resolver.h @@ -88,6 +88,9 @@ private: share::schema::ObSchemaGetterGuard *schema_guard, const obrpc::ObCreateForeignKeyArg &foreign_key_arg); int resolve_alter_table_option_list(const ParseNode &node); + int check_drop_column_is_partition_key(const ObTableSchema &table_schema, + const ObString &column_name); + int set_column_collation(share::schema::AlterColumnSchema &alter_column_schema); int resolve_index_column_list(const ParseNode &node, obrpc::ObCreateIndexArg &index_arg,