From a623e539b07dda6de13f38fcc343dbf1ab709585 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 14 Nov 2024 12:14:46 +0000 Subject: [PATCH] fix oracle modify null failed after drop pk. --- src/sql/resolver/ddl/ob_ddl_resolver.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/sql/resolver/ddl/ob_ddl_resolver.cpp b/src/sql/resolver/ddl/ob_ddl_resolver.cpp index 13ea978c6..19e72db16 100644 --- a/src/sql/resolver/ddl/ob_ddl_resolver.cpp +++ b/src/sql/resolver/ddl/ob_ddl_resolver.cpp @@ -4028,13 +4028,29 @@ int ObDDLResolver::resolve_normal_column_attribute_constr_null(ObColumnSchemaV2 LOG_WARN("duplicate NULL specifications", K(ret)); } else if (stmt::T_ALTER_TABLE == stmt_->get_stmt_type() && OB_DDL_ADD_COLUMN != (static_cast(column)).alter_type_) { - if (!column.has_not_null_constraint()) { - ret = OB_COLUMN_CANT_CHANGE_TO_NULLALE; - LOG_WARN("column to be modified to NULL cannot be modified to NULL", K(ret)); - } else if (stmt::T_ALTER_TABLE == stmt_->get_stmt_type() + // To modify column to nullable. + // 1. Primary key column can not insert NULL due to is_nullable_ = true, keep the attribute after the drop pk op. + // And modify column null should set is_nullable_ = true after drop pk op. (Modify null successfully is not compatible with the Oracle) + // 2. With not null constraint. + if (!column.has_not_null_constraint()) { // without not null cst. + if (stmt::T_ALTER_TABLE != stmt_->get_stmt_type() + || column.is_nullable() + || column.is_rowkey_column()) { + ret = OB_COLUMN_CANT_CHANGE_TO_NULLALE; + LOG_WARN("column to be modified to NULL cannot be modified to NULL", K(ret), + "stmt_type", stmt_->get_stmt_type(), "is_null", column.is_nullable(), "is_rowkey", column.is_rowkey_column(), + K(column)); + } else { + column.set_nullable(true); + } + } else if (stmt::T_ALTER_TABLE == stmt_->get_stmt_type() // with not null cst. && OB_FAIL(drop_not_null_constraint(column))) { LOG_WARN("drop not null constraint failed", K(ret)); } else { + if (!column.is_rowkey_column()) { + // After drop pk op, the column should set null by setting nullable and dropping not null flag. + column.set_nullable(true); + } column.drop_not_null_cst(); } }