From 99e2a21014c8f0940fd10f8984a810277eff9b30 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 22 Feb 2024 16:52:57 +0800 Subject: [PATCH] ddl: fix the optimization for the empty table(speed up) (#49629) (#49815) close pingcap/tidb#49679, close pingcap/tidb#49682 --- ddl/backfilling.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ddl/backfilling.go b/ddl/backfilling.go index 0f77978e61e71..61edd6857a6c1 100644 --- a/ddl/backfilling.go +++ b/ddl/backfilling.go @@ -399,6 +399,11 @@ func splitTableRanges(t table.PhysicalTable, store kv.Storage, startKey, endKey zap.Int64("physicalTableID", t.GetPhysicalID()), zap.String("start key", hex.EncodeToString(startKey)), zap.String("end key", hex.EncodeToString(endKey))) + if len(startKey) == 0 && len(endKey) == 0 { + logutil.BgLogger().Info("split table range from PD, get noop table range", zap.String("category", "ddl"), zap.Int64("physicalTableID", t.GetPhysicalID())) + return []kv.KeyRange{}, nil + } + kvRange := kv.KeyRange{StartKey: startKey, EndKey: endKey} s, ok := store.(tikv.Storage) if !ok { @@ -685,9 +690,6 @@ func (dc *ddlCtx) writePhysicalTableRecord(sessPool *sess.Pool, t table.Physical if err := dc.isReorgRunnable(reorgInfo.Job.ID, false); err != nil { return errors.Trace(err) } - if startKey == nil && endKey == nil { - return nil - } failpoint.Inject("MockCaseWhenParseFailure", func(val failpoint.Value) { //nolint:forcetypeassert