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

Created index for zipkin_annotations, so DEPENDENCIES can run faster #1471

Merged
merged 1 commit into from
Jan 4, 2017
Merged

Created index for zipkin_annotations, so DEPENDENCIES can run faster #1471

merged 1 commit into from
Jan 4, 2017

Conversation

josetesan
Copy link
Contributor

@josetesan josetesan commented Jan 4, 2017

Having 238460 rows inside zipkin_annotations, show this benefit :

BEFORE

mysql> explain SELECTtrace_id_high,trace_id,parent_id,id,a_key,endpoint_service_name` FROM (select distinct s.trace_id_high, s.trace_id, s.parent_id, s.id, a.a_key, a.endpoint_service_name from zipkin_spans s left outer join zipkin_annotations a on (s.trace_id = a.trace_id and s.id = a.span_id and a.a_key in ('ca', 'cs', 'sr', 'sa')) where s.start_ts between 1483401600000000 and 1483487999999999 group by s.trace_id_high, s.trace_id, s.id, a.a_key, a.endpoint_service_name) as link_spans;

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | PRIMARY | | ALL | NULL | NULL | NULL | NULL | 2529761520| |
| 2 | DERIVED | s | ALL | start_ts | NULL | NULL | NULL | 94380 | Using where; Using temporary |
| 2 | DERIVED | a | ALL | a_key | NULL | NULL | NULL | 236871 | Using where; Using join buffer (flat, BNL join) |
`

AFTER

mysql> explain SELECTtrace_id_high,trace_id,parent_id,id,a_key,endpoint_service_name` FROM (select distinct s.trace_id_high, s.trace_id, s.parent_id, s.id, a.a_key, a.endpoint_service_name from zipkin_spans s left outer join zipkin_annotations a on (s.trace_id = a.trace_id and s.id = a.span_id and a.a_key in ('ca', 'cs', 'sr', 'sa')) where s.start_ts between 1483401600000000 and 1483487999999999 group by s.trace_id_high, s.trace_id, s.id, a.a_key, a.endpoint_service_name) as link_spans;

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
| 1 | PRIMARY | | ALL | NULL | NULL | NULL | NULL | 47190 | |
| 2 | DERIVED | s | ALL | start_ts | NULL | NULL | NULL | 94380 | Using where; Using temporary |
| 2 | DERIVED | a | ref | a_key,akey | akey | 16 | zipkin.s.trace_id,zipkin.s.id | 1 | Using where |
`

As you can see, rows seeked went from 2529761520 to a mere 47190.

Having 238460 rows inside zipkin_annotations, show this benefit :

BEFORE
---
mysql> explain  SELECT `trace_id_high`,`trace_id`,`parent_id`,`id`,`a_key`,`endpoint_service_name` FROM (select distinct s.trace_id_high, s.trace_id, s.parent_id, s.id, a.a_key, a.endpoint_service_name from zipkin_spans s left outer join zipkin_annotations a on   (s.trace_id = a.trace_id and s.id = a.span_id and a.a_key in ('ca', 'cs', 'sr', 'sa')) where s.start_ts between 1483401600000000 and 1483487999999999 group by s.trace_id_high, s.trace_id, s.id, a.a_key, a.endpoint_service_name)  as link_spans;
+------+-------------+------------+------+---------------+------+---------+------+------------+-------------------------------------------------+
| id   | select_type | table      | type | possible_keys | key  | key_len | ref  | rows       | Extra                                           |
+------+-------------+------------+------+---------------+------+---------+------+------------+-------------------------------------------------+
|    1 | PRIMARY     | <derived2> | ALL  | NULL          | NULL | NULL    | NULL | 2529761520 |                                                 |
|    2 | DERIVED     | s          | ALL  | start_ts      | NULL | NULL    | NULL |      94380 | Using where; Using temporary                    |
|    2 | DERIVED     | a          | ALL  | a_key         | NULL | NULL    | NULL |     236871 | Using where; Using join buffer (flat, BNL join) |

AFTER
---
mysql> explain  SELECT `trace_id_high`,`trace_id`,`parent_id`,`id`,`a_key`,`endpoint_service_name` FROM (select distinct s.trace_id_high, s.trace_id, s.parent_id, s.id, a.a_key, a.endpoint_service_name from zipkin_spans s left outer join zipkin_annotations a on   (s.trace_id = a.trace_id and s.id = a.span_id and a.a_key in ('ca', 'cs', 'sr', 'sa')) where s.start_ts between 1483401600000000 and 1483487999999999 group by s.trace_id_high, s.trace_id, s.id, a.a_key, a.endpoint_service_name)  as link_spans;
+------+-------------+------------+------+---------------+------+---------+-------------------------------+-------+------------------------------+
| id   | select_type | table      | type | possible_keys | key  | key_len | ref                           | rows  | Extra                        |
+------+-------------+------------+------+---------------+------+---------+-------------------------------+-------+------------------------------+
|    1 | PRIMARY     | <derived2> | ALL  | NULL          | NULL | NULL    | NULL                          | 47190 |                              |
|    2 | DERIVED     | s          | ALL  | start_ts      | NULL | NULL    | NULL                          | 94380 | Using where; Using temporary |
|    2 | DERIVED     | a          | ref  | a_key,akey    | akey | 16      | zipkin.s.trace_id,zipkin.s.id |     1 | Using where                  |
+------+-------------+------------+------+---------------+------+---------+-------------------------------+-------+------------------------------+
@codefromthecrypt
Copy link
Member

Gracias, @josetesan y bravo!

@codefromthecrypt codefromthecrypt merged commit a129e3b into openzipkin:master Jan 4, 2017
@codefromthecrypt
Copy link
Member

@jcarres-mdsol fyi!

@jcarres-mdsol
Copy link
Contributor

Nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants