[CP] Optimize slow performance when adding not null columns to empty table in oracle mode

Co-authored-by: Someti1mes <chenguo.chen@qq.com>
This commit is contained in:
obdev
2024-06-20 14:08:23 +00:00
committed by ob-robot
parent 92546c111b
commit 2383698d81
8 changed files with 495 additions and 62 deletions

View File

@ -1257,36 +1257,7 @@ int ObAlterTableExecutor::need_check_constraint_validity(obrpc::ObAlterTableArg
} else if (CONSTRAINT_TYPE_NOT_NULL == (*iter)->get_constraint_type()) {
if (1 != (*iter)->get_column_cnt()) {
ret = OB_ERR_UNEXPECTED;
} else if (OB_INVALID_ID == *(*iter)->cst_col_begin()) {
// alter table add column not null.
ObTableSchema::const_column_iterator target_col_iter = NULL;
ObTableSchema::const_column_iterator cst_col_iter =
alter_table_arg.alter_table_schema_.column_begin();
ObString cst_col_name;
if (OB_FAIL((*iter)->get_not_null_column_name(cst_col_name))) {
LOG_WARN("get not null column name failed", K(ret));
} else {
for(; NULL == target_col_iter
&& cst_col_iter != alter_table_arg.alter_table_schema_.column_end();
cst_col_iter++) {
if ((*cst_col_iter)->get_column_name_str().length() == cst_col_name.length()
&& 0 == (*cst_col_iter)->get_column_name_str().compare(cst_col_name)) {
target_col_iter = cst_col_iter;
}
}
if (OB_ISNULL(target_col_iter)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("column schema not found", K(ret),K(alter_table_arg.alter_table_schema_),
K(cst_col_name));
} else {
const ObObj &cur_default_value = (*target_col_iter)->get_cur_default_value();
need_check = cur_default_value.is_null() ||
(cur_default_value.is_string_type()
&& (0 == cur_default_value.get_string().case_compare(N_NULL)
|| 0 == cur_default_value.get_string().case_compare("''")));
}
}
} else {
} else if (OB_INVALID_ID != *(*iter)->cst_col_begin()) {
// alter table modify column not null.
need_check = (*iter)->is_validated();
}