@@ -63,3 +63,29 @@ func (s *testPrepareSuite) TestPrepareCache(c *C) {
63
63
tk .MustQuery ("execute stmt5" ).Check (testkit .Rows ("1" , "2" , "2" , "3" , "4" , "5" ))
64
64
tk .MustQuery ("execute stmt5" ).Check (testkit .Rows ("1" , "2" , "2" , "3" , "4" , "5" ))
65
65
}
66
+
67
+ func (s * testPrepareSuite ) TestPrepareCacheIndexScan (c * C ) {
68
+ defer testleak .AfterTest (c )()
69
+ store , dom , err := newStoreWithBootstrap ()
70
+ c .Assert (err , IsNil )
71
+ tk := testkit .NewTestKit (c , store )
72
+ orgEnable := core .PreparedPlanCacheEnabled ()
73
+ orgCapacity := core .PreparedPlanCacheCapacity
74
+ defer func () {
75
+ dom .Close ()
76
+ store .Close ()
77
+ core .SetPreparedPlanCache (orgEnable )
78
+ core .PreparedPlanCacheCapacity = orgCapacity
79
+ }()
80
+ core .SetPreparedPlanCache (true )
81
+ core .PreparedPlanCacheCapacity = 100
82
+ tk .MustExec ("use test" )
83
+ tk .MustExec ("drop table if exists t" )
84
+ tk .MustExec ("create table t(a int, b int, c int, primary key (a, b))" )
85
+ tk .MustExec ("insert into t values(1, 1, 2), (1, 2, 3), (1, 3, 3), (2, 1, 2), (2, 2, 3), (2, 3, 3)" )
86
+ tk .MustExec (`prepare stmt1 from "select a, c from t where a = ? and c = ?"` )
87
+ tk .MustExec ("set @a=1, @b=3" )
88
+ // When executing one statement at the first time, we don't use cache, so we need to execute it at least twice to test the cache.
89
+ tk .MustQuery ("execute stmt1 using @a, @b" ).Check (testkit .Rows ("1 3" , "1 3" ))
90
+ tk .MustQuery ("execute stmt1 using @a, @b" ).Check (testkit .Rows ("1 3" , "1 3" ))
91
+ }
0 commit comments