fix bug, dbms_metadata.get_ddl not show cg info of column store index
This commit is contained in:
parent
a19fff3cb2
commit
0c935cf425
@ -1063,87 +1063,56 @@ int ObIndexBuilder::create_index_column_group(const obrpc::ObCreateIndexArg &arg
|
||||
} else if (compat_version >= DATA_VERSION_4_3_0_0) {
|
||||
ObArray<uint64_t> column_ids; // not include virtual column
|
||||
index_table_schema.set_column_store(true);
|
||||
if (arg.index_cgs_.count() > 0) {
|
||||
index_table_schema.set_max_used_column_group_id(index_table_schema.get_max_used_column_group_id());
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < arg.index_cgs_.count(); ++i) {
|
||||
bool is_all_cg_exist = arg.exist_all_column_group_; //for compat
|
||||
bool is_each_cg_exist = false;
|
||||
ObColumnGroupSchema tmp_cg;
|
||||
/* check exist column group*/
|
||||
for (int64_t i = 0; OB_SUCC(ret) && i < arg.index_cgs_.count(); ++i) {
|
||||
const obrpc::ObCreateIndexArg::ObIndexColumnGroupItem &cur_item = arg.index_cgs_.at(i);
|
||||
if (!cur_item.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid cg item", K(ret), K(cur_item));
|
||||
} else if (cur_item.is_each_cg_) {
|
||||
// handle all_type column_group & single_type column_group
|
||||
ObColumnGroupSchema column_group_schema;
|
||||
const int64_t column_cnt = index_table_schema.get_column_count();
|
||||
if (OB_FAIL(column_ids.reserve(column_cnt))) {
|
||||
LOG_WARN("fail to reserve", KR(ret), K(column_cnt));
|
||||
} else {
|
||||
ObTableSchema::const_column_iterator tmp_begin = index_table_schema.column_begin();
|
||||
ObTableSchema::const_column_iterator tmp_end = index_table_schema.column_end();
|
||||
for (; OB_SUCC(ret) && (tmp_begin != tmp_end); tmp_begin++) {
|
||||
column_group_schema.reset();
|
||||
ObColumnSchemaV2 *column = (*tmp_begin);
|
||||
if (OB_FAIL(ObSchemaUtils::build_single_column_group(
|
||||
index_table_schema, column, index_table_schema.get_tenant_id(),
|
||||
index_table_schema.get_max_used_column_group_id() + 1, column_group_schema))) {
|
||||
LOG_WARN("fail to build single column group");
|
||||
} else if (column_group_schema.is_valid()) {
|
||||
if (OB_FAIL(index_table_schema.add_column_group(column_group_schema))) {
|
||||
LOG_WARN("fail to add single type column group", KR(ret), K(column_group_schema));
|
||||
} else if (column->is_rowkey_column() || arg.exist_all_column_group_) {//if not exist all cg, build rowkey cg
|
||||
if (OB_FAIL(column_ids.push_back(column->get_column_id()))) {
|
||||
LOG_WARN("fail to push back", KR(ret), "column_id", column->get_column_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
column_group_schema.reset();
|
||||
const ObColumnGroupType cg_type = arg.exist_all_column_group_ ? ObColumnGroupType::ALL_COLUMN_GROUP
|
||||
: ObColumnGroupType::ROWKEY_COLUMN_GROUP;
|
||||
const ObString cg_name = arg.exist_all_column_group_ ? OB_ALL_COLUMN_GROUP_NAME : OB_ROWKEY_COLUMN_GROUP_NAME;
|
||||
|
||||
if (OB_FAIL(ObSchemaUtils::build_column_group(index_table_schema, index_table_schema.get_tenant_id(), cg_type, cg_name,
|
||||
column_ids, index_table_schema.get_max_used_column_group_id() + 1, column_group_schema))) {
|
||||
LOG_WARN("fail to build all type column_group", KR(ret), K(column_ids));
|
||||
} else if (OB_FAIL(index_table_schema.add_column_group(column_group_schema))) {
|
||||
LOG_WARN("fail to add all type column group", KR(ret), K(column_group_schema));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!cur_item.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid cg item", K(ret), K(cur_item));
|
||||
} else if (ObColumnGroupType::SINGLE_COLUMN_GROUP == cur_item.cg_type_) {
|
||||
is_each_cg_exist = true;
|
||||
} else if (ObColumnGroupType::ALL_COLUMN_GROUP == cur_item.cg_type_) {
|
||||
is_all_cg_exist = true;
|
||||
} else {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid column group type", K(ret), K(cur_item.cg_type_));
|
||||
}
|
||||
}
|
||||
/* build each column group */
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (!is_each_cg_exist) {
|
||||
} else if (OB_FAIL(ObSchemaUtils::build_add_each_column_group(index_table_schema, index_table_schema))) {
|
||||
LOG_WARN("failed to build all cg", K(ret));
|
||||
}
|
||||
/* build all column group*/
|
||||
tmp_cg.reset();
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (!is_all_cg_exist) {
|
||||
} else if (OB_FAIL(ObSchemaUtils::build_all_column_group(index_table_schema,
|
||||
index_table_schema.get_tenant_id(),
|
||||
index_table_schema.get_max_used_column_group_id() + 1,
|
||||
tmp_cg))) {
|
||||
LOG_WARN("failed to build all column group", K(ret));
|
||||
} else if (OB_FAIL(index_table_schema.add_column_group(tmp_cg))) {
|
||||
LOG_WARN("failed to add column group", K(ret), K(index_table_schema), K(tmp_cg));
|
||||
}
|
||||
|
||||
// add default column_group
|
||||
if (OB_SUCC(ret)) {
|
||||
ObColumnGroupSchema tmp_cg;
|
||||
if (arg.index_cgs_.count() > 0) {
|
||||
column_ids.reuse(); // if exists cg node, column_ids in default_type will be empty
|
||||
} else {
|
||||
ObTableSchema::const_column_iterator tmp_begin = index_table_schema.column_begin();
|
||||
ObTableSchema::const_column_iterator tmp_end = index_table_schema.column_end();
|
||||
for (; OB_SUCC(ret) && (tmp_begin != tmp_end); tmp_begin++) {
|
||||
ObColumnSchemaV2 *column = (*tmp_begin);
|
||||
if (OB_ISNULL(column)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("column should not be null", KR(ret));
|
||||
} else if (column->is_virtual_generated_column()) {
|
||||
// skip virtual column
|
||||
} else if (OB_FAIL(column_ids.push_back(column->get_column_id()))) {
|
||||
LOG_WARN("fail to push back", KR(ret), "column_id", column->get_column_id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILEDx(ObSchemaUtils::build_column_group(index_table_schema, index_table_schema.get_tenant_id(),
|
||||
ObColumnGroupType::DEFAULT_COLUMN_GROUP, OB_DEFAULT_COLUMN_GROUP_NAME, column_ids,
|
||||
DEFAULT_TYPE_COLUMN_GROUP_ID, tmp_cg))) {
|
||||
LOG_WARN("fail to build default type column_group", KR(ret), "table_id", index_table_schema.get_table_id(), K(column_ids));
|
||||
} else if (OB_FAIL(index_table_schema.add_column_group(tmp_cg))) {
|
||||
LOG_WARN("fail to add default column group", KR(ret), "table_id", index_table_schema.get_table_id(),
|
||||
K(arg.index_cgs_.count()), K(column_ids));
|
||||
}
|
||||
if (OB_FAIL(ret)) { /* build empty default cg*/
|
||||
} else if (FALSE_IT(tmp_cg.reset())) {
|
||||
} else if (OB_FAIL(ObSchemaUtils::build_column_group(index_table_schema, index_table_schema.get_tenant_id(),
|
||||
ObColumnGroupType::DEFAULT_COLUMN_GROUP,
|
||||
OB_DEFAULT_COLUMN_GROUP_NAME, column_ids,
|
||||
DEFAULT_TYPE_COLUMN_GROUP_ID, tmp_cg))) {
|
||||
LOG_WARN("fail to build default type column_group", KR(ret), "table_id", index_table_schema.get_table_id());
|
||||
} else if (OB_FAIL(index_table_schema.add_column_group(tmp_cg))) {
|
||||
LOG_WARN("failed to add column group", K(ret), K(index_table_schema), K(tmp_cg));
|
||||
} else if (OB_FAIL(ObSchemaUtils::alter_rowkey_column_group(index_table_schema))) { /* build rowkey cg*/
|
||||
LOG_WARN("fail to adjust for rowkey column group", K(ret), K(index_table_schema));
|
||||
} else if (OB_FAIL(ObSchemaUtils::alter_default_column_group(index_table_schema))) { /* set val in default cg*/
|
||||
LOG_WARN("fail to adjust for default column group", K(ret), K(index_table_schema));
|
||||
}
|
||||
} else if (arg.index_cgs_.count() > 0) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
|
@ -3108,12 +3108,13 @@ bool ObCreateIndexArg::is_valid() const
|
||||
&& index_using_type_ >= USING_BTREE
|
||||
&& index_using_type_ < USING_TYPE_MAX;
|
||||
}
|
||||
OB_SERIALIZE_MEMBER(ObCreateIndexArg::ObIndexColumnGroupItem, is_each_cg_, column_list_);
|
||||
OB_SERIALIZE_MEMBER(ObCreateIndexArg::ObIndexColumnGroupItem, is_each_cg_, column_list_, cg_type_);
|
||||
|
||||
int ObCreateIndexArg::ObIndexColumnGroupItem::assign(const ObCreateIndexArg::ObIndexColumnGroupItem &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
is_each_cg_ = other.is_each_cg_;
|
||||
cg_type_ = other.cg_type_;
|
||||
if (OB_FAIL(column_list_.assign(other.column_list_))) {
|
||||
LOG_WARN("fail to assign array", K(ret));
|
||||
}
|
||||
|
@ -2649,29 +2649,29 @@ public:
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObIndexColumnGroupItem() : is_each_cg_(false), column_list_()
|
||||
{}
|
||||
ObIndexColumnGroupItem(const bool is_each_cg) : is_each_cg_(is_each_cg), column_list_()
|
||||
{}
|
||||
ObIndexColumnGroupItem() : is_each_cg_(false), column_list_(), cg_type_(ObColumnGroupType::SINGLE_COLUMN_GROUP)
|
||||
{} /* to compat former version, force to set default value as single column group*/
|
||||
~ObIndexColumnGroupItem()
|
||||
{
|
||||
reset();
|
||||
}
|
||||
bool is_valid() const
|
||||
{
|
||||
return is_each_cg_;
|
||||
return cg_type_ < ObColumnGroupType::NORMAL_COLUMN_GROUP;
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
is_each_cg_ = false;
|
||||
column_list_.reset();
|
||||
cg_type_ = ObColumnGroupType::SINGLE_COLUMN_GROUP;
|
||||
}
|
||||
int assign(const ObIndexColumnGroupItem &other);
|
||||
TO_STRING_KV(K(is_each_cg_), K(column_list_));
|
||||
TO_STRING_KV(K(is_each_cg_), K(column_list_), K(cg_type_));
|
||||
|
||||
public:
|
||||
bool is_each_cg_;
|
||||
ObCGColumnList column_list_;
|
||||
ObCGColumnList column_list_; /* column list not used yet, wait user define cg*/
|
||||
ObColumnGroupType cg_type_;
|
||||
};
|
||||
|
||||
public:
|
||||
|
@ -2747,6 +2747,8 @@ int ObSchemaPrinter::print_index_table_definition(
|
||||
OB_LOG(WARN, "fail to print partition info for index", K(ret), K(*index_table_schema));
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, ";\n"))) {
|
||||
OB_LOG(WARN, "fail to print end ;", K(ret));
|
||||
} else if ((!strict_compat_) && OB_FAIL(print_table_definition_column_group(*index_table_schema, buf, buf_len, pos))) {
|
||||
SHARE_SCHEMA_LOG(WARN, "fail to print column_group", K(ret), K(*index_table_schema));
|
||||
}
|
||||
OB_LOG(DEBUG, "print table schema", K(ret), K(*index_table_schema));
|
||||
}
|
||||
|
@ -3331,10 +3331,10 @@ int ObCreateTableResolver::resolve_column_group(const ParseNode *cg_node)
|
||||
}
|
||||
}
|
||||
|
||||
// only when not cg node use default format
|
||||
/* build column group when cg node is null && tenant cg valid*/
|
||||
ObTenantConfigGuard tenant_config(TENANT_CONF(session_info_->get_effective_tenant_id()));
|
||||
if (OB_SUCC(ret) && OB_LIKELY(tenant_config.is_valid()) && nullptr == cg_node) {
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if ( OB_LIKELY(tenant_config.is_valid()) && nullptr == cg_node) {
|
||||
/* force to build each cg*/
|
||||
if (!ObSchemaUtils::can_add_column_group(table_schema)) {
|
||||
} else if (OB_FAIL(ObTableStoreFormat::find_table_store_type(
|
||||
@ -3343,11 +3343,7 @@ int ObCreateTableResolver::resolve_column_group(const ParseNode *cg_node)
|
||||
LOG_WARN("fail to get table store format", K(ret), K(table_store_type));
|
||||
} else if (ObTableStoreFormat::is_with_column(table_store_type)) {
|
||||
/* for default is column store, must add each column group*/
|
||||
bool is_each_column_exist = false;
|
||||
if (OB_FAIL(table_schema.is_column_group_exist(OB_EACH_COLUMN_GROUP_NAME, is_each_column_exist))) {
|
||||
LOG_WARN("fail to check is each column group exist", K(ret));
|
||||
} else if (is_each_column_exist) {
|
||||
} else if (OB_FAIL(ObSchemaUtils::build_add_each_column_group(table_schema, table_schema))) {
|
||||
if (OB_FAIL(ObSchemaUtils::build_add_each_column_group(table_schema, table_schema))) {
|
||||
LOG_WARN("fail to add each column group", K(ret));
|
||||
}
|
||||
}
|
||||
@ -3357,10 +3353,7 @@ int ObCreateTableResolver::resolve_column_group(const ParseNode *cg_node)
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (!ObSchemaUtils::can_add_column_group(table_schema)) {
|
||||
} else if (ObTableStoreFormat::is_row_with_column_store(table_store_type)) {
|
||||
bool is_all_cg_exist = false;
|
||||
if (OB_FAIL(table_schema.is_column_group_exist(OB_ALL_COLUMN_GROUP_NAME, is_all_cg_exist))) {
|
||||
LOG_WARN("fail to check is all column group exist", K(ret));
|
||||
} else if (OB_FAIL(ObSchemaUtils::build_all_column_group(table_schema, table_schema.get_tenant_id(),
|
||||
if (OB_FAIL(ObSchemaUtils::build_all_column_group(table_schema, table_schema.get_tenant_id(),
|
||||
table_schema.get_max_used_column_group_id() + 1, all_cg))) {
|
||||
LOG_WARN("fail to add all column group", K(ret));
|
||||
} else if (OB_FAIL(table_schema.add_column_group(all_cg))) {
|
||||
|
@ -11990,17 +11990,17 @@ int ObDDLResolver::parse_column_group(const ParseNode *column_group_node,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDDLResolver::parse_cg_node(const ParseNode &cg_node, bool &exist_all_column_group) const
|
||||
int ObDDLResolver::parse_cg_node(const ParseNode &cg_node, obrpc::ObCreateIndexArg &create_index_arg) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
exist_all_column_group = false;
|
||||
bool is_all_cg_exist = false;
|
||||
bool is_each_cg_exist = false;
|
||||
|
||||
if (OB_UNLIKELY(T_COLUMN_GROUP != cg_node.type_ || cg_node.num_child_ <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SQL_RESV_LOG(WARN, "invalid argument", KR(ret), K(cg_node.type_), K(cg_node.num_child_));
|
||||
} else {
|
||||
const int64_t num_child = cg_node.num_child_;
|
||||
bool exist_single_type = false;
|
||||
// handle all_type column_group & single_type column_group
|
||||
for (int64_t i = 0; OB_SUCC(ret) && (i < num_child); ++i) {
|
||||
ParseNode *node = cg_node.children_[i];
|
||||
@ -12008,24 +12008,24 @@ int ObDDLResolver::parse_cg_node(const ParseNode &cg_node, bool &exist_all_colum
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("children of column_group_list should not be null", KR(ret));
|
||||
} else if (T_ALL_COLUMN_GROUP == node->type_) {
|
||||
if (exist_all_column_group) {
|
||||
if (is_all_cg_exist) {
|
||||
ret = OB_ERR_COLUMN_GROUP_DUPLICATE;
|
||||
SQL_RESV_LOG(WARN, "all column group already exist in sql",
|
||||
K(ret), K(node->children_[i]->type_));
|
||||
const ObString error_msg = "all columns";
|
||||
LOG_USER_ERROR(OB_ERR_COLUMN_GROUP_DUPLICATE, error_msg.length(), error_msg.ptr());
|
||||
} else {
|
||||
exist_all_column_group = true;
|
||||
is_all_cg_exist = true;
|
||||
}
|
||||
} else if (T_SINGLE_COLUMN_GROUP == node->type_) {
|
||||
if (exist_single_type) {
|
||||
if (is_each_cg_exist) {
|
||||
ret = OB_ERR_COLUMN_GROUP_DUPLICATE;
|
||||
SQL_RESV_LOG(WARN, "single column group already exist in sql",
|
||||
K(ret), K(node->type_));
|
||||
const ObString error_msg = "each column";
|
||||
LOG_USER_ERROR(OB_ERR_COLUMN_GROUP_DUPLICATE, error_msg.length(), error_msg.ptr());
|
||||
} else {
|
||||
exist_single_type = true;
|
||||
is_each_cg_exist = true;
|
||||
}
|
||||
} else if (T_NORMAL_COLUMN_GROUP == node->type_) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
@ -12033,8 +12033,28 @@ int ObDDLResolver::parse_cg_node(const ParseNode &cg_node, bool &exist_all_colum
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "column store tables with customized column group are");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (is_each_cg_exist) {
|
||||
obrpc::ObCreateIndexArg::ObIndexColumnGroupItem each_cg_item;
|
||||
each_cg_item.is_each_cg_ = true;
|
||||
each_cg_item.cg_type_ = ObColumnGroupType::SINGLE_COLUMN_GROUP;
|
||||
if (OB_FAIL(create_index_arg.index_cgs_.push_back(each_cg_item))) {
|
||||
LOG_WARN("failed to push back value", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (is_all_cg_exist) {
|
||||
obrpc::ObCreateIndexArg::ObIndexColumnGroupItem all_cg_item;
|
||||
all_cg_item.is_each_cg_ = false;
|
||||
all_cg_item.cg_type_ = ObColumnGroupType::ALL_COLUMN_GROUP;
|
||||
if (OB_FAIL(create_index_arg.index_cgs_.push_back(all_cg_item))) {
|
||||
LOG_WARN("failed to push back value", K(ret));
|
||||
} else {
|
||||
create_index_arg.exist_all_column_group_ = true; /* for compat*/
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -12111,12 +12131,8 @@ int ObDDLResolver::resolve_index_column_group(const ParseNode *cg_node, obrpc::O
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "tenant data version is less than 4.3, create index with column group");
|
||||
} else {
|
||||
bool exist_all_column_group = false;
|
||||
if (OB_FAIL(parse_cg_node(*cg_node, exist_all_column_group))) {
|
||||
if (OB_FAIL(parse_cg_node(*cg_node, create_index_arg))) {
|
||||
LOG_WARN("fail to parse cg node", KR(ret));
|
||||
} else if (OB_FAIL(create_index_arg.index_cgs_.push_back(obrpc::ObCreateIndexArg::ObIndexColumnGroupItem(true/*each cg*/)))) {
|
||||
LOG_WARN("fail to push each cg", K(ret));
|
||||
} else {
|
||||
create_index_arg.exist_all_column_group_ = exist_all_column_group;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -530,7 +530,7 @@ protected:
|
||||
const common::ObIArray<uint64_t> &column_ids,
|
||||
const uint64_t cg_id,
|
||||
share::schema::ObColumnGroupSchema &column_group);
|
||||
int parse_cg_node(const ParseNode &cg_node, bool &exist_all_column_group) const;
|
||||
int parse_cg_node(const ParseNode &cg_node, obrpc::ObCreateIndexArg &create_index_arg) const;
|
||||
int parse_column_group(const ParseNode *cg_node,const share::schema::ObTableSchema &table_schema, share::schema::ObTableSchema &dst_table_schema);
|
||||
int resolve_index_column_group(const ParseNode *node, obrpc::ObCreateIndexArg &create_index_arg);
|
||||
bool need_column_group(const ObTableSchema &table_schema);
|
||||
|
Loading…
x
Reference in New Issue
Block a user