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:

貢獻者指南