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

Function testRandomPlanCacheCases

pkg/planner/core/plan_cache_test.go:848–883  ·  view source on GitHub ↗
(t *testing.T,
	prepFunc func(tk *testkit.TestKit),
	queryFunc func(isNonPrep bool) []string)

Source from the content-addressed store, hash-verified

846}
847
848func 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
885func TestPlanCacheSubquerySPMEffective(t *testing.T) {
886 store := testkit.CreateMockStore(t)

Callers 1

TestPlanCacheRandomCasesFunction · 0.85

Calls 9

MustExecMethod · 0.95
MustQueryMethod · 0.95
CreateMockStoreFunction · 0.92
NewTestKitFunction · 0.92
SortMethod · 0.65
EqualMethod · 0.65
RowsMethod · 0.65
JoinMethod · 0.65

Tested by

no test coverage detected