(t *testing.T, ids []any, tk *testkit.TestKit, testTbl partCoverStruct, seededRand *rand.Rand, rowData map[any]string, filler, currTest string, isCaseSensitive bool)
| 556 | } |
| 557 | |
| 558 | func 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 | |
| 609 | func getRowData(rowData map[any]string, filler string, cols []string, isCaseSensitive bool, id ...any) []string { |
| 610 | maxRange := 2000000 |
no test coverage detected