Skip to content
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

executor: speed up replace into statement #7027

Merged
merged 11 commits into from
Jul 18, 2018
Merged

Conversation

jackysp
Copy link
Member

@jackysp jackysp commented Jul 10, 2018

What have you changed? (mandatory)

Speed up replace into statement.

What are the type of the changes (mandatory)?

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested (mandatory)?

Unit tests and manual tests.

Benchmark result if necessary (optional)

[17:13:29] yusp@ShuaipengdeMacBook-Pro ~/cluster
$ time mysql -uroot -P4000 -h127.0.0.1 --default-character-set utf8 -D test < replace.sql 

real	0m1.964s
user	0m0.023s
sys	0m0.015s
[17:13:40] yusp@ShuaipengdeMacBook-Pro ~/cluster
$ time mysql -uroot -P5000 -h127.0.0.1 --default-character-set utf8 -D test < replace.sql 

real	0m19.322s
user	0m0.025s
sys	0m0.020s

This pr(port 4000) is nearly 10x faster than master(port 5000).

PTAL @coocood @zimulala

@jackysp
Copy link
Member Author

jackysp commented Jul 10, 2018

/run-all-tests

@jackysp jackysp added the sig/execution SIG execution label Jul 10, 2018
@jackysp
Copy link
Member Author

jackysp commented Jul 10, 2018

/run-all-tests

@jackysp
Copy link
Member Author

jackysp commented Jul 10, 2018

/rebuild

@jackysp
Copy link
Member Author

jackysp commented Jul 11, 2018

/run-all-tests tidb-test=pr/570

@jackysp
Copy link
Member Author

jackysp commented Jul 11, 2018

/run-unit-test

if err != nil {
return errors.Trace(err)
}
err = e.Table.RemoveRecord(e.ctx, handle, oldRow)
Copy link
Member

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.

@@ -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) {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vote for getOldRow 😄

@@ -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 {
Copy link
Member

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.

@zz-jason
Copy link
Member

@jackysp PTAL the comments

@zz-jason zz-jason added the type/enhancement The issue or PR belongs to an enhancement. label Jul 12, 2018
@jackysp
Copy link
Member Author

jackysp commented Jul 12, 2018

PTAL @coocood @shenli @zz-jason

@zz-jason
Copy link
Member

LGTM

@zz-jason
Copy link
Member

/run-all-tests

@zz-jason zz-jason added status/LGT1 Indicates that a PR has LGTM 1. priority/P2 The issue has P2 priority. labels Jul 12, 2018
@jackysp
Copy link
Member Author

jackysp commented Jul 16, 2018

PTAL @coocood

}

for i, r := range e.toBeCheckedRows {
for {
Copy link
Member

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.

@jackysp
Copy link
Member Author

jackysp commented Jul 17, 2018

PTAL @coocood

@jackysp
Copy link
Member Author

jackysp commented Jul 17, 2018

PTAL @coocood

return h, nil
}

// replaceRow remove all duplicate rows for one row, then insert it.
Copy link
Contributor

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

@jackysp
Copy link
Member Author

jackysp commented Jul 18, 2018

PTAL @zimulala

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 18, 2018
@coocood
Copy link
Member

coocood commented Jul 18, 2018

/run-all-tests

@coocood
Copy link
Member

coocood commented Jul 18, 2018

LGTM

@coocood coocood merged commit 50193eb into pingcap:master Jul 18, 2018
@jackysp jackysp deleted the replace branch August 7, 2018 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/P2 The issue has P2 priority. sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants