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

infoschema,planner: implement the metric table predicate push down #14169

Merged
merged 23 commits into from
Dec 25, 2019

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

  • Implement the metric table predicate push down.
mysql>desc select * from up;
+----------------+----------+------+--------------------------------------------------------------------------------------------+
| id             | count    | task | operator info                                                                              |
+----------------+----------+------+--------------------------------------------------------------------------------------------+
| MemTableScan_4 | 10000.00 | root | PromQL:up{}, start_time:2019-12-20 22:26:13.47, end_time:2019-12-20 22:26:13.47, step:1m0s |
+----------------+----------+------+--------------------------------------------------------------------------------------------+
1 row in set
Time: 0.006s
mysql>desc select * from up where time > "2019-12-20 22:10:13"
+----------------+----------+------+------------------------------------------------------------------------------------------+
| id             | count    | task | operator info                                                                            |
+----------------+----------+------+------------------------------------------------------------------------------------------+
| MemTableScan_5 | 10000.00 | root | PromQL:up{}, start_time:2019-12-20 22:10:13, end_time:2019-12-20 22:26:28.558, step:1m0s |
+----------------+----------+------+------------------------------------------------------------------------------------------+
1 row in set
Time: 0.006s
mysql>desc select * from query_duration where `Quantile` = 0.8 and time > "2019-12-20 22:10:13"
+----------------+----------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id             | count    | task | operator info                                                                                                                                                                           |
+----------------+----------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| MemTableScan_5 | 10000.00 | root | PromQL:histogram_quantile(0.8, sum(rate(tidb_server_handle_query_duration_seconds_bucket{}[60s])) by (le)), start_time:2019-12-20 22:10:13, end_time:2019-12-20 22:26:39.944, step:1m0s |
+----------------+----------+------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set
Time: 0.009s
mysql>desc select * from query_duration where `Quantile` = 0.8 and instance="127.0.0.1:10080" and sql_type="general";
+----------------+----------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id             | count    | task | operator info                                                                                                                                                                                                                            |
+----------------+----------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| MemTableScan_5 | 10000.00 | root | PromQL:histogram_quantile(0.8, sum(rate(tidb_server_handle_query_duration_seconds_bucket{instance="127.0.0.1:10080",sql_type="general"}[60s])) by (le)), start_time:2019-12-20 22:27:06.407, end_time:2019-12-20 22:27:06.407, step:1m0s |
+----------------+----------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
mysql>select * from query_duration where `Quantile` = 0.8 and sql_type="internal" and time > "2019-12-20 22:10:13";
+---------------------+-------------------+----------+----------+----------+
| time                | value             | instance | sql_type | Quantile |
+---------------------+-------------------+----------+----------+----------+
| 2019-12-20 22:10:13 | 0.00126666666667  |          | internal | 0.8      |
| 2019-12-20 22:11:13 | 0.00136           |          | internal | 0.8      |
| 2019-12-20 22:13:13 | 0.001             |          | internal | 0.8      |
| 2019-12-20 22:14:13 | 0.00133333333333  |          | internal | 0.8      |
| 2019-12-20 22:15:13 | 0.0009            |          | internal | 0.8      |
| 2019-12-20 22:16:13 | 0.00133333333333  |          | internal | 0.8      |
| 2019-12-20 22:17:13 | 0.000961538461538 |          | internal | 0.8      |
| 2019-12-20 22:18:13 | 0.000957142857143 |          | internal | 0.8      |
| 2019-12-20 22:19:13 | 0.00166666666667  |          | internal | 0.8      |
| 2019-12-20 22:20:13 | 0.000928571428571 |          | internal | 0.8      |
| 2019-12-20 22:21:13 | 0.000928571428571 |          | internal | 0.8      |
| 2019-12-20 22:22:13 | 0.0016            |          | internal | 0.8      |
| 2019-12-20 22:27:13 | 0.0009            |          | internal | 0.8      |
| 2019-12-20 22:28:13 | 0.0014            |          | internal | 0.8      |
| 2019-12-20 22:29:13 | 0.000992307692308 |          | internal | 0.8      |
| 2019-12-20 22:30:13 | 0.000961538461538 |          | internal | 0.8      |
| 2019-12-20 22:31:13 | 0.000928571428571 |          | internal | 0.8      |
| 2019-12-20 22:32:13 | 0.000928571428571 |          | internal | 0.8      |
| 2019-12-20 22:33:13 | 0.0009            |          | internal | 0.8      |
| 2019-12-20 22:34:13 | 0.001             |          | internal | 0.8      |
| 2019-12-20 22:35:13 | 0.002             |          | internal | 0.8      |
| 2019-12-20 22:36:13 | 0.0009            |          | internal | 0.8      |
| 2019-12-20 22:37:13 | 0.000928571428571 |          | internal | 0.8      |
| 2019-12-20 22:38:13 | 0.0015            |          | internal | 0.8      |
| 2019-12-20 22:39:13 | 0.000992307692308 |          | internal | 0.8      |
| 2019-12-20 22:40:13 | 0.0015            |          | internal | 0.8      |
| 2019-12-20 22:41:13 | 0.001             |          | internal | 0.8      |
| 2019-12-20 22:42:13 | 0.000928571428571 |          | internal | 0.8      |
| 2019-12-20 22:43:13 | 0.00226666666667  |          | internal | 0.8      |
| 2019-12-20 22:44:13 | 0.001             |          | internal | 0.8      |
| 2019-12-20 22:45:13 | 0.000928571428571 |          | internal | 0.8      |
| 2019-12-20 22:46:13 | 0.0009            |          | internal | 0.8      |
+---------------------+-------------------+----------+----------+----------+
32 rows in set

What is changed and how it works?

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Code changes

  • Has exported function/method change

@crazycs520 crazycs520 requested a review from a team as a code owner December 20, 2019 14:51
@ghost ghost requested review from alivxxx and lzmhhh123 and removed request for a team December 20, 2019 14:51
planner/core/explain.go Outdated Show resolved Hide resolved

func (e *MetricTableExtractor) convertToTime(t int64) time.Time {
if t == 0 || t == math.MaxInt64 {
return time.Now()
Copy link
Contributor

Choose a reason for hiding this comment

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

What if startTime=0, endTime=now-1h?
You changed it to [now, now-1h].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but it will got error when query.

mysql>desc select * from query_duration where `Quantile` in ( 0.99) and sql_type="internal" and time < "2019-12-23 16:10:13" and instance="127.0.0.1:10080";
+----------------+----------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id             | count    | task | operator info                                                                                                                                                                                                                          |
+----------------+----------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| MemTableScan_5 | 10000.00 | root | PromQL:histogram_quantile(0.99, sum(rate(tidb_server_handle_query_duration_seconds_bucket{instance="127.0.0.1:10080",sql_type="internal"}[60s])) by (le)), start_time:2019-12-23 16:20:47.559, end_time:2019-12-23 16:10:12, step:1m0s |
+----------------+----------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set
Time: 0.009s
mysql>select * from query_duration where `Quantile` in ( 0.99) and sql_type="internal" and time < "2019-12-23 16:10:13" and instance="127.0.0.1:10080";
(1105, u'bad_data: end timestamp must not be before start time')

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, it shouldn't return an error.
When user queries [0, 16:10], you can change it to [13:40, 16:10], not [16:20, 16:10].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed. But When the user queries [0, 16:10], it will change it to [16:10, 16:10] now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, done

executor/metric_reader.go Outdated Show resolved Hide resolved
executor/metric_reader.go Outdated Show resolved Hide resolved
executor/metric_reader.go Outdated Show resolved Hide resolved
executor/metric_reader.go Outdated Show resolved Hide resolved
planner/core/explain.go Outdated Show resolved Hide resolved
planner/core/explain.go Outdated Show resolved Hide resolved
planner/core/explain.go Outdated Show resolved Hide resolved
planner/core/explain.go Outdated Show resolved Hide resolved
Copy link
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

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

Rest LGTM

@crazycs520
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@lonng lonng left a comment

Choose a reason for hiding this comment

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

LGTM

@crazycs520
Copy link
Contributor Author

/run-unit-test

Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

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

LGTM

@djshow832 djshow832 merged commit 279ad0d into pingcap:master Dec 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants