pingcap/tidb

Add performance diagnose rule to check useless prepare statement

Open

#18.743 aperta il 23 lug 2020

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)Go (6186 fork)batch import
feature/acceptedhelp wantedtype/feature-requesttype/usability

Metriche repository

Star
 (40.090 star)
Metriche merge PR
 (Merge medio 14g 4h) (346 PR mergiate in 30 g)

Descrizione

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:

Guida contributor