@@ -1220,6 +1220,12 @@ func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent))
12201220 }
12211221 defer conn .Close ()
12221222
1223+ sessionQuery := "SET /* gh-ost */ SESSION time_zone = '+00:00'"
1224+ sessionQuery = fmt .Sprintf ("%s, %s" , sessionQuery , this .generateSqlModeQuery ())
1225+ if _ , err := conn .ExecContext (ctx , sessionQuery ); err != nil {
1226+ return err
1227+ }
1228+
12231229 tx , err := conn .BeginTx (ctx , nil )
12241230 if err != nil {
12251231 return err
@@ -1229,13 +1235,6 @@ func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent))
12291235 return err
12301236 }
12311237
1232- sessionQuery := "SET /* gh-ost */ SESSION time_zone = '+00:00'"
1233- sessionQuery = fmt .Sprintf ("%s, %s" , sessionQuery , this .generateSqlModeQuery ())
1234-
1235- if _ , err := tx .Exec (sessionQuery ); err != nil {
1236- return rollback (err )
1237- }
1238-
12391238 buildResults := make ([]* dmlBuildResult , 0 , len (dmlEvents ))
12401239 nArgs := 0
12411240 for _ , dmlEvent := range dmlEvents {
@@ -1248,6 +1247,9 @@ func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent))
12481247 }
12491248 }
12501249
1250+ // We batch together the DML queries into multi-statements to minimize network trips.
1251+ // We have to use the raw driver connection to access the rows affected
1252+ // for each statement in the multi-statement.
12511253 execErr := conn .Raw (func (driverConn any ) error {
12521254 ex := driverConn .(driver.ExecerContext )
12531255 nvc := driverConn .(driver.NamedValueChecker )
0 commit comments