in pkg/datasource/sql/undo/builder/mysql_insert_undo_log_builder.go [141:184]
func (u *MySQLInsertUndoLogBuilder) getPkValues(execCtx *types.ExecContext, parseCtx *types.ParseContext, meta types.TableMeta) (map[string][]interface{}, error) {
pkColumnNameList := meta.GetPrimaryKeyOnlyName()
pkValuesMap := make(map[string][]interface{})
var err error
//when there is only one pk in the table
if len(pkColumnNameList) == 1 {
if u.containsPK(meta, parseCtx) {
// the insert sql contain pk value
pkValuesMap, err = u.getPkValuesByColumn(execCtx)
if err != nil {
return nil, err
}
} else if containsColumns(parseCtx) {
// the insert table pk auto generated
pkValuesMap, err = u.getPkValuesByAuto(execCtx)
if err != nil {
return nil, err
}
} else {
pkValuesMap, err = u.getPkValuesByColumn(execCtx)
if err != nil {
return nil, err
}
}
} else {
//when there is multiple pk in the table
//1,all pk columns are filled value.
//2,the auto increment pk column value is null, and other pk value are not null.
pkValuesMap, err = u.getPkValuesByColumn(execCtx)
if err != nil {
return nil, err
}
for _, columnName := range pkColumnNameList {
if _, ok := pkValuesMap[columnName]; !ok {
curPkValuesMap, err := u.getPkValuesByAuto(execCtx)
if err != nil {
return nil, err
}
pkValuesMapMerge(&pkValuesMap, curPkValuesMap)
}
}
}
return pkValuesMap, nil
}