Optimizer choose table full scan instead of point get when prepared plan cache enabled
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
```go
func TestExplainForConnDebug(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`set tidb_enable_prepared_plan_cache=1`)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (i varchar(20), j varchar(20), unique index (i))")
tk.MustExec("prepare stmt from 'select * from t where i >= ? and i <= ?'")
tk.MustExec("set @a='1'")
tk.MustExec("set @b='2'")
tk.MustExec("execute stmt using @a, @b")
tk.MustExec("execute stmt using @a, @b")
tk.MustExec("set @b='1'")
tk.MustExec("execute stmt using @a, @b")
tk.MustQuery(fmt.Sprintf("explain for connection %d", tk.Session().GetSessionVars().ConnectionID)).Check(testkit.Rows(""))
}
```
### 2. What did you expect to see? (Required)
```
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,2 @@
-[]
+[Point_Get_5 1.00 0 root table:t, index:i(i) time:0s, loops:0 N/A N/A]
```
### 3. What did you see instead (Required)
```
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,4 @@
-[]
+[TableReader_7 250.00 0 root time:0s, loops:0 data:Selection_6 N/A N/A]
+[└─Selection_6 250.00 0 cop[tikv] ge(test.t.i, "1"), le(test.t.i, "1") N/A N/A]
+[ └─TableFullScan_5 10000.00 0 cop[tikv] table:t keep order:false, stats:pseudo N/A N/A]
```
### 4. What is your TiDB version? (Required)
At least starting from v5.4.1
Contributor guide
Assessment
This issue has not been assessed yet.