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

*: add trace support for the AllocAutoIncrementValue function #11158

Merged
merged 2 commits into from
Jul 10, 2019

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Jul 10, 2019

What problem does this PR solve?

AllocAutoIncrementValue may need to visit the network and be slow, add trace support for it.

mysql> create table xx (a int, b int key auto_increment);
Query OK, 0 rows affected (0.03 sec)
mysql> trace insert into xx (a) values (666);

For example, from the following image, we can see that dominant cost in InsertExec.Next is AllocAutoIncrementValue.

image

And AllocAutoIncrementValue is much faster after the first time it's been executed, because alloc would cache a batch of ids:

mysql> trace format='row' insert into xx (a) values (66);
+----------------------------------------+-----------------+------------+
| operation                              | startTS         | duration   |
+----------------------------------------+-----------------+------------+
| session.getTxnFuture                   | 11:08:11.924668 | 4.009µs    |
|   ├─session.Execute                    | 11:08:11.924660 | 940.11µs   |
|   ├─session.ParseSQL                   | 11:08:11.924717 | 33.085µs   |
|   ├─executor.Compile                   | 11:08:11.924775 | 80.327µs   |
|   ├─session.runStmt                    | 11:08:11.924876 | 669.409µs  |
|   ├─executor.handleNoDelayExecutor     | 11:08:11.924904 | 170.199µs  |
|   ├─*executor.InsertExec.Next          | 11:08:11.924913 | 142.591µs  |
|   ├─table.AllocAutoIncrementValue      | 11:08:11.924971 | 6.702µs    |
|   └─session.CommitTxn                  | 11:08:11.925113 | 396.121µs  |
+----------------------------------------+-----------------+------------+
9 rows in set (0.01 sec)

What is changed and how it works?

Add those lines to AllocAutoIncrementValue:

	if span := opentracing.SpanFromContext(ctx); span != nil && span.Tracer() != nil {
		span1 := span.Tracer().StartSpan("table.AllocAutoIncrementValue", opentracing.ChildOf(span.Context()))
		defer span1.Finish()
	}

Tiny refactor for the ctx parameter in AllocAutoIncrementValue.

Check List

Tests

  • Manual test (add detailed scripts or steps below)

Code changes

  • Has exported function/method change

AllocAutoIncrementValue may need to visit the network and be slow,
add trace for it
@tiancaiamao tiancaiamao added the type/enhancement The issue or PR belongs to an enhancement. label Jul 10, 2019
@tiancaiamao
Copy link
Contributor Author

PTAL @lysu @jackysp

@jackysp
Copy link
Member

jackysp commented Jul 10, 2019

Great!

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

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

LGTM

@tiancaiamao
Copy link
Contributor Author

/run-all-tests

@tiancaiamao
Copy link
Contributor Author

/run-unit-test

@tiancaiamao
Copy link
Contributor Author

PTAL @lysu

Copy link
Contributor

@lysu lysu left a comment

Choose a reason for hiding this comment

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

LGTM

@lysu lysu added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 10, 2019
@codecov
Copy link

codecov bot commented Jul 10, 2019

Codecov Report

Merging #11158 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11158   +/-   ##
===========================================
  Coverage   81.0651%   81.0651%           
===========================================
  Files           423        423           
  Lines         90051      90051           
===========================================
  Hits          73000      73000           
  Misses        11773      11773           
  Partials       5278       5278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

3 participants