Fix unexpected ddl stat sync from non-partitioned table to partitioned table

This commit is contained in:
Hongqin-Li 2024-03-25 07:46:41 +00:00 committed by ob-robot
parent 9e779a318b
commit 45d42b517c
2 changed files with 10 additions and 13 deletions

View File

@ -1669,7 +1669,7 @@ int ObDDLRedefinitionTask::sync_stats_info_in_same_tenant(common::ObMySQLTransac
LOG_WARN("error sys, root service must not be nullptr", K(ret));
} else if (OB_FAIL(trans.start(&root_service->get_sql_proxy(), dst_tenant_id_))) {
LOG_WARN("fail to start transaction", K(ret));
} else if (OB_FAIL(sync_table_level_stats_info(trans, data_table_schema, need_sync_history))) {
} else if (OB_FAIL(sync_table_level_stats_info(trans, data_table_schema, new_table_schema, need_sync_history))) {
LOG_WARN("fail to sync table level stats", K(ret));
} else if (DDL_ALTER_PARTITION_BY != task_type_
&& OB_FAIL(sync_partition_level_stats_info(trans,
@ -2004,6 +2004,7 @@ int ObDDLRedefinitionTask::sync_column_stats_info_accross_tenant(common::ObMySQL
int ObDDLRedefinitionTask::sync_table_level_stats_info(common::ObMySQLTransaction &trans,
const ObTableSchema &data_table_schema,
const ObTableSchema &new_table_schema,
const bool need_sync_history/*default true*/)
{
int ret = OB_SUCCESS;
@ -2011,13 +2012,9 @@ int ObDDLRedefinitionTask::sync_table_level_stats_info(common::ObMySQLTransactio
ObSqlString history_sql_string;
int64_t affected_rows = 0;
// for partitioned table, table-level stat is -1, for non-partitioned table, table-level stat is table id
int64_t partition_id = -1;
int64_t target_partition_id = -1;
int64_t partition_id = data_table_schema.is_partitioned_table() ? -1 : object_id_;
int64_t target_partition_id = new_table_schema.is_partitioned_table() ? -1 : target_object_id_;
const uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(dst_tenant_id_);
if (!data_table_schema.is_partitioned_table()) {
partition_id = object_id_;
target_partition_id = target_object_id_;
}
if (OB_FAIL(sql_string.assign_fmt("UPDATE %s SET table_id = %ld, partition_id = %ld"
" WHERE tenant_id = %ld and table_id = %ld and partition_id = %ld",
OB_ALL_TABLE_STAT_TNAME, target_object_id_, target_partition_id,
@ -2141,6 +2138,7 @@ int ObDDLRedefinitionTask::sync_column_level_stats_info(common::ObMySQLTransacti
} else if (!is_offline) {
if (OB_FAIL(sync_one_column_table_level_stats_info(trans,
data_table_schema,
new_table_schema,
col->get_column_id(),
new_col->get_column_id(),
need_sync_history))) {
@ -2162,6 +2160,7 @@ int ObDDLRedefinitionTask::sync_column_level_stats_info(common::ObMySQLTransacti
int ObDDLRedefinitionTask::sync_one_column_table_level_stats_info(common::ObMySQLTransaction &trans,
const ObTableSchema &data_table_schema,
const ObTableSchema &new_table_schema,
const uint64_t old_col_id,
const uint64_t new_col_id,
const bool need_sync_history/*default true*/)
@ -2173,13 +2172,9 @@ int ObDDLRedefinitionTask::sync_one_column_table_level_stats_info(common::ObMySQ
ObSqlString histogram_history_sql_string;
int64_t affected_rows = 0;
// for partitioned table, table-level stat is -1, for non-partitioned table, table-level stat is table id
int64_t partition_id = -1;
int64_t target_partition_id = -1;
int64_t partition_id = data_table_schema.is_partitioned_table() ? -1 : object_id_;
int64_t target_partition_id = new_table_schema.is_partitioned_table() ? -1 : target_object_id_;
const uint64_t exec_tenant_id = ObSchemaUtils::get_exec_tenant_id(dst_tenant_id_);
if (!data_table_schema.is_partitioned_table()) {
partition_id = object_id_;
target_partition_id = target_object_id_;
}
if (OB_FAIL(column_sql_string.assign_fmt("UPDATE %s SET table_id = %ld, partition_id = %ld, column_id = %ld"
" WHERE tenant_id = %ld and table_id = %ld and partition_id = %ld and column_id = %ld",
OB_ALL_COLUMN_STAT_TNAME, target_object_id_, target_partition_id, new_col_id,

View File

@ -211,6 +211,7 @@ protected:
int sync_table_level_stats_info(common::ObMySQLTransaction &trans,
const ObTableSchema &data_table_schema,
const ObTableSchema &new_table_schema,
const bool need_sync_history = true);
int sync_partition_level_stats_info(common::ObMySQLTransaction &trans,
const ObTableSchema &data_table_schema,
@ -223,6 +224,7 @@ protected:
const bool need_sync_history = true);
int sync_one_column_table_level_stats_info(common::ObMySQLTransaction &trans,
const ObTableSchema &data_table_schema,
const ObTableSchema &new_table_schema,
const uint64_t old_col_id,
const uint64_t new_col_id,
const bool need_sync_history = true);