Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

statstics,ddl: fix FK table forgets to send CreateTable event #53654

Merged
merged 2 commits into from
May 29, 2024
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
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