[SCHEMA] Fix schema object overwrite problem

This commit is contained in:
tino247 2024-03-12 10:15:01 +00:00 committed by ob-robot
parent 8475beca3f
commit fefe6aec9a
16 changed files with 242 additions and 232 deletions

View File

@ -7762,8 +7762,8 @@ int ObDDLService::update_generated_column_schema(
ret = OB_ERR_UNEXPECTED;
LOG_WARN("*col_iter is NULL", K(ret));
} else if (column->has_cascaded_column_id(orig_column_schema.get_column_id())) {
ObColumnSchemaV2 new_generated_column_schema = *column;
if (OB_FAIL(new_generated_column_schema.get_err_ret())) {
ObColumnSchemaV2 new_generated_column_schema;
if (OB_FAIL(new_generated_column_schema.assign(*column))) {
LOG_WARN("failed to copy new gen column", K(ret));
} else if (need_update_session_var
&& OB_FAIL(modify_generated_column_local_vars(new_generated_column_schema,
@ -8741,21 +8741,23 @@ int ObDDLService::check_modify_column_when_upgrade(
if (obrpc::OB_UPGRADE_STAGE_DBUPGRADE != GCTX.get_upgrade_stage()) {
// do nothing
} else {
ObColumnSchemaV2 tmp_column = new_column;
tmp_column.set_schema_version(orig_column.get_schema_version());
tmp_column.set_data_length(orig_column.get_data_length());
tmp_column.set_data_precision(orig_column.get_data_precision());
tmp_column.set_data_scale(orig_column.get_data_scale());
if (OB_FAIL(tmp_column.get_assign_ret())) {
ObColumnSchemaV2 tmp_column;
if (OB_FAIL(tmp_column.assign(new_column))) {
LOG_WARN("assign failed", K(ret), K(new_column));
} else if (tmp_column != orig_column) {
ret = OB_OP_NOT_ALLOW;
LOG_WARN("can only modify column's length", K(ret), K(new_column), K(orig_column));
} else if (new_column.get_data_length() < orig_column.get_data_length()
|| new_column.get_data_precision() < orig_column.get_data_precision()
|| new_column.get_data_scale() < orig_column.get_data_scale()) {
ret = OB_OP_NOT_ALLOW;
LOG_WARN("can only increase column's length", K(ret), K(new_column), K(orig_column));
} else {
tmp_column.set_schema_version(orig_column.get_schema_version());
tmp_column.set_data_length(orig_column.get_data_length());
tmp_column.set_data_precision(orig_column.get_data_precision());
tmp_column.set_data_scale(orig_column.get_data_scale());
if (tmp_column != orig_column) {
ret = OB_OP_NOT_ALLOW;
LOG_WARN("can only modify column's length", K(ret), K(new_column), K(orig_column));
} else if (new_column.get_data_length() < orig_column.get_data_length()
|| new_column.get_data_precision() < orig_column.get_data_precision()
|| new_column.get_data_scale() < orig_column.get_data_scale()) {
ret = OB_OP_NOT_ALLOW;
LOG_WARN("can only increase column's length", K(ret), K(new_column), K(orig_column));
}
}
}
return ret;
@ -8841,17 +8843,20 @@ int ObDDLService::check_new_column_for_index(
"index_table", index_table_schema->get_table_name_str());
} else {
copy_index_column_schema.reset();
copy_index_column_schema = new_column_schema;
copy_index_column_schema.set_rowkey_position(origin_idx_column_schema->get_rowkey_position());
copy_index_column_schema.set_index_position(origin_idx_column_schema->get_index_position());
copy_index_column_schema.set_tbl_part_key_pos(origin_idx_column_schema->get_tbl_part_key_pos());
if (OB_FAIL(index_table_schema->alter_column(copy_index_column_schema,
ObTableSchema::CHECK_MODE_ONLINE,
for_view))) {
RS_LOG(WARN, "failed to alter index column schema", K(copy_index_column_schema), K(ret));
} else if (!index_table_schema->is_valid()) {
ret = OB_SCHEMA_ERROR;
RS_LOG(WARN, "idx table schema is invalid!", K(ret));
if (OB_FAIL(copy_index_column_schema.assign(new_column_schema))) {
LOG_WARN("fail to assign column schema", KR(ret), K(new_column_schema));
} else {
copy_index_column_schema.set_rowkey_position(origin_idx_column_schema->get_rowkey_position());
copy_index_column_schema.set_index_position(origin_idx_column_schema->get_index_position());
copy_index_column_schema.set_tbl_part_key_pos(origin_idx_column_schema->get_tbl_part_key_pos());
if (OB_FAIL(index_table_schema->alter_column(copy_index_column_schema,
ObTableSchema::CHECK_MODE_ONLINE,
for_view))) {
RS_LOG(WARN, "failed to alter index column schema", K(copy_index_column_schema), K(ret));
} else if (!index_table_schema->is_valid()) {
ret = OB_SCHEMA_ERROR;
RS_LOG(WARN, "idx table schema is invalid!", K(ret));
}
}
}
}
@ -8937,19 +8942,22 @@ int ObDDLService::alter_table_update_aux_column(
aux_table_schema->get_column_schema(new_column_schema.get_column_id());
if (NULL != origin_column_schema) {
// exist such column in aux schema
new_aux_column_schema = new_column_schema;
new_aux_column_schema.set_table_id(aux_table_schema->get_table_id());
new_aux_column_schema.set_autoincrement(false);
//save the rowkey postion and aux postion
if (is_index) {
new_aux_column_schema.set_rowkey_position(origin_column_schema->get_rowkey_position());
new_aux_column_schema.set_index_position(origin_column_schema->get_index_position());
new_aux_column_schema.set_tbl_part_key_pos(origin_column_schema->get_tbl_part_key_pos());
ObIndexBuilderUtil::del_column_flags_and_default_value(new_aux_column_schema);
}
if (!is_index) {
// VP column of primary table need not update.
new_aux_column_schema.set_column_flags(AUX_VP_COLUMN_FLAG);
if (OB_FAIL(new_aux_column_schema.assign(new_column_schema))) {
LOG_WARN("fail to assign column", KR(ret), K(new_column_schema));
} else {
new_aux_column_schema.set_table_id(aux_table_schema->get_table_id());
new_aux_column_schema.set_autoincrement(false);
//save the rowkey postion and aux postion
if (is_index) {
new_aux_column_schema.set_rowkey_position(origin_column_schema->get_rowkey_position());
new_aux_column_schema.set_index_position(origin_column_schema->get_index_position());
new_aux_column_schema.set_tbl_part_key_pos(origin_column_schema->get_tbl_part_key_pos());
ObIndexBuilderUtil::del_column_flags_and_default_value(new_aux_column_schema);
}
if (!is_index) {
// VP column of primary table need not update.
new_aux_column_schema.set_column_flags(AUX_VP_COLUMN_FLAG);
}
}
//will only update some attribute, not include rowkey postion or aux position
if (OB_FAIL(ret)) {
@ -26780,9 +26788,11 @@ int ObDDLService::modify_tenant_inner_phase(const ObModifyTenantArg &arg, const
ret = OB_ERR_UNEXPECTED;
LOG_WARN("sys variable schema is null", K(ret));
} else {
ObSysVariableSchema new_sys_variable = *orig_sys_variable;
new_sys_variable.reset_sysvars();
if (OB_FAIL(update_sys_variables(arg.sys_var_list_, *orig_sys_variable, new_sys_variable, value_changed))) {
ObSysVariableSchema new_sys_variable;
if (OB_FAIL(new_sys_variable.assign(*orig_sys_variable))) {
LOG_WARN("fail to assign sys variable schema", KR(ret), KPC(orig_sys_variable));
} else if (FALSE_IT(new_sys_variable.reset_sysvars())) {
} else if (OB_FAIL(update_sys_variables(arg.sys_var_list_, *orig_sys_variable, new_sys_variable, value_changed))) {
LOG_WARN("failed to update_sys_variables", K(ret));
} else if (value_changed == true) {
int64_t refreshed_schema_version = 0;
@ -27024,8 +27034,9 @@ int ObDDLService::update_sys_variables(const common::ObIArray<obrpc::ObSysVarIdV
LOG_WARN("sysvar is null", K(sysvar_value), K(ret));
} else {
ObSysVarSchema new_sysvar;
new_sysvar = *sysvar;
if (SYS_VAR_OB_COMPATIBILITY_MODE
if (OB_FAIL(new_sysvar.assign(*sysvar))) {
LOG_WARN("fail to assign sys var schema", KR(ret), KPC(sysvar));
} else if (SYS_VAR_OB_COMPATIBILITY_MODE
== ObSysVarFactory::find_sys_var_id_by_name(new_sysvar.get_name())) {
ret = OB_OP_NOT_ALLOW;
LOG_USER_ERROR(OB_OP_NOT_ALLOW, "change tenant compatibility mode");
@ -31789,7 +31800,9 @@ int ObDDLService::alter_outline_in_trans(const obrpc::ObAlterOutlineArg &arg)
//copy from the old outline info
new_outline_info = *orig_outline_info;
const ObString &outline_name = new_outline_info.get_name_str();
if (alter_outline_info.get_alter_option_bitset().has_member(
if (OB_FAIL(new_outline_info.get_err_ret())) {
LOG_WARN("copy assign failed", KR(ret), KPC(orig_outline_info));
} else if (alter_outline_info.get_alter_option_bitset().has_member(
obrpc::ObAlterOutlineArg::ADD_OUTLINE_CONTENT)) {
//add outline_content
const ObString &orig_outline_content = orig_outline_info->get_outline_content_str();
@ -37625,12 +37638,15 @@ int ObDDLService::check_new_columns_for_index(ObIArray<ObTableSchema> &idx_schem
LOG_WARN("push back element failed", K(ret));
} else {
ObColumnSchemaV2 copy_index_column_schema;
copy_index_column_schema = new_column_schemas.at(j);
copy_index_column_schema.set_rowkey_position(orig_idx_col_schema->get_rowkey_position());
copy_index_column_schema.set_index_position(orig_idx_col_schema->get_index_position());
copy_index_column_schema.set_tbl_part_key_pos(orig_idx_col_schema->get_tbl_part_key_pos());
if (OB_FAIL(copy_index_column_schemas.push_back(copy_index_column_schema))) {
LOG_WARN("push back element failed", K(ret));
if (OB_FAIL(copy_index_column_schema.assign(new_column_schemas.at(j)))) {
LOG_WARN("fail to assign column", KR(ret), K(new_column_schemas.at(j)));
} else {
copy_index_column_schema.set_rowkey_position(orig_idx_col_schema->get_rowkey_position());
copy_index_column_schema.set_index_position(orig_idx_col_schema->get_index_position());
copy_index_column_schema.set_tbl_part_key_pos(orig_idx_col_schema->get_tbl_part_key_pos());
if (OB_FAIL(copy_index_column_schemas.push_back(copy_index_column_schema))) {
LOG_WARN("push back element failed", K(ret));
}
}
}
} // end for

View File

@ -164,14 +164,18 @@ int ObVertialPartitionBuilder::set_aux_vp_table_columns(
ret = OB_ERR_BAD_FIELD_ERROR;
LOG_WARN("get_column_schema failed", K(column_id), K(ret));
} else {
ObColumnSchemaV2 column_schema = *data_column;
// 在处理主分区表时,将主表的垂直分区列原地标记为PRIMARY_VP_COLUMN_FLAG
// 将主表的rowkey copy进入副表时,应该将该标记清除
column_schema.del_column_flag(PRIMARY_VP_COLUMN_FLAG);
column_schema.set_is_hidden(true);
if (OB_FAIL(ObIndexBuilderUtil::add_column(&column_schema, false /*is_index_column*/, true /*is_rowkey*/,
data_column->get_order_in_rowkey(), row_desc, aux_vp_table_schema, false /* is_hidden */, false /* is_specified_storing_col */))) {
LOG_WARN("add column failed", K(column_schema), K(ret));
ObColumnSchemaV2 column_schema;
if (OB_FAIL(column_schema.assign(*data_column))) {
LOG_WARN("fail to assign column schema", KR(ret), KPC(data_column));
} else {
// 在处理主分区表时,将主表的垂直分区列原地标记为PRIMARY_VP_COLUMN_FLAG
// 将主表的rowkey copy进入副表时,应该将该标记清除
column_schema.del_column_flag(PRIMARY_VP_COLUMN_FLAG);
column_schema.set_is_hidden(true);
if (OB_FAIL(ObIndexBuilderUtil::add_column(&column_schema, false /*is_index_column*/, true /*is_rowkey*/,
data_column->get_order_in_rowkey(), row_desc, aux_vp_table_schema, false /* is_hidden */, false /* is_specified_storing_col */))) {
LOG_WARN("add column failed", K(column_schema), K(ret));
}
}
}
}
@ -182,8 +186,10 @@ int ObVertialPartitionBuilder::set_aux_vp_table_columns(
ret = OB_ERR_BAD_FIELD_ERROR;
LOG_WARN("get_column_schema failed", K(column_name), K(ret));
} else {
ObColumnSchemaV2 column_schema = *data_column;
if (column_schema.is_rowkey_column()) {
ObColumnSchemaV2 column_schema;
if (OB_FAIL(column_schema.assign(*data_column))) {
LOG_WARN("fail to assign column schema", KR(ret), KPC(data_column));
} else if (column_schema.is_rowkey_column()) {
// 无需添加该列,因为第一步已经添加该列,但仍需要给该列打标
ObColumnSchemaV2 *rowkey_column = NULL;
if (NULL == (rowkey_column = aux_vp_table_schema.get_column_schema(column_name))) {

View File

@ -90,50 +90,54 @@ int ObIndexBuilderUtil::add_column(
LOG_WARN("add_column_desc failed", "table_id", data_column->get_table_id(),
"column_id", data_column->get_column_id(), K(ret));
} else {
ObColumnSchemaV2 column = *data_column;
column.set_table_id(OB_INVALID_ID);
column.set_autoincrement(false);
column.set_tbl_part_key_pos(0);
column.set_prev_column_id(UINT64_MAX);
column.set_next_column_id(UINT64_MAX);
if (is_hidden) {
column.set_is_hidden(is_hidden);
}
// Generated column of index table's value is generated by data table. Default value
// (generated column expression) is not needed, and it introduce failure on global index
// partition location lookup (refer columns not exist in index table).
// Fulltext column's default value is needed, because we need to set GENERATED_CTXCAT_CASCADE_FLAG
// spatial column's default value is needed, because we need to set SPATIAL_INDEX_GENERATED_COLUMN_FLAG
// flag by parsing the default value.
del_column_flags_and_default_value(column);
if (is_rowkey) {
column.set_rowkey_position(row_desc.get_column_num());
column.set_order_in_rowkey(order_type);
ObColumnSchemaV2 column;
if (OB_FAIL(column.assign(*data_column))) {
LOG_WARN("fail to assign column", KR(ret), KPC(data_column));
} else {
column.set_rowkey_position(0);
}
column.set_table_id(OB_INVALID_ID);
column.set_autoincrement(false);
column.set_tbl_part_key_pos(0);
column.set_prev_column_id(UINT64_MAX);
column.set_next_column_id(UINT64_MAX);
if (is_hidden) {
column.set_is_hidden(is_hidden);
}
if (is_index) {
column.set_index_position(row_desc.get_column_num());
column.set_order_in_rowkey(order_type);
} else {
column.set_index_position(0);
}
// user specified storing column.
if (is_specified_storing_col) {
column.add_column_flag(USER_SPECIFIED_STORING_COLUMN_FLAG);
}
//index column are not auto increment
column.set_autoincrement(false);
// Generated column of index table's value is generated by data table. Default value
// (generated column expression) is not needed, and it introduce failure on global index
// partition location lookup (refer columns not exist in index table).
// Fulltext column's default value is needed, because we need to set GENERATED_CTXCAT_CASCADE_FLAG
// spatial column's default value is needed, because we need to set SPATIAL_INDEX_GENERATED_COLUMN_FLAG
// flag by parsing the default value.
del_column_flags_and_default_value(column);
if (is_rowkey) {
column.set_rowkey_position(row_desc.get_column_num());
column.set_order_in_rowkey(order_type);
} else {
column.set_rowkey_position(0);
}
if (column.is_spatial_generated_column()) {
column.set_geo_col_id(data_column->get_geo_col_id());
}
if (is_index) {
column.set_index_position(row_desc.get_column_num());
column.set_order_in_rowkey(order_type);
} else {
column.set_index_position(0);
}
// user specified storing column.
if (is_specified_storing_col) {
column.add_column_flag(USER_SPECIFIED_STORING_COLUMN_FLAG);
}
//index column are not auto increment
column.set_autoincrement(false);
if (OB_FAIL(ret)) {
} else if (OB_FAIL(table_schema.add_column(column))) {
LOG_WARN("add_column failed", K(column), K(ret));
if (column.is_spatial_generated_column()) {
column.set_geo_col_id(data_column->get_geo_col_id());
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(table_schema.add_column(column))) {
LOG_WARN("add_column failed", K(column), K(ret));
}
}
}
return ret;
@ -206,8 +210,9 @@ int ObIndexBuilderUtil::add_shadow_pks(
LOG_WARN("Unexpected lob column in shadow pk", "table_id", data_schema.get_table_id(),
K(column_id), K(ret));
} else {
data_column = *const_data_column;
if (OB_FAIL(set_shadow_column_info(shadow_pk_name, common::OB_MIN_SHADOW_COLUMN_ID + const_data_column->get_column_id(), data_column))) {
if (OB_FAIL(data_column.assign(*const_data_column))) {
LOG_WARN("fail to assign column", KR(ret), KPC(const_data_column));
} else if (OB_FAIL(set_shadow_column_info(shadow_pk_name, common::OB_MIN_SHADOW_COLUMN_ID + const_data_column->get_column_id(), data_column))) {
LOG_WARN("fail to set shadow_column_info", K(ret), K(data_column), K(shadow_pk_name));
} else {
// primary key(uk2, uk1)
@ -275,12 +280,13 @@ int ObIndexBuilderUtil::add_shadow_partition_keys(
LOG_WARN("Unexpected json column in shadow pk", "table_id", data_schema.get_table_id(),
K(column_id), K(ret));
} else {
data_column = *const_data_column;
if (data_column.get_column_id() > schema.get_max_used_column_id()) {
if (OB_FAIL(data_column.assign(*const_data_column))) {
LOG_WARN("fail to assign column", KR(ret), KPC(const_data_column));
} else if (data_column.get_column_id() > schema.get_max_used_column_id()) {
schema.set_max_used_column_id(data_column.get_column_id());
}
if (OB_FAIL(add_column(&data_column, is_index_column, is_rowkey,
if (FAILEDx(add_column(&data_column, is_index_column, is_rowkey,
data_column.get_order_in_rowkey(), row_desc, schema,
false /* is_hidden */, false /* is_specified_storing_col */))) {
LOG_WARN("add column failed", "data_column", data_column, K(is_index_column),
@ -1183,9 +1189,10 @@ int ObIndexBuilderUtil::generate_prefix_column(
} else {
ObObj default_value;
default_value.set_varchar(expr_def, static_cast<int32_t>(def_pos));
prefix_column = *old_column;
prefix_column.del_column_flag(HEAP_ALTER_ROWKEY_FLAG); // clear flag
if (!prefix_column.is_valid()) {
if (OB_FAIL(prefix_column.assign(*old_column))) {
LOG_WARN("fail to assign column", KR(ret), KPC(old_column));
} else if (FALSE_IT(prefix_column.del_column_flag(HEAP_ALTER_ROWKEY_FLAG))) { // clear flag
} else if (!prefix_column.is_valid()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("prefix column is invalid", K(ret));
} else if (OB_FAIL(prefix_column.set_column_name(col_name_buf))) {

View File

@ -105,23 +105,15 @@ ObColumnSchemaV2::ObColumnSchemaV2(ObIAllocator *allocator)
reset();
}
ObColumnSchemaV2::ObColumnSchemaV2(const ObColumnSchemaV2 &src_schema)
: ObSchema(),
local_session_vars_(get_allocator())
{
reset();
*this = src_schema;
}
ObColumnSchemaV2::~ObColumnSchemaV2()
{
}
ObColumnSchemaV2 &ObColumnSchemaV2::operator =(const ObColumnSchemaV2 &src_schema)
int ObColumnSchemaV2::assign(const ObColumnSchemaV2 &src_schema)
{
int ret = OB_SUCCESS;
if (this != &src_schema) {
reset();
ObColumnSchemaV2::reset();
error_ret_ = src_schema.error_ret_;
tenant_id_ = src_schema.tenant_id_;
table_id_ = src_schema.table_id_;
@ -151,7 +143,6 @@ ObColumnSchemaV2 &ObColumnSchemaV2::operator =(const ObColumnSchemaV2 &src_schem
skip_index_attr_ = src_schema.skip_index_attr_;
lob_chunk_size_ = src_schema.lob_chunk_size_;
int ret = OB_SUCCESS;
if (OB_FAIL(deep_copy_obj(src_schema.orig_default_value_, orig_default_value_))) {
LOG_WARN("Fail to deepy copy orig_default_value, ", K(ret));
} else if (OB_FAIL(deep_copy_obj(src_schema.cur_default_value_, cur_default_value_))) {
@ -181,13 +172,7 @@ ObColumnSchemaV2 &ObColumnSchemaV2::operator =(const ObColumnSchemaV2 &src_schem
}
LOG_DEBUG("operator =", K(src_schema), K(*this));
}
return *this;
}
int ObColumnSchemaV2::assign(const ObColumnSchemaV2 &other)
{
*this = other;
return error_ret_;
return ret;
}
bool ObColumnSchemaV2::operator==(const ObColumnSchemaV2 &r) const

View File

@ -54,15 +54,14 @@ static common::ColumnType convert_str_to_column_type(const char *str);
//constructor and destructor
ObColumnSchemaV2();
explicit ObColumnSchemaV2(common::ObIAllocator *allocator);
ObColumnSchemaV2(const ObColumnSchemaV2 &src_schema);
DISABLE_COPY_ASSIGN(ObColumnSchemaV2);
virtual ~ObColumnSchemaV2();
//operators
ObColumnSchemaV2 &operator=(const ObColumnSchemaV2 &src_schema);
bool operator==(const ObColumnSchemaV2 &r) const;
bool operator!=(const ObColumnSchemaV2 &r) const;
int assign(const ObColumnSchemaV2 &other);
int assign(const ObColumnSchemaV2 &src_schema);
//set methods
inline void set_tenant_id(const uint64_t id) { tenant_id_ = id; }

View File

@ -670,8 +670,9 @@ int ObSchemaPrinter::print_single_index_definition(const ObTableSchema *index_sc
} else if (NULL == table_schema.get_column_schema(col->get_column_id())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("get column schema from data table failed", K(ret));
} else if (OB_FAIL(last_col.assign(*table_schema.get_column_schema(col->get_column_id())))) {
LOG_WARN("fail to assign column", KR(ret));
} else {
last_col = *table_schema.get_column_schema(col->get_column_id());
is_valid_col = true;
}
} else {

View File

@ -327,7 +327,9 @@ int64_t AlterColumnSchema::to_string(char* buf, const int64_t buf_len) const
int AlterColumnSchema::assign(const ObColumnSchemaV2 &other)
{
int ret = OB_SUCCESS;
ObColumnSchemaV2::operator = (other);
if (OB_FAIL(ObColumnSchemaV2::assign(other))) {
LOG_WARN("fail to assign column", KR(ret), K(other));
}
return ret;
}
@ -336,7 +338,6 @@ AlterColumnSchema &AlterColumnSchema::operator=(const AlterColumnSchema &src_sch
int ret = OB_SUCCESS;
if (this != &src_schema) {
reset();
ObColumnSchemaV2::operator = (src_schema);
alter_type_ = src_schema.alter_type_;
is_primary_key_ = src_schema.is_primary_key_;
is_autoincrement_ = src_schema.is_autoincrement_;
@ -346,7 +347,9 @@ AlterColumnSchema &AlterColumnSchema::operator=(const AlterColumnSchema &src_sch
is_set_default_ = src_schema.is_set_default_;
check_timestamp_column_order_ = src_schema.check_timestamp_column_order_;
is_no_zero_date_ = src_schema.is_no_zero_date_;
if (OB_FAIL(deep_copy_str(src_schema.get_origin_column_name(), origin_column_name_))) {
if (OB_FAIL(ObColumnSchemaV2::assign(src_schema))) {
LOG_WARN("fail to assign column", KR(ret), K(src_schema));
} else if (OB_FAIL(deep_copy_str(src_schema.get_origin_column_name(), origin_column_name_))) {
SHARE_LOG(WARN, "failed to deep copy origin_column_name", K(ret));
} else if (OB_FAIL(deep_copy_str(src_schema.get_next_column_name(), next_column_name_))) {
SHARE_LOG(WARN, "failed to deep copy next_column_name", K(ret));

View File

@ -582,6 +582,7 @@ public:
new_part_name_()
{
}
DISABLE_COPY_ASSIGN(AlterTableSchema);
inline const common::ObString &get_origin_table_name() const { return origin_table_name_; }
inline int set_origin_table_name(const common::ObString &origin_table_name);
inline const common::ObString &get_database_name() const { return new_database_name_; }

View File

@ -814,22 +814,15 @@ ObSysVariableSchema::ObSysVariableSchema(ObIAllocator *allocator)
reset();
}
ObSysVariableSchema::ObSysVariableSchema(const ObSysVariableSchema &src_schema)
: ObSchema()
{
reset();
*this = src_schema;
}
ObSysVariableSchema::~ObSysVariableSchema()
{
}
ObSysVariableSchema& ObSysVariableSchema::operator =(const ObSysVariableSchema &src_schema)
int ObSysVariableSchema::assign(const ObSysVariableSchema &src_schema)
{
int ret = OB_SUCCESS;
if (this != &src_schema) {
reset();
int ret = OB_SUCCESS;
error_ret_ = src_schema.error_ret_;
tenant_id_ = src_schema.tenant_id_;
schema_version_ = src_schema.schema_version_;
@ -848,14 +841,6 @@ ObSysVariableSchema& ObSysVariableSchema::operator =(const ObSysVariableSchema &
error_ret_ = ret;
}
}
return *this;
}
int ObSysVariableSchema::assign(const ObSysVariableSchema &other)
{
int ret = OB_SUCCESS;
*this = other;
ret = get_err_ret();
return ret;
}
@ -984,7 +969,9 @@ int ObSysVariableSchema::add_sysvar_schema(const ObSysVarSchema &sysvar_schema)
LOG_WARN("alloc sysvar schema failed", K(sizeof(ObSysVarSchema)));
} else {
tmp_sysvar_schema = new(ptr) ObSysVarSchema(allocator_);
*tmp_sysvar_schema = sysvar_schema;
if (OB_FAIL(tmp_sysvar_schema->assign(sysvar_schema))) {
LOG_WARN("fail to assign sysvar", KR(ret), K(sysvar_schema));
}
}
if (OB_SUCC(ret)) {
if (OB_UNLIKELY(!tmp_sysvar_schema->is_valid())) {
@ -2290,25 +2277,19 @@ int64_t ObSysVarSchema::get_convert_size() const
return convert_size;
}
ObSysVarSchema::ObSysVarSchema(const ObSysVarSchema &src_schema)
: ObSchema()
{
*this = src_schema;
}
ObSysVarSchema::ObSysVarSchema(ObIAllocator *allocator)
: ObSchema(allocator)
{
reset();
}
ObSysVarSchema &ObSysVarSchema::operator=(const ObSysVarSchema &src_schema)
int ObSysVarSchema::assign(const ObSysVarSchema &src_schema)
{
int ret = OB_SUCCESS;
if (this != &src_schema) {
reset();
if (!src_schema.is_valid()) {
ret = src_schema.get_err_ret();
ret = OB_INVALID_ARGUMENT;
LOG_WARN("src schema is invalid", K(ret));
} else if (OB_FAIL(set_name(src_schema.get_name()))) {
LOG_WARN("set sysvar name failed", K(ret));
@ -2328,16 +2309,8 @@ ObSysVarSchema &ObSysVarSchema::operator=(const ObSysVarSchema &src_schema)
set_flags(src_schema.get_flags());
set_tenant_id(src_schema.get_tenant_id());
}
error_ret_ = ret;
}
error_ret_ = ret;
return *this;
}
int ObSysVarSchema::assign(const ObSysVarSchema &other)
{
int ret = OB_SUCCESS;
*this = other;
ret = get_err_ret();
return ret;
}

View File

@ -1422,9 +1422,8 @@ public:
ObSysVarSchema() : ObSchema() { reset(); }
~ObSysVarSchema() {}
explicit ObSysVarSchema(common::ObIAllocator *allocator);
explicit ObSysVarSchema(const ObSysVarSchema &src_schema);
ObSysVarSchema &operator=(const ObSysVarSchema &src_schema);
int assign(const ObSysVarSchema &other);
DISABLE_COPY_ASSIGN(ObSysVarSchema);
int assign(const ObSysVarSchema &src_schema);
virtual bool is_valid() const { return ObSchema::is_valid() && tenant_id_ != common::OB_INVALID_ID && !name_.empty(); }
void reset();
int64_t get_convert_size() const;
@ -1494,9 +1493,8 @@ public:
ObSysVariableSchema();
explicit ObSysVariableSchema(common::ObIAllocator *allocator);
virtual ~ObSysVariableSchema();
ObSysVariableSchema(const ObSysVariableSchema &src_schema);
ObSysVariableSchema &operator=(const ObSysVariableSchema &src_schema);
int assign(const ObSysVariableSchema &other);
DISABLE_COPY_ASSIGN(ObSysVariableSchema);
int assign(const ObSysVariableSchema &src_schema);
//set methods
inline void set_tenant_id(const uint64_t tenant_id) { tenant_id_ = tenant_id; }
inline void set_schema_version(const int64_t schema_version) { schema_version_ = schema_version; }

View File

@ -6169,8 +6169,8 @@ int ObSimpleTableSchemaV2::get_index_name(const ObString &table_name, ObString &
pos = strlen(OB_INDEX_PREFIX);
while (NULL != table_name.ptr() &&
isdigit(*(table_name.ptr() + pos)) &&
pos < table_name.length()) {
pos < table_name.length() &&
isdigit(*(table_name.ptr() + pos))) {
++pos;
}
if (pos == table_name.length()) {

View File

@ -2145,11 +2145,9 @@ int ObTableSchema::add_column(const ColumnType &column)
ret = common::OB_ERR_UNEXPECTED;
SHARE_SCHEMA_LOG(WARN, "Fail to new local_column", KR(ret));
} else {
*local_column = column;
ret = local_column->get_err_ret();
local_column->set_table_id(table_id_);
if (OB_FAIL(ret)) {
if (OB_FAIL(local_column->assign(column))) {
SHARE_SCHEMA_LOG(WARN, "failed copy assign column", KR(ret), K(column));
} else if (FALSE_IT(local_column->set_table_id(table_id_))) {
} else if (!local_column->is_valid()) {
ret = common::OB_ERR_UNEXPECTED;
SHARE_SCHEMA_LOG(WARN, "The local column is not valid", KR(ret));

View File

@ -1125,14 +1125,18 @@ int ObTableSqlService::add_columns_for_core(ObISQLClient &sql_client, const ObTa
}
for (ObTableSchema::const_column_iterator iter = table.column_begin();
OB_SUCC(ret) && iter != table.column_end(); ++iter) {
ObColumnSchemaV2 column = (**iter);
column.set_schema_version(table.get_schema_version());
column.set_tenant_id(table.get_tenant_id());
column.set_table_id(table.get_table_id());
dml.reset();
cells.reuse();
int64_t affected_rows = 0;
if (OB_FAIL(gen_column_dml(tenant_id, column, dml))) {
ObColumnSchemaV2 column;
if (OB_FAIL(column.assign(**iter))) {
LOG_WARN("fail to assign column", KR(ret), KPC(*iter));
} else {
column.set_schema_version(table.get_schema_version());
column.set_tenant_id(table.get_tenant_id());
column.set_table_id(table.get_table_id());
}
if (FAILEDx(gen_column_dml(tenant_id, column, dml))) {
LOG_WARN("gen column dml failed", K(ret));
} else if (OB_FAIL(dml.splice_core_cells(kv, cells))) {
LOG_WARN("splice core cells failed", K(ret));
@ -1233,12 +1237,16 @@ int ObTableSqlService::add_columns_for_not_core(ObISQLClient &sql_client,
ret = OB_ERR_UNEXPECTED;
LOG_WARN("iter is NULL", K(ret));
} else {
ObColumnSchemaV2 column = (**iter);
column.set_schema_version(new_schema_version);
column.set_tenant_id(table.get_tenant_id());
column.set_table_id(table.get_table_id());
ObColumnSchemaV2 column;
if (OB_FAIL(column.assign(**iter))) {
LOG_WARN("fail to assign column", KR(ret), KPC(*iter));
} else {
column.set_schema_version(new_schema_version);
column.set_tenant_id(table.get_tenant_id());
column.set_table_id(table.get_table_id());
}
ObDMLSqlSplicer dml;
if (OB_FAIL(gen_column_dml(exec_tenant_id, column, dml))) {
if (FAILEDx(gen_column_dml(exec_tenant_id, column, dml))) {
LOG_WARN("gen_column_dml failed", K(column), K(ret));
} else if (column_sql.empty()) {
if (OB_FAIL(dml.splice_insert_sql_without_plancache(OB_ALL_COLUMN_TNAME, column_sql))) {
@ -6249,12 +6257,16 @@ int ObTableSqlService::update_view_columns(ObISQLClient &sql_client,
ret = OB_ERR_UNEXPECTED;
LOG_WARN("iter is NULL", K(ret));
} else {
ObColumnSchemaV2 column = (**iter);
column.set_schema_version(new_schema_version);
column.set_tenant_id(table.get_tenant_id());
column.set_table_id(table.get_table_id());
ObColumnSchemaV2 column;
if (OB_FAIL(column.assign(**iter))) {
LOG_WARN("fail to assign column", KR(ret), KPC(*iter));
} else {
column.set_schema_version(new_schema_version);
column.set_tenant_id(table.get_tenant_id());
column.set_table_id(table.get_table_id());
}
ObDMLSqlSplicer dml;
if (OB_FAIL(gen_column_dml(exec_tenant_id, column, dml))) {
if (FAILEDx(gen_column_dml(exec_tenant_id, column, dml))) {
LOG_WARN("gen_column_dml failed", K(column), K(ret));
} else if (OB_FAIL(dml.splice_insert_update_sql(OB_ALL_COLUMN_TNAME, column_sql))) {
LOG_WARN("splice_insert_sql failed", "table_name", OB_ALL_COLUMN_TNAME, K(ret));

View File

@ -1939,11 +1939,16 @@ int ObCreateTableResolver::resolve_table_elements_from_select(const ParseNode &p
ObColumnSchemaV2 *org_column = table_schema.get_column_schema(column.get_column_name());
if (OB_NOT_NULL(org_column)) {
//同名列存在, 为了和mysql保持一致, 需要调整原列的顺序
ObColumnSchemaV2 new_column(*org_column);
new_column.set_column_id(gen_column_id());
new_column.set_prev_column_id(UINT64_MAX);
new_column.set_next_column_id(UINT64_MAX);
if (1 == table_schema.get_column_count()) {
ObColumnSchemaV2 new_column;
if (OB_FAIL(new_column.assign(*org_column))) {
LOG_WARN("fail to assign column", KR(ret), KPC(org_column));
} else {
new_column.set_column_id(gen_column_id());
new_column.set_prev_column_id(UINT64_MAX);
new_column.set_next_column_id(UINT64_MAX);
}
if (OB_FAIL(ret)) {
} else if (1 == table_schema.get_column_count()) {
//do nothing, 只有一列就不用调整了
if (OB_FAIL(set_nullable_for_cta_column(select_stmt, *org_column, expr, table_name_, *allocator_, stmt_))) {
LOG_WARN("failed to check and set nullable for cta.", K(ret));

View File

@ -818,7 +818,7 @@ void TestSqlUtils::generate_index_column_schema(ObCreateIndexStmt &stmt,
ObColumnSchemaV2 index_column;
const ObColumnSchemaV2 *col = table_schema->get_column_schema(index_arg.index_columns_[i].column_name_);
ASSERT_FALSE(NULL == col);
index_column = *col;
ASSERT_TRUE(OB_SUCCESS == index_column.assign(*col));
++index_rowkey_num;
index_column.set_rowkey_position(index_rowkey_num);
index_column.set_index_position(index_rowkey_num);
@ -838,7 +838,7 @@ void TestSqlUtils::generate_index_column_schema(ObCreateIndexStmt &stmt,
const ObColumnSchemaV2 *col = table_schema->get_column_schema(column_id);
ASSERT_FALSE(NULL == col);
ObColumnSchemaV2 index_column;
index_column = *col;
ASSERT_TRUE(OB_SUCCESS == index_column.assign(*col));
index_column.set_rowkey_position(index_rowkey_num);
if (col->get_column_id() > max_column_id) {
max_column_id = col->get_column_id();

View File

@ -67,16 +67,16 @@ int ObRestoreSchema::init()
STORAGE_LOG(WARN, "fail add database schema", K(ret));
}
//ObArray<ObDatabaseSchema> db_array;
//if (OB_SUCCESS != (ret = schema_manager_.init())) {
//if (OB_FAIL(schema_manager_.init())) {
// STORAGE_LOG(WARN, "fail to initialize schema manager", K(ret));
//} else if (OB_SUCCESS != (ret = db_array.push_back(db_schema))) {
//} else if (OB_FAIL(db_array.push_back(db_schema))) {
// STORAGE_LOG(WARN, "fail to add database", K(ret));
//} else if (OB_SUCCESS != (ret = schema_manager_.add_new_database_schema_array(db_array))) {
//} else if (OB_FAIL(schema_manager_.add_new_database_schema_array(db_array))) {
// STORAGE_LOG(WARN, "fail to add default database", K(ret));
//}
}
if (OB_SUCC(ret)) {
if (OB_SUCCESS != (ret = ObPreProcessSysVars::init_sys_var())) {
if (OB_FAIL(ObPreProcessSysVars::init_sys_var())) {
STORAGE_LOG(ERROR, "fail to init sys variables", K(ret));
}
}
@ -212,13 +212,14 @@ int ObRestoreSchema::gen_columns(ObCreateIndexStmt &stmt,
ret = OB_ERR_ILLEGAL_NAME;
STORAGE_LOG(WARN, "invalid column name",
K_(index_arg.index_columns_[i].column_name));
} else if (OB_FAIL(index_column.assign(*col))) {
STORAGE_LOG(WARN, "fail to assign col", KR(ret), KPC(col));
} else {
index_column = *col;
index_column.set_rowkey_position(++index_rowkey_num);
if (col->get_column_id() > max_column_id) {
max_column_id = col->get_column_id();
}
if (OB_SUCCESS != (ret = index_schema.add_column(index_column))) {
if (OB_FAIL(index_schema.add_column(index_column))) {
STORAGE_LOG(WARN, "add column schema error", K(ret));
}
}
@ -229,14 +230,15 @@ int ObRestoreSchema::gen_columns(ObCreateIndexStmt &stmt,
for (int64_t i = 0; OB_SUCC(ret) && i < rowkey_info.get_size(); ++i) {
uint64_t column_id = OB_INVALID_ID;
ObColumnSchemaV2 index_column;
if (OB_SUCCESS != (ret = rowkey_info.get_column_id(i, column_id))) {
if (OB_FAIL(rowkey_info.get_column_id(i, column_id))) {
STORAGE_LOG(WARN, "get column id error", K(i), K(ret));
} else if (NULL == index_schema.get_column_schema(column_id)) {
if (NULL == (col = table_schema->get_column_schema(column_id))) {
ret = OB_ERR_ILLEGAL_ID;
STORAGE_LOG(WARN, "invalid column id", K(column_id));
} else if (OB_FAIL(index_column.assign(*col))) {
STORAGE_LOG(WARN, "fail to assign col", KR(ret), KPC(col));
} else {
index_column = *col;
index_column.set_rowkey_position(++index_rowkey_num);
// we do not have index of other type now
OB_ASSERT(INDEX_TYPE_UNIQUE_LOCAL == index_arg.index_type_
@ -258,9 +260,9 @@ int ObRestoreSchema::gen_columns(ObCreateIndexStmt &stmt,
K(col->get_column_name_str()));
} else {
shadow_name[shadow_name_len - 1] = '\0';
if (OB_SUCCESS != (ret = index_column.set_column_name(shadow_name))) {
if (OB_FAIL(index_column.set_column_name(shadow_name))) {
STORAGE_LOG(WARN, "failed to set shadow name", K(*shadow_name));
} else if (OB_SUCCESS != (ret = rk_cols.push_back(col))) {
} else if (OB_FAIL(rk_cols.push_back(col))) {
STORAGE_LOG(WARN, "failed to remember rowkey column", K(ret));
}
}
@ -269,7 +271,7 @@ int ObRestoreSchema::gen_columns(ObCreateIndexStmt &stmt,
if (index_column.get_column_id() > max_column_id) {
max_column_id = index_column.get_column_id();
}
if (OB_SUCCESS != (ret = index_schema.add_column(index_column))) {
if (OB_FAIL(index_schema.add_column(index_column))) {
STORAGE_LOG(WARN, "add column schema error", K(ret));
}
}
@ -279,10 +281,14 @@ int ObRestoreSchema::gen_columns(ObCreateIndexStmt &stmt,
//add primary key of unique index
if (OB_SUCC(ret)) {
for (int64_t i = 0; OB_SUCC(ret) && i < rk_cols.count(); ++i) {
ObColumnSchemaV2 index_column = *rk_cols.at(i);
index_column.set_rowkey_position(0);
if (OB_SUCCESS != (ret = index_schema.add_column(index_column))) {
STORAGE_LOG(WARN, "add column schema error", K(ret));
ObColumnSchemaV2 index_column;
if (OB_FAIL(index_column.assign(*rk_cols.at(i)))) {
STORAGE_LOG(WARN, "fail to assign col", KR(ret), KPC(rk_cols.at(i)));
} else {
index_column.set_rowkey_position(0);
if (OB_FAIL(index_schema.add_column(index_column))) {
STORAGE_LOG(WARN, "add column schema error", K(ret));
}
}
}
}
@ -291,7 +297,7 @@ int ObRestoreSchema::gen_columns(ObCreateIndexStmt &stmt,
if (NULL == (col = table_schema->get_column_schema(index_arg.store_columns_[i]))) {
ret = OB_ERR_ILLEGAL_NAME;
STORAGE_LOG(WARN, "invalid column name", K(index_arg.store_columns_[i]));
} else if (OB_SUCCESS != (ret = index_schema.add_column(*col))) {
} else if (OB_FAIL(index_schema.add_column(*col))) {
STORAGE_LOG(WARN, "add column schema error", K(ret));
} else {
if (col->get_column_id() > max_column_id) {
@ -333,12 +339,12 @@ int ObRestoreSchema::do_create_index(ObStmt *stmt)
STORAGE_LOG(WARN, "table schema should not be null!", K(index_arg), K(ret));
} else {
ObTableSchema index_schema;
if (OB_SUCCESS != (ret = gen_columns(*crt_idx_stmt, index_schema))) {
if (OB_FAIL(gen_columns(*crt_idx_stmt, index_schema))) {
STORAGE_LOG(WARN, "get index column(s) error", K(ret));
} else if (OB_SUCCESS != (ret = index_schema.set_compress_func_name(
} else if (OB_FAIL(index_schema.set_compress_func_name(
index_arg.index_option_.compress_method_))) {
STORAGE_LOG(WARN, "set compress func error", K(ret));
} else if (OB_SUCCESS != (ret = index_schema.set_comment(
} else if (OB_FAIL(index_schema.set_comment(
index_arg.index_option_.comment_))) {
STORAGE_LOG(WARN, "set comment error", K(ret));
} else {
@ -385,7 +391,7 @@ int ObRestoreSchema::do_resolve_single_stmt(ParseNode *node,
} else {
ObResolver resolver(ctx);
ObStmt *stmt = NULL;
if (OB_SUCCESS != (ret = resolver.resolve(
if (OB_FAIL(resolver.resolve(
ObResolver::IS_NOT_PREPARED_STMT,
*node, stmt))) {
STORAGE_LOG(WARN, "resolver.resolve() failed", K(ret));
@ -413,7 +419,7 @@ int ObRestoreSchema::do_parse_line(ObArenaAllocator &allocator, const char *quer
ObParser parser(allocator, mode);
ObString query = ObString::make_string(query_str);
ParseResult parse_result;
if (OB_SUCCESS != (ret = parser.parse(query, parse_result))) {
if (OB_FAIL(parser.parse(query, parse_result))) {
STORAGE_LOG(WARN, "parser.parse() failed", K(ret));
}
if (OB_SUCC(ret)) {
@ -434,23 +440,23 @@ int ObRestoreSchema::do_parse_line(ObArenaAllocator &allocator, const char *quer
resolver_ctx.expr_factory_ = &expr_factory;
resolver_ctx.stmt_factory_ = &stmt_factory;
resolver_ctx.query_ctx_ = stmt_factory.get_query_ctx();
if (OB_SUCCESS != (ret = session_info.init_tenant(tenant, tenant_id_))) {
if (OB_FAIL(session_info.init_tenant(tenant, tenant_id_))) {
STORAGE_LOG(WARN, "fail to init sql session info", K(ret), K(tenant_id_));
} else if (OB_SUCCESS != (ret = session_info.set_default_database(db_name))) {
} else if (OB_FAIL(session_info.set_default_database(db_name))) {
STORAGE_LOG(WARN, "fail to set default database", K(ret));
} else if (OB_SUCCESS != (ret = session_info.test_init(version, 0, 0, &allocator))) {
} else if (OB_FAIL(session_info.test_init(version, 0, 0, &allocator))) {
STORAGE_LOG(WARN, "fail to init session info", K(ret));
} else if (OB_SUCCESS != (ret= session_info.load_default_sys_variable(false, true))) {
STORAGE_LOG(WARN, "fail to load default sys variable");
} else if (T_STMT_LIST == parse_result.result_tree_->type_) {
for (int64_t i = 0; OB_SUCC(ret) && i < parse_result.result_tree_->num_child_; ++i) {
if (OB_SUCCESS != (ret = do_resolve_single_stmt(parse_result.result_tree_->children_[i],
if (OB_FAIL(do_resolve_single_stmt(parse_result.result_tree_->children_[i],
resolver_ctx))) {
STORAGE_LOG(WARN, "resolve single stmt failed", K(ret));
}
}
} else {
if (OB_SUCCESS != (ret = do_resolve_single_stmt(parse_result.result_tree_,
if (OB_FAIL(do_resolve_single_stmt(parse_result.result_tree_,
resolver_ctx))) {
STORAGE_LOG(WARN, "resolve single stmt failed", K(ret));
}
@ -473,7 +479,7 @@ int ObRestoreSchema::parse_from_file(const char *filename,
}
schema_guard = &schema_guard_;
// if (OB_SUCC(ret)) {
// if (OB_SUCCESS != (ret = schema_manager_.cons_table_to_index_relation())) {
// if (OB_FAIL(schema_manager_.cons_table_to_index_relation())) {
// STORAGE_LOG(WARN, "construct table to index relation error", K(ret));
// } else {
// schema_manager = &schema_manager_;