Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pkg/ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ func adjustForeignKeyChildTableInfoAfterRenameTable(
childFKInfo.RefTable = newTableName
}
for _, info := range fkh.loaded {
err := updateTable(t, info.schemaID, info.tblInfo)
err := updateTable(t, info.schemaID, info.tblInfo, false)
if err != nil {
return err
}
Expand Down Expand Up @@ -1323,21 +1323,28 @@ func updateVersionAndTableInfo(jobCtx *jobContext, job *model.Job, tblInfo *mode
}
}

err = updateTable(jobCtx.metaMut, job.SchemaID, tblInfo)
needUpdateTs := tblInfo.State == model.StatePublic &&
job.Type != model.ActionTruncateTable &&
job.Type != model.ActionTruncateTablePartition &&
job.Type != model.ActionRenameTable &&
job.Type != model.ActionRenameTables &&
job.Type != model.ActionExchangeTablePartition

err = updateTable(jobCtx.metaMut, job.SchemaID, tblInfo, needUpdateTs)
if err != nil {
return 0, errors.Trace(err)
}
for _, info := range multiInfos {
err = updateTable(jobCtx.metaMut, info.schemaID, info.tblInfo)
err = updateTable(jobCtx.metaMut, info.schemaID, info.tblInfo, needUpdateTs)
if err != nil {
return 0, errors.Trace(err)
}
}
return ver, nil
}

func updateTable(t *meta.Mutator, schemaID int64, tblInfo *model.TableInfo) error {
if tblInfo.State == model.StatePublic {
func updateTable(t *meta.Mutator, schemaID int64, tblInfo *model.TableInfo, needUpdateTs bool) error {
if needUpdateTs {
tblInfo.UpdateTS = t.StartTS
}
return t.UpdateTable(schemaID, tblInfo)
Expand Down
21 changes: 21 additions & 0 deletions pkg/ddl/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -815,3 +815,24 @@ func TestCreateViewTwice(t *testing.T) {
tk.MustExec("create view v as select * from t_raw")
wg.Wait()
}

func TestIssue59238(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)

tk.MustExec("use test")
tk.MustExec("CREATE TABLE t ( a INT, b INT, INDEX idx(b))" +
" PARTITION BY RANGE(a) (" +
" PARTITION p1 VALUES LESS THAN (10000)," +
" PARTITION p2 VALUES LESS THAN (20000)," +
" PARTITION p3 VALUES LESS THAN (MAXVALUE))")

rs := tk.MustQuery("select distinct create_time from information_schema.partitions where table_name = 't'").String()

tk.MustExec("alter table t truncate partition p1")
require.True(t, tk.MustQuery("select distinct create_time from information_schema.partitions where table_name = 't'").Equal(testkit.Rows(rs)))

tk.MustExec("create table t1 (a int, b int, index idx(b))")
tk.MustExec("alter table t exchange partition p1 with table t1")
require.True(t, tk.MustQuery("select distinct create_time from information_schema.partitions where table_name = 't'").Equal(testkit.Rows(rs)))
}
3 changes: 2 additions & 1 deletion pkg/meta/model/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ type TableInfo struct {
MaxForeignKeyID int64 `json:"max_fk_id"`
MaxConstraintID int64 `json:"max_cst_id"`
// UpdateTS is used to record the timestamp of updating the table's schema information.
// These changing schema operations don't include 'truncate table' and 'rename table'.
// These changing schema operations don't include 'truncate table', 'rename table',
// 'rename tables', 'truncate partition' and 'exchange partition'.
UpdateTS uint64 `json:"update_timestamp"`
// OldSchemaID :
// Because auto increment ID has schemaID as prefix,
Expand Down