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 performance diagnose rule to check useless prepare statement #18743

Open
crazycs520 opened this issue Jul 23, 2020 · 0 comments
Open

Add performance diagnose rule to check useless prepare statement #18743

crazycs520 opened this issue Jul 23, 2020 · 0 comments
Labels
feature/accepted This feature request is accepted by product managers help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/feature-request Categorizes issue or PR as related to a new feature. type/usability

Comments

@crazycs520
Copy link
Contributor

crazycs520 commented Jul 23, 2020

Feature Request

image

image

As you can see, the client try to use the prepared statement, but the prepare statement should only compile once.

If the client has to prepare again before each execution, actually the performance is worse than not use prepare.

This Issue wants to add a diagnose rule to auto find this problem by diagnose.

How to diagnose?

You can simply check the statement count of prepare and execute. Normally, the statement count of execute should much more than the statement count of prepare.

And you can use the metrics tables to get this information.

here is a SQL you can use to diagnose:

select t1.execute/t2.prepare > 10 from (select avg(value) as execute from tidb_ops_statement where type='Execute' and time>= '2020-07-23 17:30:00' and time < '2020-07-23 17:35:00') as t1,(select avg(value) as prepare from tidb_ops_statement where type='Prepare' and  time>= '2020-07-23 17:30:00' and time < '2020-07-23 17:35:00') as t2;
+----------------------------+
| t1.execute/t2.prepare > 10 |
+----------------------------+
| 0                          |
+----------------------------+

If the upper SQL returns 0, you can output a warning like:

The `Execute` statements count should much more than the `Prepare` statements count. otherwise, the performance may be worse than not use prepared statements.

Describe alternatives you've considered:

@crazycs520 crazycs520 added type/feature-request Categorizes issue or PR as related to a new feature. type/usability labels Jul 23, 2020
@crazycs520 crazycs520 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Jul 23, 2020
@zz-jason zz-jason added the feature/accepted This feature request is accepted by product managers label Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/accepted This feature request is accepted by product managers help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. type/feature-request Categorizes issue or PR as related to a new feature. type/usability
Projects
None yet
Development

No branches or pull requests

2 participants