the plans for SQLs containing user defined variables are cachable
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
In the current `cachableChecker`, the query contains an user defined variable is not cachable: https://github.com/pingcap/tidb/blob/master/planner/core/plan_cacheable_checker.go#L128-L131
```go
case *ast.VariableExpr:
checker.cacheable = false
checker.reason = "query has user-defined variables is un-cacheable"
return in, true
```
However, I don't know why it's not cachable. The user-defined variables are a `ScalarFunc` expression (`GetVarFunction`), and get the value at runtime, so it's definitely cachable (unless the planner has done some other things to make it a constant... I'm not familiar with planner so I'm not 100% confident).
The query contains a **system** variable is not cachable, because it's turned into `Constant` value in `(*expressionRewriter).rewriteVariable`
Contributor guide
Assessment
This issue has not been assessed yet.