Skip to content

Commit d51f6f0

Browse files
authored
ddl, meta: don't update tblInfo.UpdateTS for exchangePartition and truncatePartition (#59312)
close #59238
1 parent 4734c9c commit d51f6f0

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

pkg/ddl/table.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,7 @@ func adjustForeignKeyChildTableInfoAfterRenameTable(
927927
childFKInfo.RefTable = newTableName
928928
}
929929
for _, info := range fkh.loaded {
930-
err := updateTable(t, info.schemaID, info.tblInfo)
930+
err := updateTable(t, info.schemaID, info.tblInfo, false)
931931
if err != nil {
932932
return err
933933
}
@@ -1323,21 +1323,28 @@ func updateVersionAndTableInfo(jobCtx *jobContext, job *model.Job, tblInfo *mode
13231323
}
13241324
}
13251325

1326-
err = updateTable(jobCtx.metaMut, job.SchemaID, tblInfo)
1326+
needUpdateTs := tblInfo.State == model.StatePublic &&
1327+
job.Type != model.ActionTruncateTable &&
1328+
job.Type != model.ActionTruncateTablePartition &&
1329+
job.Type != model.ActionRenameTable &&
1330+
job.Type != model.ActionRenameTables &&
1331+
job.Type != model.ActionExchangeTablePartition
1332+
1333+
err = updateTable(jobCtx.metaMut, job.SchemaID, tblInfo, needUpdateTs)
13271334
if err != nil {
13281335
return 0, errors.Trace(err)
13291336
}
13301337
for _, info := range multiInfos {
1331-
err = updateTable(jobCtx.metaMut, info.schemaID, info.tblInfo)
1338+
err = updateTable(jobCtx.metaMut, info.schemaID, info.tblInfo, needUpdateTs)
13321339
if err != nil {
13331340
return 0, errors.Trace(err)
13341341
}
13351342
}
13361343
return ver, nil
13371344
}
13381345

1339-
func updateTable(t *meta.Mutator, schemaID int64, tblInfo *model.TableInfo) error {
1340-
if tblInfo.State == model.StatePublic {
1346+
func updateTable(t *meta.Mutator, schemaID int64, tblInfo *model.TableInfo, needUpdateTs bool) error {
1347+
if needUpdateTs {
13411348
tblInfo.UpdateTS = t.StartTS
13421349
}
13431350
return t.UpdateTable(schemaID, tblInfo)

pkg/ddl/table_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,24 @@ func TestCreateViewTwice(t *testing.T) {
815815
tk.MustExec("create view v as select * from t_raw")
816816
wg.Wait()
817817
}
818+
819+
func TestIssue59238(t *testing.T) {
820+
store := testkit.CreateMockStore(t)
821+
tk := testkit.NewTestKit(t, store)
822+
823+
tk.MustExec("use test")
824+
tk.MustExec("CREATE TABLE t ( a INT, b INT, INDEX idx(b))" +
825+
" PARTITION BY RANGE(a) (" +
826+
" PARTITION p1 VALUES LESS THAN (10000)," +
827+
" PARTITION p2 VALUES LESS THAN (20000)," +
828+
" PARTITION p3 VALUES LESS THAN (MAXVALUE))")
829+
830+
rs := tk.MustQuery("select distinct create_time from information_schema.partitions where table_name = 't'").String()
831+
832+
tk.MustExec("alter table t truncate partition p1")
833+
require.True(t, tk.MustQuery("select distinct create_time from information_schema.partitions where table_name = 't'").Equal(testkit.Rows(rs)))
834+
835+
tk.MustExec("create table t1 (a int, b int, index idx(b))")
836+
tk.MustExec("alter table t exchange partition p1 with table t1")
837+
require.True(t, tk.MustQuery("select distinct create_time from information_schema.partitions where table_name = 't'").Equal(testkit.Rows(rs)))
838+
}

pkg/meta/model/table.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ type TableInfo struct {
136136
MaxForeignKeyID int64 `json:"max_fk_id"`
137137
MaxConstraintID int64 `json:"max_cst_id"`
138138
// UpdateTS is used to record the timestamp of updating the table's schema information.
139-
// These changing schema operations don't include 'truncate table' and 'rename table'.
139+
// These changing schema operations don't include 'truncate table', 'rename table',
140+
// 'rename tables', 'truncate partition' and 'exchange partition'.
140141
UpdateTS uint64 `json:"update_timestamp"`
141142
// OldSchemaID :
142143
// Because auto increment ID has schemaID as prefix,

0 commit comments

Comments
 (0)