-
Notifications
You must be signed in to change notification settings - Fork 188
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL
} | ||
|
||
// genKeyList format keys. | ||
func genKeyList(table string, columns []*model.ColumnInfo, dataSeq []interface{}) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as
Line 414 in 256afb4
func genKeyList(table string, columns []*model.ColumnInfo, dataSeq []interface{}) string { |
|
||
// genMultipleKeys gens keys with UNIQUE NOT NULL value. | ||
// if not UNIQUE NOT NULL value, use table name instead. | ||
func genMultipleKeys(ti *model.TableInfo, value []interface{}, table string) []string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as
Line 435 in 256afb4
func genMultipleKeys(ti *model.TableInfo, value []interface{}, table string) []string { |
} | ||
|
||
// genWhere generates where condition. | ||
func (dml *DML) genWhere(buf *strings.Builder) []interface{} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactor from
Line 541 in 256afb4
func genWhere(buf *strings.Builder, columns []*model.ColumnInfo, data []interface{}) { |
I check the TiDB code, Another reason is that if update statement doesn't update index value, change it to Furthermore, if we are in safemode, I tested it before and it was in line with this conclusion |
in my memory REPLACE will also use batch get to get all rows before mutation https://github.com/pingcap/tidb/blob/94e30df8e2d8ba2a1a26f153f40067ba3acd78eb/executor/replace.go#L233 good to reduce index kv mutation 👍 seems ON DUPLICATE KEY UPDATE will use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rest lgtm
syncer/dml.go
Outdated
@@ -33,6 +33,7 @@ import ( | |||
// genDMLParam stores pruned columns, data as well as the original columns, data, index. | |||
type genDMLParam struct { | |||
tableID string // as a key in map like `schema`.`table` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to note this is target table ID (maybe in future PR)
syncer/dml.go
Outdated
sqls = append(sqls, sql) | ||
values = append(values, value) | ||
keys = append(keys, ks) | ||
dmls = append(dmls, newDML(insert, param.safeMode, param.tableID, param.sourceTable, nil, value, nil, originalValue, columns, ti)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
slightly recommend that if DML
struct will always stay same package with syncer, I think it's more readable that we use literal to create it. Like
DML{op: insert, ..., sourceTableInfo: ti}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So many args, so keep this function.
syncer/dml.go
Outdated
key := genKeyList(table, cols, vals) | ||
if len(key) > 0 { // ignore `null` value. | ||
multipleKeys = append(multipleKeys, key) | ||
// TODO: break here? one unique index is enough? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is added by me about one year ago, now it can be removed 😂
@@ -87,18 +84,15 @@ type job struct { | |||
|
|||
func (j *job) String() string { | |||
// only output some important information, maybe useful in execution. | |||
return fmt.Sprintf("tp: %s, sql: %s, args: %v, key: %s, ddls: %s, last_location: %s, start_location: %s, current_location: %s", j.tp, j.sql, j.args, j.key, j.ddls, j.location, j.startLocation, j.currentLocation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can we know the DML values in debug mode now?
/merge |
This pull request has been accepted and is ready to merge. Commit hash: 2ebdb46
|
In response to a cherrypick label: new pull request created: #2256. |
What problem does this PR solve?
refactor dml.go for later develop
INSERT ON DUPLICATE KEY UPDATE
instead ofREPLACE
in safemodeCheck List
Tests