Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mysql(ticdc): use string join to build multi statement sql. (#9936) #9938

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading