Skip to content

Commit

Permalink
mysql(ticdc): use string join to build multi statement sql. (#9936) (#…
Browse files Browse the repository at this point in the history
…9937)

close #9935
  • Loading branch information
ti-chi-bot authored Oct 30, 2023
1 parent 6ba0aec commit 4439ae4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions cdc/sink/dmlsink/txn/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"math"
"net/url"
"strings"
"time"

dmysql "github.com/go-sql-driver/mysql"
Expand Down Expand Up @@ -655,20 +656,17 @@ func (s *mysqlBackend) prepareDMLs() *preparedDMLs {
func (s *mysqlBackend) multiStmtExecute(
ctx context.Context, dmls *preparedDMLs, tx *sql.Tx, writeTimeout time.Duration,
) error {
start := time.Now()
multiStmtSQL := ""
multiStmtArgs := []any{}
for i, query := range dmls.sqls {
multiStmtSQL += query
if i != len(dmls.sqls)-1 {
multiStmtSQL += ";"
}
multiStmtArgs = append(multiStmtArgs, dmls.values[i]...)
var multiStmtArgs []any
for _, value := range dmls.values {
multiStmtArgs = append(multiStmtArgs, value...)
}
multiStmtSQL := strings.Join(dmls.sqls, ";")

log.Debug("exec row", zap.Int("workerID", s.workerID),
zap.String("sql", multiStmtSQL), zap.Any("args", multiStmtArgs))
ctx, cancel := context.WithTimeout(ctx, writeTimeout)
defer cancel()
start := time.Now()
_, execError := tx.ExecContext(ctx, multiStmtSQL, multiStmtArgs...)
if execError != nil {
err := logDMLTxnErr(
Expand Down

0 comments on commit 4439ae4

Please sign in to comment.