From ace2eed16bb672f8aca6d6e767efc23907d99b99 Mon Sep 17 00:00:00 2001 From: Sanket Kedia Date: Wed, 15 Jul 2026 16:19:40 -0700 Subject: [PATCH] ddl: do not fill TiKV block cache for reorg coprocessor scans Reorg coprocessor scans (add index / add primary key backfill, and the table-max-handle probe) are single-pass bulk reads over the whole table/index range. The blocks they touch are never re-read by the reorg, so inserting them into the TiKV block cache yields no benefit while risking eviction of the working set that concurrent foreground traffic relies on. Set NotFillCache on the shared reorg DistSQLContext so all reorg coprocessor scans skip filling the block cache. The table-max-handle probe already set this flag directly; this makes the behavior consistent across every reorg coprocessor scan. Signed-off-by: Sanket Kedia --- pkg/ddl/backfilling_test.go | 11 +++++++++++ pkg/ddl/backfilling_txn_executor.go | 9 +++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/ddl/backfilling_test.go b/pkg/ddl/backfilling_test.go index 57275d962d5c6..e80b3e45359a1 100644 --- a/pkg/ddl/backfilling_test.go +++ b/pkg/ddl/backfilling_test.go @@ -404,6 +404,17 @@ func assertDistSQLCtxEqual(t *testing.T, expected *distsqlctx.DistSQLContext, ac require.Equal(t, errctx.NewContextWithLevels(expected.ErrCtx.LevelMap(), expected.WarnHandler), actual.ErrCtx) } +func TestReorgDistSQLCtxNotFillCache(t *testing.T) { + // Reorg coprocessor scans are single-pass bulk reads and must not pollute the TiKV + // block cache, so NotFillCache is always set on the reorg DistSQLContext. + ctx := newDefaultReorgDistSQLCtx(&mock.Client{}, contextutil.NewStaticWarnHandler(0)) + require.True(t, ctx.NotFillCache) + + withMeta, err := newReorgDistSQLCtxWithReorgMeta(&mock.Client{}, &model.DDLReorgMeta{}, contextutil.NewStaticWarnHandler(0)) + require.NoError(t, err) + require.True(t, withMeta.NotFillCache) +} + func TestValidateAndFillRanges(t *testing.T) { mkRange := func(start, end string) kv.KeyRange { return kv.KeyRange{StartKey: []byte(start), EndKey: []byte(end)} diff --git a/pkg/ddl/backfilling_txn_executor.go b/pkg/ddl/backfilling_txn_executor.go index f2a72e3fc1382..3622e27a13657 100644 --- a/pkg/ddl/backfilling_txn_executor.go +++ b/pkg/ddl/backfilling_txn_executor.go @@ -154,8 +154,13 @@ func newDefaultReorgDistSQLCtx(kvClient kv.Client, warnHandler contextutil.WarnA var execDetails execdetails.SyncExecDetails var cpuUsages ppcpuusage.SQLCPUUsages return &distsqlctx.DistSQLContext{ - WarnHandler: warnHandler, - Client: kvClient, + WarnHandler: warnHandler, + Client: kvClient, + // Reorg scans are single-pass bulk reads over the whole table/index range: the blocks + // they touch are never re-read by the reorg, so caching them brings no benefit and can + // evict the working set that concurrent foreground traffic relies on. Skip filling the + // block cache for all reorg coprocessor scans. + NotFillCache: true, EnableChunkRPC: true, EnabledRateLimitAction: vardef.DefTiDBEnableRateLimitAction, KVVars: tikvstore.NewVariables(&sqlKiller.Signal),