pingcap / pingcap/tidb

the plans for SQLs containing user defined variables are cachable

Open
#44,546 2 comments 0 reactions 1 assignee Claimed by @qw4990 View on GitHub
epic/plan-cache sig/planner type/enhancement
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

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.