Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 22 additions & 6 deletions common/persistence/sql/sqlplugin/mysql/execution_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,17 @@ func expandBatchInsertQuery(q string, rowCount int) string {
b.WriteString(q[valStartIdx:valEndIdx])
}

// sqlx does not like VALUES() and is generating an artifact into the sql code.
// Removing that while writing the second half of the query.
b.WriteString(q[valEndIdx:strings.LastIndex(q, ",")])
// sqlx does not like VALUES() and is generating an artifact
// into the sql query when we don't use a semicolon when we don't terminate with a `;`.
// Removing that while writing the second half of the query if it exists.
lastIdx := strings.LastIndex(q, ",")
if lastIdx == -1 || lastIdx <= valEndIdx{
b.WriteString(q[valEndIdx:])
} else {
b.WriteString(q[valEndIdx:lastIdx])
}


return b.String()
}

Expand Down Expand Up @@ -383,9 +391,10 @@ workflow_id = ? AND
run_id = ?
`

createSignalsRequestedSetQry = `INSERT IGNORE INTO signals_requested_sets
createSignalsRequestedSetQry = `INSERT INTO signals_requested_sets
(shard_id, namespace_id, workflow_id, run_id, signal_id) VALUES
(:shard_id, :namespace_id, :workflow_id, :run_id, :signal_id)`
(:shard_id, :namespace_id, :workflow_id, :run_id, :signal_id)
ON DUPLICATE KEY UPDATE signal_id=VALUES(signal_id);`

deleteSignalsRequestedSetQry = `DELETE FROM signals_requested_sets
WHERE
Expand All @@ -404,7 +413,14 @@ run_id = ?`

// InsertIntoSignalsRequestedSets inserts one or more rows into signals_requested_sets table
func (mdb *db) InsertIntoSignalsRequestedSets(rows []sqlplugin.SignalsRequestedSetsRow) (sql.Result, error) {
return mdb.conn.NamedExec(createSignalsRequestedSetQry, rows)
q, args, err := mdb.db.BindNamed(createSignalsRequestedSetQry, rows)
if err != nil {
return nil, err
}

q = expandBatchInsertQuery(q, len(rows))

return mdb.conn.Exec(q, args...)
}

// SelectFromSignalsRequestedSets reads one or more rows from signals_requested_sets table
Expand Down
7 changes: 5 additions & 2 deletions common/persistence/sql/sqlplugin/mysql/visibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,12 @@ import (
)

const (
templateCreateWorkflowExecutionStarted = `INSERT IGNORE INTO executions_visibility (` +
templateCreateWorkflowExecutionStarted = `INSERT INTO executions_visibility (` +
`namespace_id, workflow_id, run_id, start_time, execution_time, workflow_type_name, status, memo, encoding) ` +
`VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
`VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ` +
`ON DUPLICATE KEY UPDATE ` +
`run_id=VALUES(run_id)`


templateCreateWorkflowExecutionClosed = `INSERT INTO executions_visibility (` +
`namespace_id, workflow_id, run_id, start_time, execution_time, workflow_type_name, close_time, status, history_length, memo, encoding) ` +
Expand Down