pingcap/tidb

Add performance diagnose rule to check useless prepare statement

Open

#18 743 ouverte le 23 juil. 2020

Voir sur GitHub
 (0 commentaires) (0 réactions) (0 assignés)Go (6 186 forks)batch import
feature/acceptedhelp wantedtype/feature-requesttype/usability

Métriques du dépôt

Stars
 (40 090 stars)
Métriques de merge PR
 (Merge moyen 14j 4h) (346 PRs mergées en 30 j)

Description

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:

Guide contributeur