diff --git a/pkg/gluetidb/glue.go b/pkg/gluetidb/glue.go index f6378c6e9..6856b4e75 100644 --- a/pkg/gluetidb/glue.go +++ b/pkg/gluetidb/glue.go @@ -74,7 +74,26 @@ func (gs *tidbSession) CreateDatabase(ctx context.Context, schema *model.DBInfo) // CreateTable implements glue.Session func (gs *tidbSession) CreateTable(ctx context.Context, dbName model.CIStr, table *model.TableInfo) error { d := domain.GetDomain(gs.se).DDL() - return d.CreateTableWithInfo(gs.se, dbName, table.Clone(), ddl.OnExistIgnore, true) + + // remove all non-public indices (perhaps they shouldn't be backed up in the first place) + n := 0 + for _, index := range table.Indices { + if index.State == model.StatePublic { + table.Indices[n] = index + n++ + } + } + table.Indices = table.Indices[:n] + + // Clone() does not clone partitions yet :( + table = table.Clone() + if table.Partition != nil { + newPartition := *table.Partition + newPartition.Definitions = append([]model.PartitionDefinition{}, ...table.Partition.Definitions) + table.Partition = &newPartition + } + + return d.CreateTableWithInfo(gs.se, dbName, table, ddl.OnExistIgnore, true) } // Close implements glue.Session