MCPcopy
hub / github.com/pingcap/tidb / TestFixControl33031

Function TestFixControl33031

pkg/planner/core/plan_cache_partition_table_test.go:180–226  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

178}
179
180func TestFixControl33031(t *testing.T) {
181 store := testkit.CreateMockStore(t)
182 tk := testkit.NewTestKit(t, store)
183 tk.MustQuery(`select @@session.tidb_enable_prepared_plan_cache`).Check(testkit.Rows("1"))
184
185 tk.MustExec("use test")
186 tk.MustExec(`drop table if exists t`)
187 tk.MustExec(`CREATE TABLE t (a int primary key, b varchar(255), key (b)) PARTITION BY HASH (a) partitions 5`)
188 tk.MustExec(`insert into t values(0,0),(1,1),(2,2),(3,3),(4,4)`)
189 tk.MustExec(`insert into t select a + 5, b + 5 from t`)
190 tk.MustExec(`analyze table t`)
191
192 tk.MustExec(`prepare stmt from 'select * from t where a = ?'`)
193 tk.MustExec(`set @a = 2`)
194 tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("2 2"))
195 require.False(t, tk.Session().GetSessionVars().FoundInPlanCache)
196 tk.MustExec(`set @a = 3`)
197 tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("3 3"))
198 require.True(t, tk.Session().GetSessionVars().FoundInPlanCache)
199 tk.MustExec(`set @@tidb_opt_fix_control = "33031:ON"`)
200 tk.MustExec(`set @a = 1`)
201 tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("1 1"))
202 require.False(t, tk.Session().GetSessionVars().FoundInPlanCache)
203 tk.MustQuery(`show warnings`).Check(testkit.Rows("Warning 1105 skip plan-cache: plan rebuild failed, Fix33031 fix-control set and partitioned table in cached Point Get plan"))
204 tk.MustExec(`set @@tidb_opt_fix_control = "33031:OFF"`)
205 tk.MustExec(`set @a = 2`)
206 tk.MustQuery(`execute stmt using @a`).Check(testkit.Rows("2 2"))
207 require.True(t, tk.Session().GetSessionVars().FoundInPlanCache)
208 tk.MustExec(`deallocate prepare stmt`)
209
210 tk.MustExec(`prepare stmt from 'select * from t where a IN (?,?)'`)
211 tk.MustExec(`set @a = 2, @b = 5`)
212 tk.MustQuery(`execute stmt using @a, @b`).Sort().Check(testkit.Rows("2 2", "5 5"))
213 require.False(t, tk.Session().GetSessionVars().FoundInPlanCache)
214 tk.MustExec(`set @a = 3, @b = 0`)
215 tk.MustQuery(`execute stmt using @a, @b`).Sort().Check(testkit.Rows("0 0", "3 3"))
216 require.True(t, tk.Session().GetSessionVars().FoundInPlanCache)
217 tk.MustExec(`set @@tidb_opt_fix_control = "33031:ON"`)
218 tk.MustExec(`set @a = 1, @b = 2`)
219 tk.MustQuery(`execute stmt using @a, @b`).Check(testkit.Rows("1 1", "2 2"))
220 require.False(t, tk.Session().GetSessionVars().FoundInPlanCache)
221 tk.MustQuery(`show warnings`).Check(testkit.Rows("Warning 1105 skip plan-cache: plan rebuild failed, Fix33031 fix-control set and partitioned table in cached Batch Point Get plan"))
222 tk.MustExec(`set @@tidb_opt_fix_control = "33031:OFF"`)
223 tk.MustExec(`set @a = 2, @b = 3`)
224 tk.MustQuery(`execute stmt using @a, @b`).Check(testkit.Rows("2 2", "3 3"))
225 require.True(t, tk.Session().GetSessionVars().FoundInPlanCache)
226}
227
228func TestPlanCachePartitionDuplicates(t *testing.T) {
229 store := testkit.CreateMockStore(t)

Callers

nothing calls this directly

Calls 9

MustQueryMethod · 0.95
MustExecMethod · 0.95
SessionMethod · 0.95
CreateMockStoreFunction · 0.92
NewTestKitFunction · 0.92
RowsFunction · 0.92
CheckMethod · 0.65
GetSessionVarsMethod · 0.65
SortMethod · 0.65

Tested by

no test coverage detected