pingcap/tidb
View on GitHubplanner: support explain and explain analyze statements for prepared queries
Open
#23,725 opened on Mar 31, 2021
good first issuesig/plannertype/enhancementtype/feature-request
Description
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: