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

Function TestLazyExecuteProjection

pkg/server/tests/cursor/cursor_test.go:312–372  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

310}
311
312func TestLazyExecuteProjection(t *testing.T) {
313 ts := servertestkit.CreateTidbTestSuite(t)
314
315 mysqldriver := &mysqlcursor.MySQLDriver{}
316 rawConn, err := mysqldriver.Open(ts.GetDSNWithCursor(10))
317 require.NoError(t, err)
318 conn := rawConn.(mysqlcursor.Connection)
319 defer conn.Close()
320
321 _, err = conn.ExecContext(context.Background(), "drop table if exists t1", nil)
322 require.NoError(t, err)
323 _, err = conn.ExecContext(context.Background(), "create table t1(id int primary key, v int)", nil)
324 require.NoError(t, err)
325 rowCount := 1000
326 for i := 0; i < rowCount; i++ {
327 _, err = conn.ExecContext(context.Background(), fmt.Sprintf("insert into t1 values(%d, %d)", i, i), nil)
328 require.NoError(t, err)
329 }
330
331 _, err = conn.ExecContext(context.Background(), "set tidb_enable_lazy_cursor_fetch = 'ON'", nil)
332 require.NoError(t, err)
333
334 require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/server/avoidEagerCursorFetch", "return"))
335 defer func() {
336 require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/server/avoidEagerCursorFetch"))
337 }()
338
339 // Normal execute. Simple table reader.
340 execTimes := 0
341outerLoop:
342 for execTimes < 50 {
343 execTimes++
344 rawStmt, err := conn.Prepare("select id + v from t1 order by id")
345 require.NoError(t, err)
346 stmt := rawStmt.(mysqlcursor.Statement)
347
348 // This query will return `rowCount` rows and use cursor fetch.
349 rows, err := stmt.QueryContext(context.Background(), nil)
350 require.NoError(t, err)
351
352 dest := make([]driver.Value, 1)
353 fetchRowCount := int64(0)
354
355 for {
356 // it'll send `FETCH` commands for every 10 rows.
357 err := rows.Next(dest)
358 if err != nil {
359 switch err {
360 case io.EOF:
361 require.Equal(t, int64(rowCount), fetchRowCount)
362 rows.Close()
363 break outerLoop
364 default:
365 require.NoError(t, err)
366 }
367 }
368 require.Equal(t, fetchRowCount*2, dest[0])
369 fetchRowCount++

Callers

nothing calls this directly

Calls 11

CreateTidbTestSuiteFunction · 0.92
GetDSNWithCursorMethod · 0.80
EnableMethod · 0.80
DisableMethod · 0.80
PrepareMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65
ExecContextMethod · 0.65
QueryContextMethod · 0.65
NextMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected