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

parser,ast: parse admin show slow statement #7688

Merged
merged 4 commits into from
Sep 26, 2018

Conversation

tiancaiamao
Copy link
Contributor

@tiancaiamao tiancaiamao commented Sep 13, 2018

What problem does this PR solve?

Add the following new syntax:

  • admin show slow top [internal | all] N
  • admin show slow recent N

I expect to use it like this:

mysql> admin show log top 3;
+-------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+-----------+----------+
| SQL                                 | START                      | DURATION | DETAILS                                                                                              | SUCC | CONN_ID | TXNTS              | USER           | DB   | TABLE_IDS       | INDEX_IDS | INTERNAL |
+-------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+-----------+----------+
| select sleep(2)                     | 2018-09-13 14:18:39.723710 | 00:00:02 |                                                                                                      |    1 |       1 | 402868016168042497 | root@127.0.0.1 | test |                 |           |        1 |
| select count(*) from t limit 330000 | 2018-09-13 14:20:38.970281 | 00:00:08 | process_time:1m0.665s wait_time:28.216s request_count:14 total_keys:20000014 processed_keys:20000000 |    1 |       1 | 402868047428714497 | root@127.0.0.1 | test | table_ids:[32], |           |        1 |
| select count(*) from t              | 2018-09-13 14:17:45.066304 | 00:00:09 | process_time:1m5.771s wait_time:31.32s request_count:14 total_keys:20000014 processed_keys:20000000  |    1 |       1 | 402868001842397185 | root@127.0.0.1 | test | table_ids:[32], |           |        1 |
+-------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+-----------+----------+
3 rows in set (0.00 sec)
mysql> admin show log recent 3;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+----------------+----------+
| SQL                                                                                                                                                                               | START                      | DURATION | DETAILS                                                                                              | SUCC | CONN_ID | TXNTS              | USER           | DB   | TABLE_IDS       | INDEX_IDS      | INTERNAL |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+----------------+----------+
| select count(*) from t limit 110000                                                                                                                                               | 2018-09-13 14:20:55.715194 | 00:00:09 | process_time:1m6.188s wait_time:30.196s request_count:14 total_keys:20000014 processed_keys:20000000 |    1 |       1 | 402868051819626497 | root@127.0.0.1 | test | table_ids:[32], |                |        1 |
| SELECT version, table_id, modify_count, count from mysql.stats_meta where version > 400040410672791554 order by version                                                           | 2018-09-13 14:20:57.148856 | 00:00:03 | wait_time:3.884s request_count:2 total_keys:266 processed_keys:144                                   |    1 |       0 | 402868052199735298 |                |      | table_ids:[19], | index_ids:[1], |        0 |
| select variable_name, variable_value from mysql.global_variables where variable_name in ('tidb_auto_analyze_ratio', 'tidb_auto_analyze_start_time', 'tidb_auto_analyze_end_time') | 2018-09-13 14:20:57.148658 | 00:00:03 | wait_time:3.884s request_count:1 total_keys:3                                                        |    1 |       0 | 402868052199735297 |                |      | table_ids:[13], | index_ids:[1], |        0 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+----------------+----------+
3 rows in set (0.00 sec)

What is changed and how it works?

Update parser.y

Check List

  • Unit test

Related changes

  • Need to update the documentation

PTAL @winkyao @coocood

Add the following new syntax:
* admin show log top [user | internal | all] N
* admin show log recent N
parser/parser.y Outdated
@@ -3606,6 +3611,10 @@ FunctionCallNonKeyword:
Args: []ast.ExprNode{ast.NewValueExpr($3), $5},
}
}
| "LOG" '(' ExpressionListOpt ')'
Copy link
Member

Choose a reason for hiding this comment

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

Why add this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After this PR, "LOG" change to a token from an identifier, it's a not keyword token.
There is no rule for builtin function "select log(...)" , so I add this rule.

parser/parser.y Outdated
@@ -5221,6 +5230,53 @@ AdminStmt:
JobIDs: $6.([]int64),
}
}
| "ADMIN" "SHOW" "LOG" AdminShowLog
Copy link
Member

Choose a reason for hiding this comment

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

"LOG" is too general, "SLOW_QUERY" is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@winkyao What's your opinion ?

Copy link
Member

Choose a reason for hiding this comment

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

I vote for the slow query.

Copy link
Contributor

Choose a reason for hiding this comment

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

Support for using "LOG" .

Copy link
Contributor

Choose a reason for hiding this comment

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

How about ADMIN SHOW SLOW? I agree that log is too generic, but with slow it could be implied.

}

AdminShowLog:
"RECENT" NUM
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the RECENT and make the NUM optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There will be two containers, one heap for TopN , one queue for Recent.
Suggested by @shenli

Copy link
Member

Choose a reason for hiding this comment

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

No "TOP" means recent.

Copy link
Member

Choose a reason for hiding this comment

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

TOP doesn't mean recent. It means order by x limit n.

parser/parser.y Outdated
Count: getUint64FromNUM($2),
}
}
| "TOP" "USER" NUM
Copy link
Member

Choose a reason for hiding this comment

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

"USER" can be removed, default only show "USER"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

Count: getUint64FromNUM($3),
}
}
| "TOP" "INTERNAL" NUM
Copy link
Member

Choose a reason for hiding this comment

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

This syntax can be removed, use ALL is enough.

Copy link
Member

Choose a reason for hiding this comment

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

Or Keep this and remove "ALL"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How to represent the result "user" + "internal" ?
We have three cases:

  • "user"
  • "internal"
  • "user" + "internal"

one keyword is not enough

@shenli
Copy link
Member

shenli commented Sep 13, 2018

Admin show slow query .... is more readable.

@shenli
Copy link
Member

shenli commented Sep 13, 2018

  1. The value in TABLE_IDS and INDEX_IDS do not have to contain table_ids: and index_ids: as prefixes.
  2. s/TXNTS/Transaction_TS/
mysql> admin show log recent 3;
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+----------------+----------+
| SQL                                                                                                                                                                               | START                      | DURATION | DETAILS                                                                                              | SUCC | CONN_ID | TXNTS              | USER           | DB   | TABLE_IDS       | INDEX_IDS      | INTERNAL |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+----------------+----------+
| select count(*) from t limit 110000                                                                                                                                               | 2018-09-13 14:20:55.715194 | 00:00:09 | process_time:1m6.188s wait_time:30.196s request_count:14 total_keys:20000014 processed_keys:20000000 |    1 |       1 | 402868051819626497 | root@127.0.0.1 | test | table_ids:[32], |                |        1 |
| SELECT version, table_id, modify_count, count from mysql.stats_meta where version > 400040410672791554 order by version                                                           | 2018-09-13 14:20:57.148856 | 00:00:03 | wait_time:3.884s request_count:2 total_keys:266 processed_keys:144                                   |    1 |       0 | 402868052199735298 |                |      | table_ids:[19], | index_ids:[1], |        0 |
| select variable_name, variable_value from mysql.global_variables where variable_name in ('tidb_auto_analyze_ratio', 'tidb_auto_analyze_start_time', 'tidb_auto_analyze_end_time') | 2018-09-13 14:20:57.148658 | 00:00:03 | wait_time:3.884s request_count:1 total_keys:3                                                        |    1 |       0 | 402868052199735297 |                |      | table_ids:[13], | index_ids:[1], |        0 |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------------+----------+------------------------------------------------------------------------------------------------------+------+---------+--------------------+----------------+------+-----------------+----------------+----------+
3 rows in set (0.00 sec)

@tiancaiamao
Copy link
Contributor Author

PTAL @coocood @shenli

1 similar comment
@tiancaiamao
Copy link
Contributor Author

PTAL @coocood @shenli

ast/misc.go Outdated
type ShowSlow struct {
Tp ShowSlowType
Count uint64
// May be "internal" or "all", default is ""
Copy link
Contributor

Choose a reason for hiding this comment

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

what about only showing general type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by "general" type? is that "user + internal"?
"user" == "" (the default)
"user + internal" == "all"

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some comment to explain what "user" is, and the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've defined a ShowSlowKind type, instead of using string. @winkyao @crazycs520

@tiancaiamao tiancaiamao changed the title parser,ast: parse admin show log statement parser,ast: parse admin show slow statement Sep 26, 2018
@tiancaiamao tiancaiamao added the priority/release-blocker This issue blocks a release. Please solve it ASAP. label Sep 26, 2018
@coocood
Copy link
Member

coocood commented Sep 26, 2018

LGTM

parser/parser.y Outdated
{
$$ = &ast.ShowSlow{
Tp: ast.ShowSlowTop,
Kind: "internal",
Copy link
Contributor

Choose a reason for hiding this comment

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

How about define a const : KindInternal, KindAll, KindDefault ?

parser/parser.y Outdated
{
$$ = &ast.ShowSlow{
Tp: ast.ShowSlowTop,
Kind: "all",
Copy link
Contributor

Choose a reason for hiding this comment

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

dito

Copy link
Contributor

@crazycs520 crazycs520 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

/run-all-tests

@crazycs520 crazycs520 added the status/LGT2 Indicates that a PR has LGTM 2. label Sep 26, 2018
@tiancaiamao
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@zhexuany zhexuany 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 tiancaiamao merged commit b098b47 into pingcap:master Sep 26, 2018
@tiancaiamao tiancaiamao deleted the parse-admin-show-log branch September 26, 2018 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/parser priority/release-blocker This issue blocks a release. Please solve it ASAP. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants