Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for ALTER TABLE t REORGANIZE PARTITION p INTO (..) #6428

Merged
merged 10 commits into from
Feb 20, 2023
30 changes: 30 additions & 0 deletions dbms/src/Storages/Transaction/TiDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,40 @@ try

auto defs_json = json->getArray("definitions");
definitions.clear();
std::unordered_set<TableID> part_id_set;
for (size_t i = 0; i < defs_json->size(); i++)
{
PartitionDefinition definition(defs_json->getObject(i));
definitions.emplace_back(definition);
part_id_set.emplace(definition.id);
}

auto add_defs_json = json->getArray("adding_definitions");
if (!add_defs_json.isNull())
{
for (size_t i = 0; i < add_defs_json->size(); i++)
{
PartitionDefinition definition(add_defs_json->getObject(i));
if (part_id_set.count(definition.id) == 0)
{
definitions.emplace_back(definition);
part_id_set.emplace(definition.id);
}
}
}

auto drop_defs_json = json->getArray("dropping_definitions");
if (!drop_defs_json.isNull())
{
for (size_t i = 0; i < drop_defs_json->size(); i++)
{
PartitionDefinition definition(drop_defs_json->getObject(i));
if (part_id_set.count(definition.id) == 0)
{
definitions.emplace_back(definition);
part_id_set.emplace(definition.id);
}
}
}

num = json->getValue<UInt64>("num");
Expand Down
1 change: 1 addition & 0 deletions dbms/src/TiDB/Schema/SchemaBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ void SchemaBuilder<Getter, NameMapper>::applyDiff(const SchemaDiff & diff)
case SchemaActionType::AddTablePartition:
case SchemaActionType::DropTablePartition:
case SchemaActionType::TruncateTablePartition:
case SchemaActionType::AlterTableReorganizePartition:
{
applyPartitionDiff(db_info, diff.table_id);
break;
Expand Down
5 changes: 3 additions & 2 deletions dbms/src/TiDB/Schema/SchemaGetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@ enum class SchemaActionType : Int8
AlterNoCacheTable = 59,
CreateTables = 60,
ActionMultiSchemaChange = 61,
AlterTableReorganizePartition = 64,
mjonss marked this conversation as resolved.
Show resolved Hide resolved

// If we supporte new type from TiDB.
// If we support new type from TiDB.
// MaxRecognizedType also needs to be changed.
// It should always be equal to the maximum supported type + 1
MaxRecognizedType = 62,
MaxRecognizedType = 65,
};

struct AffectedOption
Expand Down