thunguo commented on code in PR #1133:
URL:
https://github.com/apache/incubator-seata-go/pull/1133#discussion_r3541126869
##########
pkg/datasource/sql/undo/executor/mysql_undo_insert_executor.go:
##########
@@ -58,12 +58,15 @@ func (m *mySQLUndoInsertExecutor) ExecuteOn(ctx
context.Context, dbType types.DB
defer stmt.Close()
afterImage := m.sqlUndoLog.AfterImage
for _, row := range afterImage.Rows {
- pkValueList := make([]interface{}, 0)
+ pkList, err := util.GetOrderedPkList(afterImage, row, dbType)
+ if err != nil {
+ return err
Review Comment:
可以fmt.Errorf补充一下信息,方便定位问题
##########
pkg/datasource/sql/exec/at/insert_executor.go:
##########
@@ -363,18 +363,18 @@ func (i *insertExecutor) buildAfterImageSQL(ctx
context.Context) (string, []driv
rowSize := len(pkValuesMap[pkColumnNameList[0]])
for i := 0; i < rowSize; i++ {
+ var columns []types.ColumnImage
Review Comment:
这里可以预分配一下容量
##########
pkg/datasource/sql/undo/executor/utils.go:
##########
@@ -72,22 +72,24 @@ func rowListToMap(rows []types.RowImage, primaryKeyList
[]string) map[string]map
for _, row := range rows {
fieldMap := make(map[string]interface{}, 0)
var rowKey string
- var firstUnderline bool
+ pkValues := make(map[string]interface{})
Review Comment:
预分配容量
##########
pkg/datasource/sql/undo/executor/utils.go:
##########
@@ -72,22 +72,24 @@ func rowListToMap(rows []types.RowImage, primaryKeyList
[]string) map[string]map
for _, row := range rows {
fieldMap := make(map[string]interface{}, 0)
var rowKey string
- var firstUnderline bool
+ pkValues := make(map[string]interface{})
for _, column := range row.Columns {
cleanName := util.DelEscape(column.ColumnName,
types.DBTypeMySQL)
- for i, key := range primaryKeyList {
+ for _, key := range primaryKeyList {
if cleanName == key {
- if firstUnderline && i > 0 {
- rowKey += "_##$$_"
- }
- // todo make value more accurate
- rowKey = fmt.Sprintf("%v%v", rowKey,
column.GetActualValue())
- firstUnderline = true
+ pkValues[key] = column.GetActualValue()
}
}
fieldMap[strings.ToUpper(cleanName)] = column.Value
}
+
+ for i, key := range primaryKeyList {
+ if i > 0 {
+ rowKey += "_##$$_"
+ }
+ rowKey = fmt.Sprintf("%v%v", rowKey, pkValues[key])
Review Comment:
这里pkValues[key]可能是nil,可以补充下边界check,不然可能会拼出来_\<nil\>这种情况
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]