Skip to content

Commit

Permalink
statstics,ddl: fix FK table forgets to send CreateTable event (#53654) (
Browse files Browse the repository at this point in the history
#53674)

close #53652
  • Loading branch information
ti-chi-bot authored May 31, 2024
1 parent 4afee51 commit 0086f44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ func createTableWithForeignKeys(d *ddlCtx, t *meta.Meta, job *model.Job, tbInfo
return ver, errors.Trace(err)
}
job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tbInfo)
asyncNotifyEvent(d, &util.Event{Tp: model.ActionCreateTable, TableInfo: tbInfo})
return ver, nil
default:
return ver, errors.Trace(dbterror.ErrInvalidDDLJob.GenWithStackByArgs("table", tbInfo.State))
Expand Down
24 changes: 24 additions & 0 deletions statistics/handle/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@ func TestDDLTable(t *testing.T) {
require.Nil(t, h.Update(is))
statsTbl = h.GetTableStats(tableInfo)
require.False(t, statsTbl.Pseudo)

// For FK table's CreateTable Event
// https://github.com/pingcap/tidb/issues/53652
testKit.MustExec("create table t_parent (id int primary key)")
is = do.InfoSchema()
tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t_parent"))
require.NoError(t, err)
tableInfo = tbl.Meta()
err = h.HandleDDLEvent(<-h.DDLEventCh())
require.NoError(t, err)
require.Nil(t, h.Update(is))
statsTbl = h.GetTableStats(tableInfo)
require.False(t, statsTbl.Pseudo)

testKit.MustExec("create table t_child (id int primary key, pid int, foreign key (pid) references t_parent(id) on delete cascade on update cascade);")
is = do.InfoSchema()
tbl, err = is.TableByName(model.NewCIStr("test"), model.NewCIStr("t_child"))
require.NoError(t, err)
tableInfo = tbl.Meta()
err = h.HandleDDLEvent(<-h.DDLEventCh())
require.NoError(t, err)
require.Nil(t, h.Update(is))
statsTbl = h.GetTableStats(tableInfo)
require.False(t, statsTbl.Pseudo)
}

func TestDDLHistogram(t *testing.T) {
Expand Down

0 comments on commit 0086f44

Please sign in to comment.