pingcap / pingcap/tidb

Accept User Variables in EXPLAIN FOR CONNECTION @connection_id

Open
#63,578 0 comments 0 reactions 0 assignees View on GitHub
type/feature-request
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Feature Request

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

TiDB can explain previously executed statements, including prepared statements, but `EXPLAIN FOR CONNECTION ` only accepts numbers, not a number inside a User Variable, so it is hard to do reproducable scripts and tests like:
```mysql
set @connid = connection_id();
execute prepStmt using @a, @b;
explain for connection @connid;
```

**Describe the feature you'd like:**

Accept a single User Variable containing a number, as well as a literal number in EXPLAIN FOR CONNECTION

**Describe alternatives you've considered:**

no direct.

**Teachability, Documentation, Adoption, Migration Strategy:**

It would also decrease the code used in test cases, like in TestPreparedNullParam:
```go
tkProcess := tk.Session().ShowProcess()
ps := []*sessmgr.ProcessInfo{tkProcess}
tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
tk.MustQuery(fmt.Sprintf("explain for connection %d", tkProcess.ID)).Check(testkit.Rows(
"TableDual_7 0.00 root rows:0"))
```
and could simply do `set @connid = connection_id()` and then use `@connid` instead.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.