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

Function preparedStmtPointGet

pkg/planner/core/plan_cache_partition_table_test.go:558–607  ·  view source on GitHub ↗
(t *testing.T, ids []any, tk *testkit.TestKit, testTbl partCoverStruct, seededRand *rand.Rand, rowData map[any]string, filler, currTest string, isCaseSensitive bool)

Source from the content-addressed store, hash-verified

556}
557
558func preparedStmtPointGet(t *testing.T, ids []any, tk *testkit.TestKit, testTbl partCoverStruct, seededRand *rand.Rand, rowData map[any]string, filler, currTest string, isCaseSensitive bool) {
559 allCols := []string{"a", "b", "c", "space(1)"}
560 seededRand.Shuffle(len(allCols), func(i, j int) {
561 allCols[i], allCols[j] = allCols[j], allCols[i]
562 })
563 cols := allCols[:seededRand.Intn(len(allCols)-1)+1]
564 // Test prepared statements
565 colStr := strings.Join(cols, ",")
566 queries := []string{"" +
567 "select " + colStr + " from t where a = ?",
568 // This uses an 'AccessCondition' for testing more
569 // code paths
570 "select " + colStr + " from t where a = ? and b is not null",
571 }
572 for i, q := range queries {
573 comment := fmt.Sprintf("/* %s, q:%d */", currTest, i)
574 id := ids[seededRand.Intn(len(ids))]
575 var idStr string
576 switch x := id.(type) {
577 case int:
578 idStr = strconv.Itoa(x)
579 case string:
580 idStr = "'" + x + "'"
581 default:
582 require.False(t, true, "Unsupported type")
583 }
584 tk.MustExec(`prepare stmt from '` + q + `' ` + comment)
585 tk.MustExec(`set @a := ` + idStr + " " + comment)
586 expect := getRowData(rowData, filler, cols, isCaseSensitive, id)
587 tk.MustQuery(`execute stmt using @a ` + comment).Check(testkit.Rows(expect...))
588 require.False(t, tk.Session().GetSessionVars().FoundInPlanCache)
589 id = ids[seededRand.Intn(len(ids))]
590 idStr = getIDStr(id)
591 tk.MustExec(`set @a := ` + idStr)
592 expect = getRowData(rowData, filler, cols, isCaseSensitive, id)
593 tk.MustQuery(`execute stmt using @a ` + comment).Check(testkit.Rows(expect...))
594 require.True(t, tk.Session().GetSessionVars().FoundInPlanCache)
595 tkProcess := tk.Session().ShowProcess()
596 ps := []*util.ProcessInfo{tkProcess}
597 tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps})
598 res := tk.MustQuery(fmt.Sprintf("explain for connection %d "+comment, tkProcess.ID))
599 if len(testTbl.pointGetExplain) > 0 {
600 res.MultiCheckContain(
601 append([]string{"Point_Get"}, testTbl.pointGetExplain...))
602 } else {
603 res.CheckNotContain("Point_Get")
604 }
605 tk.MustExec(`deallocate prepare stmt`)
606 }
607}
608
609func getRowData(rowData map[any]string, filler string, cols []string, isCaseSensitive bool, id ...any) []string {
610 maxRange := 2000000

Callers 1

testPartitionFullCoverFunction · 0.85

Calls 13

RowsFunction · 0.92
getIDStrFunction · 0.85
MultiCheckContainMethod · 0.80
CheckNotContainMethod · 0.80
getRowDataFunction · 0.70
JoinMethod · 0.65
CheckMethod · 0.65
GetSessionVarsMethod · 0.65
ShowProcessMethod · 0.65
SetSessionManagerMethod · 0.65
MustExecMethod · 0.45
MustQueryMethod · 0.45

Tested by

no test coverage detected