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
#53662)

close #53652
  • Loading branch information
ti-chi-bot authored May 30, 2024
1 parent 76a23fd commit b8a2b9e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ func createTableWithForeignKeys(d *ddlCtx, t *meta.Meta, job *model.Job, tbInfo
return ver, errors.Trace(err)
}
job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tbInfo)
createTableEvent := statsutil.NewCreateTableEvent(
job.SchemaID,
tbInfo,
)
asyncNotifyEvent(d, createTableEvent)
return ver, nil
default:
return ver, errors.Trace(dbterror.ErrInvalidDDLJob.GenWithStackByArgs("table", tbInfo.State))
Expand Down
24 changes: 24 additions & 0 deletions pkg/statistics/handle/ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 TestCreateASystemTable(t *testing.T) {
Expand Down

0 comments on commit b8a2b9e

Please sign in to comment.