-
Notifications
You must be signed in to change notification settings - Fork 6k
executor: speed up replace into statement #7027
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
Conversation
|
/run-all-tests |
|
/run-all-tests |
|
/rebuild |
|
/run-all-tests tidb-test=pr/570 |
|
/run-unit-test |
executor/replace.go
Outdated
| if err != nil { | ||
| return errors.Trace(err) | ||
| } | ||
| err = e.Table.RemoveRecord(e.ctx, handle, oldRow) |
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.
If the row is unchanged, we don't need to remove the row and insert it again.
executor/batch_checker.go
Outdated
| @@ -249,3 +249,29 @@ func (b *batchChecker) deleteDupKeys(row toBeCheckedRow) { | |||
| delete(b.dupKVs, string(uk.newKV.key)) | |||
| } | |||
| } | |||
|
|
|||
| // decodeOldRow decodes the table record row from storage for batch check. | |||
| func (b *batchChecker) decodeOldRow(ctx sessionctx.Context, t table.Table, handle int64) (types.DatumRow, error) { | |||
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.
s/decodeOldRow/getCurrentRow/ or getOldRow
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.
vote for getOldRow 😄
executor/replace.go
Outdated
| @@ -44,7 +46,51 @@ func (e *ReplaceExec) Open(ctx context.Context) error { | |||
| return nil | |||
| } | |||
|
|
|||
| func (e *ReplaceExec) exec(rows []types.DatumRow) error { | |||
| func (e *ReplaceExec) removeRow(handle int64, newRow types.DatumRow) error { | |||
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.
Add comments for removeRow and insertRow.
|
@jackysp PTAL the comments |
|
LGTM |
|
/run-all-tests |
|
PTAL @coocood |
executor/replace.go
Outdated
| } | ||
|
|
||
| for i, r := range e.toBeCheckedRows { | ||
| for { |
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.
Can we extract the inner for loop into its own function.
It's hard to see where the code is going to execute after break and continute.
|
PTAL @coocood |
|
PTAL @coocood |
executor/replace.go
Outdated
| return h, nil | ||
| } | ||
|
|
||
| // replaceRow remove all duplicate rows for one row, then insert it. |
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.
s/remove/removes
s/insert/inserts
|
PTAL @zimulala |
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 |
|
LGTM |
What have you changed? (mandatory)
Speed up
replace intostatement.What are the type of the changes (mandatory)?
How has this PR been tested (mandatory)?
Unit tests and manual tests.
Benchmark result if necessary (optional)
This pr(port 4000) is nearly 10x faster than master(port 5000).
PTAL @coocood @zimulala