(t *testing.T, tk *testkit.TestKit, isIndexMerge, hitCache bool, queryTemplate string, colTypes ...string)
| 1367 | } |
| 1368 | |
| 1369 | func verifyPlanCacheForMVIndex(t *testing.T, tk *testkit.TestKit, isIndexMerge, hitCache bool, queryTemplate string, colTypes ...string) { |
| 1370 | for i := 0; i < 5; i++ { |
| 1371 | var vals []string |
| 1372 | for _, colType := range colTypes { |
| 1373 | vals = append(vals, randValueForMVIndex(colType)) |
| 1374 | } |
| 1375 | |
| 1376 | query := queryTemplate |
| 1377 | var setStmt, usingStmt string |
| 1378 | for i, p := range vals { |
| 1379 | query = strings.Replace(query, "?", p, 1) |
| 1380 | if i > 0 { |
| 1381 | setStmt += ", " |
| 1382 | usingStmt += ", " |
| 1383 | } |
| 1384 | setStmt += fmt.Sprintf("@a%v=%v", i, p) |
| 1385 | usingStmt += fmt.Sprintf("@a%v", i) |
| 1386 | } |
| 1387 | result := tk.MustQuery(query).Sort() |
| 1388 | if isIndexMerge { |
| 1389 | tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning |
| 1390 | } |
| 1391 | tk.MustExec(fmt.Sprintf("set %v", setStmt)) |
| 1392 | tk.MustExec(fmt.Sprintf("prepare stmt from '%v'", queryTemplate)) |
| 1393 | if isIndexMerge { |
| 1394 | tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning |
| 1395 | } |
| 1396 | result1 := tk.MustQuery(fmt.Sprintf("execute stmt using %v", usingStmt)).Sort() |
| 1397 | result.Check(result1.Rows()) |
| 1398 | if isIndexMerge && hitCache { |
| 1399 | tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning |
| 1400 | } |
| 1401 | result2 := tk.MustQuery(fmt.Sprintf("execute stmt using %v", usingStmt)).Sort() |
| 1402 | result.Check(result2.Rows()) |
| 1403 | if isIndexMerge && hitCache { |
| 1404 | tk.MustQuery(`show warnings`).Check(testkit.Rows()) // no warning |
| 1405 | } |
| 1406 | result3 := tk.MustQuery(fmt.Sprintf("execute stmt using %v", usingStmt)).Sort() |
| 1407 | result.Check(result3.Rows()) |
| 1408 | if isIndexMerge && hitCache { |
| 1409 | tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("1")) // hit the cache |
| 1410 | } |
| 1411 | |
| 1412 | if isIndexMerge && hitCache { // check the plan |
| 1413 | result4 := tk.MustQuery(fmt.Sprintf("execute stmt using %v", usingStmt)).Sort() |
| 1414 | result.Check(result4.Rows()) |
| 1415 | tkProcess := tk.Session().ShowProcess() |
| 1416 | ps := []*util.ProcessInfo{tkProcess} |
| 1417 | tk.Session().SetSessionManager(&testkit.MockSessionManager{PS: ps}) |
| 1418 | rows := tk.MustQuery(fmt.Sprintf("explain for connection %d", tkProcess.ID)).Rows() |
| 1419 | haveIndexMerge := false |
| 1420 | for _, r := range rows { |
| 1421 | if strings.Contains(r[0].(string), "IndexMerge") { |
| 1422 | haveIndexMerge = true |
| 1423 | } |
| 1424 | } |
| 1425 | require.True(t, haveIndexMerge) // IndexMerge has to be used. |
| 1426 | } |
no test coverage detected