docs/agents/ddl/03-reorg-backfill.md
Many DDLs are not “metadata-only”. They require scanning existing data and writing new data structures (indexes, column rewrites, partition changes, …). TiDB calls this phase reorganization (“reorg” / backfill).
Typical examples:
Deep dive:
docs/agents/ddl/06-add-index.mddocs/agents/ddl/07-modify-column.mddocs/agents/ddl/08-partition-ddl.mdThese jobs usually enter the schema state reorg, where:
High-level hooks:
pkg/ddl/job_worker.go (runOneJobStep, transitOneJobStep)pkg/ddl/reorg.go, pkg/ddl/reorg_util.gopkg/ddl/job_scheduler.go creates a dedicated reorg worker pool (see reorgCnt sizing logic).The key requirement is resumability:
TiDB supports distributing backfill work using the dist-task framework (especially for large backfills).
Anchors:
pkg/ddl/ddl.go:NewDDL via taskexecutor.RegisterTaskType(proto.Backfill, ...) and scheduler factories.docs/design/2022-09-19-distributed-ddl-reorg.mddocs/design/2023-04-11-dist-task.mdWhen reading code, treat this as an extension of the same DDL job lifecycle:
For some workloads, backfill can be accelerated using ingest/Lightning-based pipelines.
Anchors:
pkg/ddl/ingest/*docs/design/2022-06-07-adding-index-acceleration.mdWhen touching ingest paths, be extra careful about:
When you change reorg/backfill code, always verify:
If the change is large or introduces a new reorg mode, prefer adding a short design doc under docs/design/ and link it from docs/agents/ddl/README.md.