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
close #9935
  • Loading branch information
3AceShowHand authored Oct 20, 2023
1 parent a71208a commit e4ac90b
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 @@ -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(
Expand Down

0 comments on commit e4ac90b

Please sign in to comment.