fix create table range columns problem

This commit is contained in:
LYAccc 2024-10-25 04:13:34 +00:00 committed by ob-robot
parent 8aab6791cd
commit ce0877a2c1
8 changed files with 102 additions and 64 deletions

View File

@ -3803,10 +3803,18 @@ int ObDDLService::create_hidden_table_with_pk_changed(
// of the data_table will always be "current" primary key.
// thus, when modify primary key, we need to check whether the part_func_type is need to be modified
const bool is_single_pk_column_new = new_table_schema.get_rowkey_column_num() == 1;
ObPartitionFuncType part_func_type = PARTITION_FUNC_TYPE_MAX;
ObPartitionFuncType part_func_type = PARTITION_FUNC_TYPE_RANGE;
if (is_single_pk_column_new) {
if (OB_FAIL(new_table_schema.detect_part_func_type(part_func_type))) {
LOG_WARN("check part func type failed", K(ret), K(new_table_schema));
ObObjMeta type;
ObRowkeyColumn row_key_col;
const common::ObRowkeyInfo &row_key_info = new_table_schema.get_rowkey_info();
if (OB_FAIL(row_key_info.get_column(0/*since there is only one row key, we only need to check the first one*/, row_key_col))) {
LOG_WARN("get row key column failed", K(ret), K(row_key_info));
} else {
type = row_key_col.get_meta_type();
}
if (ObResolverUtils::is_partition_range_column_type(type.get_type())) {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
}
} else {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;

View File

@ -1734,7 +1734,7 @@ int ObIndexBuilder::set_global_index_auto_partition_infos(const share::schema::O
{
int ret = OB_SUCCESS;
const ObPartitionOption& index_part_option = schema.get_part_option();
ObPartitionFuncType part_type = PARTITION_FUNC_TYPE_MAX;
if (OB_UNLIKELY(!data_schema.is_valid())) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(data_schema), KR(ret));
@ -1754,9 +1754,9 @@ int ObIndexBuilder::set_global_index_auto_partition_infos(const share::schema::O
KR(ret), K(schema), K(data_schema));
} else {
const ObRowkeyInfo &presetting_partition_keys = schema.get_index_info();
ObPartitionFuncType part_type = presetting_partition_keys.get_size() > 1 ?
ObPartitionFuncType::PARTITION_FUNC_TYPE_RANGE_COLUMNS :
ObPartitionFuncType::PARTITION_FUNC_TYPE_RANGE;
part_type = presetting_partition_keys.get_size() > 1 ?
ObPartitionFuncType::PARTITION_FUNC_TYPE_RANGE_COLUMNS :
ObPartitionFuncType::PARTITION_FUNC_TYPE_RANGE;
for (int64_t i = 0; enable_auto_split && OB_SUCC(ret) && i < presetting_partition_keys.get_size(); ++i) {
const ObRowkeyColumn *partition_column = presetting_partition_keys.get_column(i);
if (OB_ISNULL(partition_column)) {
@ -1796,7 +1796,7 @@ int ObIndexBuilder::set_global_index_auto_partition_infos(const share::schema::O
ret = OB_NOT_SUPPORTED;
LOG_WARN("current data version doesn't support to split partition", KR(ret), K(data_version));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "data version lower than 4.4 is");
} else if (OB_FAIL(schema.enable_auto_partition(auto_part_size))) {
} else if (OB_FAIL(schema.enable_auto_partition(auto_part_size, part_type))) {
LOG_WARN("fail to enable auto partition", KR(ret));
}
}

View File

@ -1893,7 +1893,7 @@ int ObTableSchema::assign_partition_schema_without_auto_part_attr(const ObTableS
return ret;
}
int ObTableSchema::enable_auto_partition(const int64_t auto_part_size)
int ObTableSchema::enable_auto_partition(const int64_t auto_part_size, const ObPartitionFuncType &part_func_type)
{
int ret = OB_SUCCESS;
if (is_partitioned_table()) {
@ -1901,56 +1901,59 @@ int ObTableSchema::enable_auto_partition(const int64_t auto_part_size)
LOG_WARN("fail to enable auto partition", KR(ret), K(auto_part_size));
}
} else {
ObPartitionFuncType part_func_type;
if (OB_FAIL(detect_part_func_type(part_func_type))) {
ObPartitionFuncType part_type = part_func_type;
if (OB_FAIL(detect_auto_part_func_type(part_type))) {
LOG_WARN("fail to check part func type", K(ret));
} else if (OB_FAIL(part_option_.enable_auto_partition(auto_part_size, part_func_type))) {
} else if (OB_FAIL(part_option_.enable_auto_partition(auto_part_size, part_type))) {
LOG_WARN("fail to enable auto partition", KR(ret), K(auto_part_size));
}
}
return ret;
}
int ObTableSchema::detect_part_func_type(ObPartitionFuncType &part_func_type)
int ObTableSchema::detect_auto_part_func_type(ObPartitionFuncType &part_func_type)
{
int ret = OB_SUCCESS;
part_func_type = PARTITION_FUNC_TYPE_MAX;
const ObString &part_expr = part_option_.get_part_func_expr_str();
static const char DELIMITER = ',';
bool is_range_columns = !part_expr.empty() ?
part_expr.find(DELIMITER) != nullptr :
is_index_table() ? get_index_column_num() > 1 :
get_rowkey_column_num() > 1;
if (!is_range_columns && part_expr.empty()) {
/*in case of create table t1(a timestamp, b VARCHAR(150), c int, d VARCHAR(4000), primary key(a)) partition by range ()*/
ObObjMeta type;
if (!is_index_table()) {
ObRowkeyColumn row_key_col;
const common::ObRowkeyInfo &row_key_info = get_rowkey_info();
if (OB_FAIL(row_key_info.get_column(0/*since there is only one row key, we only need to check the first one*/, row_key_col))) {
LOG_WARN("get row key column failed", K(ret), K(row_key_info));
} else {
type = row_key_col.get_meta_type();
}
if (part_expr.empty()) {
bool is_range_column_type = false;
if (OB_FAIL(is_range_col_part_type(is_range_column_type))) {
LOG_WARN("failed to check if first part key is range column type", K(ret), K(part_expr));
} else if (is_range_column_type) {
/*in case of create table t1(a timestamp, b VARCHAR(150), c int, d VARCHAR(4000), primary key(a)) partition by range ()*/
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else {
ObIndexColumn index_key_col;
const common::ObIndexInfo &index_key_info = get_index_info();
if (OB_FAIL(index_key_info.get_column(0/*since there is only one index key, we only need to check the first one*/, index_key_col))) {
LOG_WARN("get index key column failed", K(ret), K(index_key_info));
} else {
type = index_key_col.get_meta_type();
}
}
if OB_FAIL(ret) {
} else {
is_range_columns = ObResolverUtils::is_partition_range_column_type(type.get_type());
part_func_type = PARTITION_FUNC_TYPE_RANGE;
}
}
if (OB_SUCC(ret)) {
part_func_type = is_range_columns ?
PARTITION_FUNC_TYPE_RANGE_COLUMNS :
PARTITION_FUNC_TYPE_RANGE;
return ret;
}
//this function can only be used for auto split table check
int ObTableSchema::is_range_col_part_type(bool &is_range_column_type) const
{
int ret = OB_SUCCESS;
is_range_column_type = false;
ObObjMeta type;
if (!is_index_table()) {
ObRowkeyColumn row_key_col;
const common::ObRowkeyInfo &row_key_info = get_rowkey_info();
if (row_key_info.get_size() > 1) {
is_range_column_type = true;
} else if (OB_FAIL(row_key_info.get_column(0/*since there is only one row key, we only need to check the first one*/, row_key_col))) {
LOG_WARN("get row key column failed", K(ret), K(row_key_info));
} else if (ObResolverUtils::is_partition_range_column_type(row_key_col.get_meta_type().get_type())) {
is_range_column_type = true;
}
} else {
ObIndexColumn index_key_col;
const common::ObIndexInfo &index_key_info = get_index_info();
if (index_key_info.get_size() > 1) {
is_range_column_type = true;
} else if (OB_FAIL(index_key_info.get_column(0/*since there is only one index key, we only need to check the first one*/, index_key_col))) {
LOG_WARN("get index key column failed", K(ret), K(index_key_info));
} else if (ObResolverUtils::is_partition_range_column_type(index_key_col.get_meta_type().get_type())) {
is_range_column_type = true;
}
}
return ret;
}

View File

@ -1388,8 +1388,10 @@ public:
// Copy all constraint information in src_schema
int assign_constraint(const ObTableSchema &other);
int assign_partition_schema_without_auto_part_attr(const ObTableSchema &other);
int enable_auto_partition(const int64_t auto_part_size);
int detect_part_func_type(ObPartitionFuncType &part_func_type);
int enable_auto_partition(const int64_t auto_part_size, const ObPartitionFuncType &part_func_type);
int detect_auto_part_func_type(ObPartitionFuncType &part_func_type);
int is_range_col_part_type(bool &is_range_column_type) const;
void forbid_auto_partition();
void clear_constraint();
int set_ttl_definition(const common::ObString &ttl_definition) { return deep_copy_str(ttl_definition, ttl_definition_); }

View File

@ -7957,6 +7957,11 @@ PARTITION BY RANGE '(' expr ')' partition_options opt_range_partition_info
dup_expr_string($$, result, @5.first_column, @5.last_column);
}
|
PARTITION BY RANGE COLUMNS'(' ')' opt_partitions opt_auto_split_tablet_size_option
{
malloc_non_terminal_node($$, result->malloc_pool_, T_RANGE_COLUMNS_PARTITION, 7, NULL, NULL, NULL, $7, NULL, NULL, $8);
}
|
PARTITION BY RANGE COLUMNS '(' column_name_list ')' partition_options opt_range_partition_info
{
ParseNode *params = NULL;

View File

@ -11553,7 +11553,7 @@ int ObDDLResolver::resolve_auto_partition_with_tenant_config(ObCreateTableStmt *
} else if (nullptr != node && OB_FAIL(resolve_auto_partition(stmt, node, table_schema))) {
LOG_WARN("fail to resolve auto partition", KR(ret), K(table_schema), KPC(stmt));
} else if (!stmt->use_auto_partition_clause() &&
OB_FAIL(try_set_auto_partition_by_config(stmt->get_index_arg_list(), table_schema))) {
OB_FAIL(try_set_auto_partition_by_config(node, stmt->get_index_arg_list(), table_schema))) {
LOG_WARN("fail to try to set auto_partition by config", KR(ret), K(table_schema), KPC(stmt));
}
return ret;
@ -11661,7 +11661,6 @@ int ObDDLResolver::resolve_auto_partition(ObPartitionedStmt *stmt, ParseNode *no
ret = OB_INVALID_ARGUMENT;
SQL_RESV_LOG(WARN, "invalid argument", KR(ret), K(node->children_));
}
if (OB_FAIL(ret)) {
} else if (FALSE_IT(stmt->set_use_auto_partition_clause(!SET_PARTITION_DEFINITION
|| SET_AUTO_PARTITION_SIZE))) {
@ -11732,9 +11731,18 @@ int ObDDLResolver::resolve_auto_partition(ObPartitionedStmt *stmt, ParseNode *no
ret = OB_NOT_SUPPORTED;
LOG_WARN("current data version doesn't support to auto split partition", KR(ret), K(data_version));
LOG_USER_ERROR(OB_NOT_SUPPORTED, "data version lower than 4.4 is");
} else if(OB_FAIL(table_schema.enable_auto_partition(auto_part_size))) {
LOG_WARN("fail to enable auto partition", KR(ret), K(table_schema));
} else {
ObPartitionFuncType part_func_type = PARTITION_FUNC_TYPE_MAX;
if (T_RANGE_COLUMNS_PARTITION == node->type_) {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else if (T_RANGE_PARTITION == node->type_) {
part_func_type = PARTITION_FUNC_TYPE_RANGE;
}
if (OB_FAIL(table_schema.enable_auto_partition(auto_part_size, part_func_type))) {
LOG_WARN("fail to enable auto partition", KR(ret), K(table_schema));
}
}
}
}
@ -11847,7 +11855,8 @@ int ObDDLResolver::resolve_presetting_partition_key(ParseNode *node, ObTableSche
// if tenant_config->enable_auto_split == true and table_schema is valid for auto-partition,
// enable auto-partition for the table;
// otherwise, do nothing
int ObDDLResolver::try_set_auto_partition_by_config(common::ObIArray<obrpc::ObCreateIndexArg> &index_arg_list,
int ObDDLResolver::try_set_auto_partition_by_config(const ParseNode *node,
common::ObIArray<obrpc::ObCreateIndexArg> &index_arg_list,
ObTableSchema &table_schema)
{
int ret = OB_SUCCESS;
@ -11867,7 +11876,8 @@ int ObDDLResolver::try_set_auto_partition_by_config(common::ObIArray<obrpc::ObCr
LOG_INFO("tenant_config has not been loaded over");
} else if (tenant_config->enable_auto_split) {
// check table
if (OB_FAIL(table_schema.enable_auto_partition(tenant_config->auto_split_tablet_size))) {
ObPartitionFuncType unused_part_func_type = PARTITION_FUNC_TYPE_MAX;// we can make sure that the part_expre is empty so enable_auto_partition will handle this situation
if (OB_FAIL(table_schema.enable_auto_partition(tenant_config->auto_split_tablet_size, unused_part_func_type))) {
LOG_WARN("fail to enable auto partition", KR(ret), K(table_schema));
} else if (OB_FAIL(table_schema.check_validity_for_auto_partition())) {
if (OB_NOT_SUPPORTED == ret) {

View File

@ -688,7 +688,8 @@ protected:
int resolve_auto_partition(ObPartitionedStmt *stmt, ParseNode *node,
ObTableSchema &table_schema);
int resolve_presetting_partition_key(ParseNode *node, share::schema::ObTableSchema &table_schema);
int try_set_auto_partition_by_config(common::ObIArray<obrpc::ObCreateIndexArg> &index_arg_list,
int try_set_auto_partition_by_config(const ParseNode *node,
common::ObIArray<obrpc::ObCreateIndexArg> &index_arg_list,
ObTableSchema &table_schema);
int check_only_modify_auto_partition_attr(ObPartitionedStmt *stmt, ParseNode *node,
ObTableSchema &table_schema, bool &is_only_modify_auto_part_attr);

View File

@ -270,7 +270,7 @@ int ObAlterAutoPartAttrOp::alter_table_auto_part_attr_if_need(
}
// enable auto split
if (OB_SUCC(ret)) {
if (OB_FAIL(table_schema.enable_auto_partition(alter_part_option.get_auto_part_size()))) {
if (OB_FAIL(table_schema.enable_auto_partition(alter_part_option.get_auto_part_size(), alter_part_option.get_part_func_type()))) {
LOG_WARN("fail to enable auto partition", K(ret), K(alter_part_option));
} else if (OB_FAIL(table_schema.check_enable_split_partition(true))) { // check origin table is satisfied auto partition conditions before enabled
LOG_WARN("fail to check validity for auto-partition", K(ret), K(table_schema));
@ -518,6 +518,7 @@ int ObAlterAutoPartAttrOp::extract_potential_partition_func_type(
ObPartitionFuncType &part_func_type)
{
int ret = OB_SUCCESS;
bool is_range_col = false;
if (part_func_expr.empty()) {
if (table_schema.is_index_table()) { // index table
ObArray<ObString> rowkey_columns;
@ -525,19 +526,23 @@ int ObAlterAutoPartAttrOp::extract_potential_partition_func_type(
LOG_WARN("fail to extract index rowkey column cnt", K(ret));
} else if (rowkey_columns.count() > 1) {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else if (OB_FAIL(table_schema.is_range_col_part_type(is_range_col))) {
LOG_WARN("fail to check is first part key range col", K(ret));
} else if (is_range_col) {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else {
part_func_type = PARTITION_FUNC_TYPE_RANGE;
// TODO: if partition key column type is double or float,
// partition func type should change to PARTITION_FUNC_TYPE_RANGE_COLUMNS later
}
} else if (table_schema.is_user_table()) { // user table
const ObRowkeyInfo &part_keys = table_schema.get_rowkey_info();
if (part_keys.get_size() > 1) {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else if (OB_FAIL(table_schema.is_range_col_part_type(is_range_col))) {
LOG_WARN("fail to check is first part key range col", K(ret));
} else if (is_range_col) {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else {
part_func_type = PARTITION_FUNC_TYPE_RANGE;
// TODO: if partition key column type is double or float,
// partition func type should change to PARTITION_FUNC_TYPE_RANGE_COLUMNS later
}
}
} else { // part_func_expr is not empty
@ -547,10 +552,12 @@ int ObAlterAutoPartAttrOp::extract_potential_partition_func_type(
LOG_WARN("fail to split func expr", K(ret), K(tmp_part_func_expr));
} else if (expr_strs.count() > 1) { // multi partition column
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else if (OB_FAIL(table_schema.is_range_col_part_type(is_range_col))) {
LOG_WARN("fail to check is first part key range col", K(ret));
} else if (is_range_col) {
part_func_type = PARTITION_FUNC_TYPE_RANGE_COLUMNS;
} else {
part_func_type = PARTITION_FUNC_TYPE_RANGE;
// TODO: if partition key column type is double or float,
// partition func type should change to PARTITION_FUNC_TYPE_RANGE_COLUMNS later
}
}
return ret;
@ -574,11 +581,11 @@ int ObAlterAutoPartAttrOp::update_global_auto_split_attr(
int ret = OB_SUCCESS;
bool enable_auto_split = alter_part_option.get_auto_part();
ObPartitionOption &new_index_option = new_index_schema.get_part_option();
ObPartitionFuncType part_func_type;
if (new_index_schema.get_part_level() == PARTITION_LEVEL_ZERO) {
if (enable_auto_split) {
if (new_index_option.get_part_func_expr_str().empty()) {
ObString empty_part_func_expr;
ObPartitionFuncType part_func_type;
if (OB_FAIL(extract_potential_partition_func_type(new_index_schema, empty_part_func_expr, part_func_type))) {
LOG_WARN("fail to extract partition func type", K(ret), K(new_index_schema));
}
@ -597,6 +604,8 @@ int ObAlterAutoPartAttrOp::update_global_auto_split_attr(
} else if (!new_index_schema.is_range_part()) {
// none range part table is not support, here we not set auto split attr
enable_auto_split = false;
} else {
part_func_type = new_index_option.get_part_func_type();
}
}
} else { // not support
@ -604,7 +613,7 @@ int ObAlterAutoPartAttrOp::update_global_auto_split_attr(
}
if (OB_SUCC(ret)) {
if (enable_auto_split) {
if (OB_FAIL(new_index_schema.enable_auto_partition(alter_part_option.get_auto_part_size()))) {
if (OB_FAIL(new_index_schema.enable_auto_partition(alter_part_option.get_auto_part_size(), part_func_type))) {
LOG_WARN("fail to enable auto partition", K(ret), K(alter_part_option));
}
} else {