pingcap/tidb

planner: support explain and explain analyze statements for prepared queries

Open

#23,725 创建于 2021年3月31日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)Go (6,186 fork)batch import
good first issuesig/plannertype/enhancementtype/feature-request

仓库指标

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

描述

Feature Request

Is your feature request related to a problem? Please describe:

Explain and explain analyze statements can print query plans, which is useful when optimizing queries and investigating issues, but prepared queries cannot support this feature:

mysql> explain execute stmt using @a,@b,@c;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 26 near "using @a,@b,@c"

Describe the feature you'd like:

Support explain and explain analyze statements for prepared queries, for example:

mysql> explain execute stmt using @a,@b,@c;
+--------------------------+---------+-----------+---------------+---------------------------------------------------------+
| id                       | estRows | task      | access object | operator info                                           |
+--------------------------+---------+-----------+---------------+---------------------------------------------------------+
| TableReader_7            | 0.04    | root      |               | data:Selection_6                                        |
| └─Selection_6            | 0.04    | cop[tikv] |               | ge(test.ta.a, "a"), ge(test.ta.b, 2), le(test.ta.b, 10) |
|   └─TableRangeScan_5     | 1.67    | cop[tikv] | table:ta      | range:["a",+inf], keep order:false, stats:pseudo        |
+--------------------------+---------+-----------+---------------+---------------------------------------------------------+
3 rows in set (0.63 sec)

Describe alternatives you've considered:

To get plans of prepared statements, now we can use explain for {ConnID} or search them from slow log file, but both these two methods are not convenient.

Teachability, Documentation, Adoption, Migration Strategy:

贡献者指南