pingcap/tidb

Add performance diagnose rule to check useless prepare statement

Open

#18,743 创建于 2020年7月23日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)Go (6,186 fork)batch import
feature/acceptedhelp wantedtype/feature-requesttype/usability

仓库指标

Star
 (40,090 star)
PR 合并指标
 (平均合并 14天 4小时) (30 天内合并 346 个 PR)

描述

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:

贡献者指南