[FEAT MERGE] column store ddl
Co-authored-by: AnimationFan <30674773338@qq.com> Co-authored-by: simonjoylet <simonjoylet@gmail.com> Co-authored-by: Monk-Liu <1152761042@qq.com>
This commit is contained in:
@ -698,6 +698,12 @@ int ObAlterTableResolver::resolve_action_list(const ParseNode &node)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_ALTER_COLUMN_GROUP_OPTION: {
|
||||
if (OB_FAIL(resolve_alter_column_groups(*action_node))) {
|
||||
SQL_RESV_LOG(WARN, "Resolve column group option failed!", K(ret));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case T_ALTER_INDEX_OPTION_ORACLE: {
|
||||
alter_table_stmt->set_alter_table_index();
|
||||
if (OB_FAIL(resolve_index_options_oracle(*action_node))) {
|
||||
@ -926,7 +932,7 @@ int ObAlterTableResolver::resolve_action_list(const ParseNode &node)
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (OB_FAIL(resolve_column_group())) {
|
||||
} else if (OB_FAIL(resolve_column_group_for_column())) {
|
||||
LOG_WARN("failed to resolve column group", K(ret));
|
||||
} else if (OB_FAIL(check_skip_index(alter_table_stmt->get_alter_table_arg().alter_table_schema_))) {
|
||||
LOG_WARN("failed to resolve skip index", K(ret));
|
||||
@ -1380,6 +1386,7 @@ int ObAlterTableResolver::resolve_add_index(const ParseNode &node)
|
||||
ParseNode *column_list_node = nullptr;
|
||||
ParseNode *table_option_node = nullptr;
|
||||
ParseNode *index_partition_option = nullptr;
|
||||
ParseNode *colulmn_group_node = nullptr;
|
||||
bool is_index_part_specified = false;
|
||||
CHECK_COMPATIBILITY_MODE(session_info_);
|
||||
if (is_unique_key && lib::is_oracle_mode()) {
|
||||
@ -1393,10 +1400,16 @@ int ObAlterTableResolver::resolve_add_index(const ParseNode &node)
|
||||
}
|
||||
} else {
|
||||
// mysql mode
|
||||
index_name_node = node.children_[0];
|
||||
column_list_node = node.children_[1];
|
||||
table_option_node = node.children_[2];
|
||||
index_partition_option = node.children_[4];
|
||||
if (OB_UNLIKELY(ALTER_INDEX_CHILD_NUM != node.num_child_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid parse tree", K(ret), K(node.num_child_));
|
||||
} else {
|
||||
index_name_node = node.children_[0];
|
||||
column_list_node = node.children_[1];
|
||||
table_option_node = node.children_[2];
|
||||
index_partition_option = node.children_[4];
|
||||
colulmn_group_node = node.children_[5];
|
||||
}
|
||||
}
|
||||
ObAlterTableStmt *alter_table_stmt = get_alter_table_stmt();
|
||||
if (OB_ISNULL(alter_table_stmt)) {
|
||||
@ -1554,6 +1567,21 @@ int ObAlterTableResolver::resolve_add_index(const ParseNode &node)
|
||||
is_index_part_specified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret) && is_mysql_mode()) {
|
||||
if (OB_ISNULL(colulmn_group_node)) {
|
||||
// no cg, ignore
|
||||
} else if (T_COLUMN_GROUP != colulmn_group_node->type_ || colulmn_group_node->num_child_ <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SQL_RESV_LOG(WARN, "invalid argument", KR(ret), K(colulmn_group_node->type_), K(colulmn_group_node->num_child_));
|
||||
} else if (OB_ISNULL(colulmn_group_node->children_[0])) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("node is null", K(ret));
|
||||
} else if (OB_FAIL(resolve_index_column_group(colulmn_group_node, *create_index_arg))) {
|
||||
SQL_RESV_LOG(WARN, "resolve index column group failed", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret) && lib::is_mysql_mode()) {
|
||||
if (OB_FAIL(set_index_tablespace(*table_schema_, *create_index_arg))) {
|
||||
LOG_WARN("fail to set index tablespace", K(ret));
|
||||
@ -5933,7 +5961,7 @@ int ObAlterTableResolver::resolve_modify_all_trigger(const ParseNode &node)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObAlterTableResolver::resolve_column_group()
|
||||
int ObAlterTableResolver::resolve_column_group_for_column()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_normal_column_store_table = false;
|
||||
@ -5946,7 +5974,8 @@ int ObAlterTableResolver::resolve_column_group()
|
||||
} else if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, compat_version))) {
|
||||
LOG_WARN("fail to get min data version", KR(ret), K(tenant_id));
|
||||
} else if (compat_version < DATA_VERSION_4_3_0_0) { //skip resolve cg
|
||||
} else if (table_schema_->is_normal_column_store_table()) {
|
||||
} else if (table_schema_->get_column_group_count() > 0) {
|
||||
// TODO, wait to support table update from 4.1 or less
|
||||
ObColumnGroupSchema column_group;
|
||||
char cg_name[OB_MAX_COLUMN_GROUP_NAME_LENGTH];
|
||||
ObArray<uint64_t> column_ids;
|
||||
@ -5989,6 +6018,129 @@ int ObAlterTableResolver::resolve_column_group()
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObAlterTableResolver::resolve_alter_column_groups(const ParseNode &node)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObAlterTableStmt *alter_table_stmt = get_alter_table_stmt();
|
||||
if (OB_ISNULL(alter_table_stmt) || OB_UNLIKELY(T_ALTER_COLUMN_GROUP_OPTION != node.type_ ||
|
||||
OB_ISNULL(node.children_))) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SQL_RESV_LOG(WARN, "get alter table stmt failed", K(ret), K(node.type_), KP(node.children_));
|
||||
} else {
|
||||
const ParseNode *column_group_node = node.children_[0];
|
||||
uint64_t compat_version = 0;
|
||||
|
||||
ObAlterTableArg &alter_table_arg = alter_table_stmt->get_alter_table_arg();
|
||||
share::schema::AlterTableSchema &alter_table_schema = alter_table_arg.alter_table_schema_;
|
||||
const uint64_t column_cnt = table_schema_->get_column_count();
|
||||
const uint64_t tenant_id = table_schema_->get_tenant_id();
|
||||
|
||||
if (OB_ISNULL(column_group_node) || column_group_node->num_child_ <= 0) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_RESV_LOG(WARN, "invalid parse tree, column group node is null or have no children!",
|
||||
K(ret), KP(column_group_node));
|
||||
} else if (OB_FAIL(GET_MIN_DATA_VERSION(tenant_id, compat_version))) {
|
||||
SQL_RESV_LOG(WARN, "fail to get min data version", K(ret));
|
||||
} else if (compat_version < DATA_VERSION_4_3_0_0) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
SQL_RESV_LOG(WARN, "data_version not support for altering column group", K(ret), K(compat_version));
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "tenant data version is less than 4.3, alter column group");
|
||||
} else if (!need_column_group(*table_schema_)) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
SQL_RESV_LOG(WARN, "table don't support alter column group", K(ret));
|
||||
} else {
|
||||
alter_table_schema.set_column_store(true);
|
||||
if (column_group_node->type_ == T_COLUMN_GROUP_ADD) {
|
||||
alter_table_stmt->get_alter_table_arg().alter_table_schema_.alter_type_ = OB_DDL_ADD_COLUMN_GROUP;
|
||||
} else if (column_group_node->type_ == T_COLUMN_GROUP_DROP) {
|
||||
alter_table_stmt->get_alter_table_arg().alter_table_schema_.alter_type_ = OB_DDL_DROP_COLUMN_GROUP;
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_RESV_LOG(WARN, "invalid parse tree ", K(ret), K(column_group_node->type_));
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
ObColumnGroupSchema column_group_schema;
|
||||
bool sql_exist_all_column_group = false;
|
||||
bool sql_exist_single_column_group = false;
|
||||
alter_table_schema.set_max_used_column_group_id(table_schema_->get_max_used_column_group_id());
|
||||
|
||||
/* check exist type and whether exist repeation of column group type*/
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < column_group_node->num_child_; ++i) {
|
||||
if (OB_ISNULL(column_group_node->children_[i])) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
SQL_RESV_LOG(WARN, "column group node children is null", K(ret), K(i));
|
||||
} else if (column_group_node->children_[i]->type_ == T_ALL_COLUMN_GROUP) {
|
||||
if (sql_exist_all_column_group) {
|
||||
ret = OB_ERR_COLUMN_GROUP_DUPLICATE;
|
||||
SQL_RESV_LOG(WARN, "all column group already exist in sql",
|
||||
K(ret), K(column_group_node->children_[i]->type_));
|
||||
const ObString error_msg = "all column group";
|
||||
LOG_USER_ERROR(OB_ERR_COLUMN_GROUP_DUPLICATE, error_msg.length(), error_msg.ptr());
|
||||
} else {
|
||||
sql_exist_all_column_group = true;
|
||||
}
|
||||
} else if (column_group_node->children_[i]-> type_ == T_SINGLE_COLUMN_GROUP) {
|
||||
if (sql_exist_single_column_group) {
|
||||
ret = OB_ERR_COLUMN_GROUP_DUPLICATE;
|
||||
SQL_RESV_LOG(WARN, "single column group already exist in sql",
|
||||
K(ret), K(column_group_node->children_[i]->type_));
|
||||
const ObString error_msg = "single column group";
|
||||
LOG_USER_ERROR(OB_ERR_COLUMN_GROUP_DUPLICATE, error_msg.length(), error_msg.ptr());
|
||||
} else {
|
||||
sql_exist_single_column_group = true;
|
||||
}
|
||||
} else {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
SQL_RESV_LOG(WARN, "Resovle unsupported column group type",
|
||||
K(ret), K(column_group_node->children_[i]->type_));
|
||||
}
|
||||
}
|
||||
|
||||
/* all column group */
|
||||
/* column group in resolver do not use real column group id*/
|
||||
/* ddl service use column group name to distingush them*/
|
||||
if (OB_SUCC(ret) && sql_exist_all_column_group) {
|
||||
column_group_schema.reset();
|
||||
if (OB_FAIL(ObSchemaUtils::build_all_column_group(*table_schema_, session_info_->get_effective_tenant_id(),
|
||||
alter_table_schema.get_max_used_column_group_id() + 1,
|
||||
column_group_schema))) {
|
||||
SQL_RESV_LOG(WARN, "build all column group failed", K(ret));
|
||||
} else if (OB_FAIL(alter_table_schema.add_column_group(column_group_schema))) {
|
||||
SQL_RESV_LOG(WARN, "fail to add column group schema", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
/* single column group*/
|
||||
if (OB_SUCC(ret) && sql_exist_single_column_group) {
|
||||
column_group_schema.reset();
|
||||
ObTableSchema::const_column_iterator iter_begin = table_schema_->column_begin();
|
||||
ObTableSchema::const_column_iterator iter_end = table_schema_->column_end();
|
||||
for (;OB_SUCC(ret) && iter_begin != iter_end; ++iter_begin) {
|
||||
ObColumnSchemaV2 *column = (*iter_begin);
|
||||
uint64_t cg_id = alter_table_schema.get_max_used_column_group_id() + 1;
|
||||
if (OB_ISNULL(column)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("column schema should not be null", K(ret));
|
||||
} else if (column->is_virtual_generated_column()) {
|
||||
/* skip virtual column*/
|
||||
} else if (OB_FAIL(ObSchemaUtils::build_single_column_group(
|
||||
*table_schema_, column, session_info_->get_effective_tenant_id(),
|
||||
cg_id, column_group_schema))) {
|
||||
LOG_WARN("fail to build single column group", K(ret));
|
||||
} else if (column_group_schema.is_valid()) {
|
||||
if (OB_FAIL(alter_table_schema.add_column_group(column_group_schema))) {
|
||||
LOG_WARN("fail to add single column group to table schema", K(ret), K(column_group_schema));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObAlterTableResolver::is_ttl_column(const ObString &orig_column_name, const ObIArray<ObString> &ttl_columns)
|
||||
{
|
||||
bool bret = false;
|
||||
|
||||
Reference in New Issue
Block a user