From d4fb9f93e07627f93c1ed50a463b43536ab98906 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 24 Dec 2024 16:12:45 +0200 Subject: [PATCH] simplify Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schemadiff/partitioning_analysis.go | 25 ++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/go/vt/schemadiff/partitioning_analysis.go b/go/vt/schemadiff/partitioning_analysis.go index 582a52dab63..205872b0f98 100644 --- a/go/vt/schemadiff/partitioning_analysis.go +++ b/go/vt/schemadiff/partitioning_analysis.go @@ -604,28 +604,25 @@ func TemporalRangePartitioningRetention(createTableEntity *CreateTableEntity, ex // We reject this operation. return nil, fmt.Errorf("retention at %s would drop all partitions in table %s", expireDatetime.Format(0), createTableEntity.Name()) } - if distinctDiffs { - for _, name := range droppedPartitionNames { - alterTable := &sqlparser.AlterTable{ - Table: createTableEntity.Table, - PartitionSpec: &sqlparser.PartitionSpec{ - Action: sqlparser.DropAction, - }, - } - alterTable.PartitionSpec.Names = append(alterTable.PartitionSpec.Names, name) - diff := &AlterTableEntityDiff{alterTable: alterTable, from: createTableEntity} - diffs = append(diffs, diff) - } - } else { + appendAlterTable := func(names sqlparser.Partitions) { alterTable := &sqlparser.AlterTable{ Table: createTableEntity.Table, PartitionSpec: &sqlparser.PartitionSpec{ Action: sqlparser.DropAction, + Names: names, }, } - alterTable.PartitionSpec.Names = droppedPartitionNames diff := &AlterTableEntityDiff{alterTable: alterTable, from: createTableEntity} diffs = append(diffs, diff) } + if distinctDiffs { + // Generate a separate ALTER TABLE for each partition to be dropped. + for _, name := range droppedPartitionNames { + appendAlterTable(sqlparser.Partitions{name}) + } + } else { + // Generate a single ALTER TABLE for all partitions to be dropped. + appendAlterTable(droppedPartitionNames) + } return diffs, nil }