From e4ac90bc2fa108e856ea056e2949420d7a7694fe Mon Sep 17 00:00:00 2001 From: Ling Jin <7138436+3AceShowHand@users.noreply.github.com> Date: Fri, 20 Oct 2023 04:57:30 -0500 Subject: [PATCH] mysql(ticdc): use string join to build multi statement sql. (#9936) close pingcap/tiflow#9935 --- cdc/sink/dmlsink/txn/mysql/mysql.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cdc/sink/dmlsink/txn/mysql/mysql.go b/cdc/sink/dmlsink/txn/mysql/mysql.go index f0eb05709a2..447d1a00710 100644 --- a/cdc/sink/dmlsink/txn/mysql/mysql.go +++ b/cdc/sink/dmlsink/txn/mysql/mysql.go @@ -20,6 +20,7 @@ import ( "fmt" "math" "net/url" + "strings" "time" dmysql "github.com/go-sql-driver/mysql" @@ -651,20 +652,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(