(t *testing.T, prepFunc func(tk *testkit.TestKit), queryFunc func(isNonPrep bool) []string)
| 846 | } |
| 847 | |
| 848 | func testRandomPlanCacheCases(t *testing.T, |
| 849 | prepFunc func(tk *testkit.TestKit), |
| 850 | queryFunc func(isNonPrep bool) []string) { |
| 851 | store := testkit.CreateMockStore(t) |
| 852 | tk := testkit.NewTestKit(t, store) |
| 853 | prepFunc(tk) |
| 854 | |
| 855 | // prepared plan cache |
| 856 | for _, q := range queryFunc(true) { |
| 857 | tk.MustExec("set tidb_enable_non_prepared_plan_cache=0") |
| 858 | result1 := tk.MustQuery(q).Sort() |
| 859 | tk.MustExec("set tidb_enable_non_prepared_plan_cache=1") |
| 860 | result2 := tk.MustQuery(q).Sort() |
| 861 | require.True(t, result1.Equal(result2.Rows())) |
| 862 | } |
| 863 | |
| 864 | // non prepared plan cache |
| 865 | for _, q := range queryFunc(false) { |
| 866 | q, prepStmt, parameters := convertQueryToPrepExecStmt(q) |
| 867 | result1 := tk.MustQuery(q).Sort() |
| 868 | tk.MustExec(prepStmt) |
| 869 | var xs []string |
| 870 | for i, p := range parameters { |
| 871 | tk.MustExec(fmt.Sprintf("set @x%d = %s", i, p)) |
| 872 | xs = append(xs, fmt.Sprintf("@x%d", i)) |
| 873 | } |
| 874 | var execStmt string |
| 875 | if len(xs) == 0 { |
| 876 | execStmt = "execute st" |
| 877 | } else { |
| 878 | execStmt = fmt.Sprintf("execute st using %s", strings.Join(xs, ", ")) |
| 879 | } |
| 880 | result2 := tk.MustQuery(execStmt).Sort() |
| 881 | require.True(t, result1.Equal(result2.Rows())) |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | func TestPlanCacheSubquerySPMEffective(t *testing.T) { |
| 886 | store := testkit.CreateMockStore(t) |
no test coverage detected