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

binlog: DML on temporary tables do not write binlog #24570

Merged
merged 8 commits into from
May 13, 2021
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
33 changes: 33 additions & 0 deletions sessionctx/binloginfo/binloginfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,36 @@ func testGetTableByName(c *C, ctx sessionctx.Context, db, table string) table.Ta
c.Assert(err, IsNil)
return tbl
}

func (s *testBinlogSuite) TestTempTableBinlog(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.Se.GetSessionVars().BinlogClient = s.client
tk.MustExec("begin")
tk.MustExec("drop table if exists temp_table")
ddlQuery := "create global temporary table temp_table(id int) on commit delete rows"
tk.MustExec(ddlQuery)
ok := mustGetDDLBinlog(s, ddlQuery, c)
c.Assert(ok, IsTrue)

tk.MustExec("insert temp_table value(1)")
tk.MustExec("update temp_table set id=id+1")
tk.MustExec("commit")
prewriteVal := getLatestBinlogPrewriteValue(c, s.pump)
c.Assert(len(prewriteVal.Mutations), Equals, 0)

tk.MustExec("begin")
tk.MustExec("delete from temp_table")
tk.MustExec("commit")
prewriteVal = getLatestBinlogPrewriteValue(c, s.pump)
c.Assert(len(prewriteVal.Mutations), Equals, 0)

ddlQuery = "truncate table temp_table"
tk.MustExec(ddlQuery)
ok = mustGetDDLBinlog(s, ddlQuery, c)
c.Assert(ok, IsTrue)

ddlQuery = "drop table if exists temp_table"
tk.MustExec(ddlQuery)
ok = mustGetDDLBinlog(s, ddlQuery, c)
c.Assert(ok, IsTrue)
}
3 changes: 3 additions & 0 deletions table/tables/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,9 @@ func shouldWriteBinlog(ctx sessionctx.Context, tblInfo *model.TableInfo) bool {
if ctx.GetSessionVars().BinlogClient == nil {
return false
}
if tblInfo.TempTableType != model.TempTableNone {
return false
}
return !ctx.GetSessionVars().InRestrictedSQL
}

Expand Down