Skip to content

Commit

Permalink
binlog: DML on temporary tables do not write binlog (#24570)
Browse files Browse the repository at this point in the history
  • Loading branch information
djshow832 committed May 13, 2021
1 parent 956149c commit f2c2fbd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit f2c2fbd

Please sign in to comment.