Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: 加索引卡主,如何确认是什么原因呢?

【TiDB Usage Environment】Production Environment
【TiDB Version】5.0.2
【Encountered Problem: Phenomenon and Impact】
Executing the following DDL has been stuck for over 3 hours:
alter table tb_xxx add index idx_yyyy(commissioner_id, month_id, city_id);
During this period, the number of rows in the table decreased from around 20 million to about 10 million, and then slowly increased to around 19 million. This was caused by delete operations followed by insert operations.
The row_count
in admin show ddl jobs
has always been 0. Additionally, approximately every 20 minutes, the following type of log is output:
[2022/12/28 14:26:47.351 +08:00] [INFO] [ddl_worker.go:861] ["[ddl] wait latest schema version changed"] [worker="worker 2, tp add index"] [ver=3484] ["take time"=53.953994ms] [job="ID:4476, Type:add index, State:running, SchemaState:write reorganization, SchemaID:51, TableID:214, RowCount:0, ArgLen:0, start time: 2022-12-28 11:13:41.69 +0800 CST, Err:<nil>, ErrCount:0, SnapshotVersion:0"]
[2022/12/28 14:26:47.353 +08:00] [INFO] [ddl_worker.go:678] ["[ddl] run DDL job"] [worker="worker 2, tp add index"] [job="ID:4476, Type:add index, State:running, SchemaState:write reorganization, SchemaID:51, TableID:214, RowCount:0, ArgLen:0, start time: 2022-12-28 11:13:41.69 +0800 CST, Err:<nil>, ErrCount:0, SnapshotVersion:0"]
[2022/12/28 14:42:59.101 +08:00] [INFO] [ddl_worker.go:861] ["[ddl] wait latest schema version changed"] [worker="worker 2, tp add index"] [ver=3485] ["take time"=53.108472ms] [job="ID:4476, Type:add index, State:running, SchemaState:write reorganization, SchemaID:51, TableID:214, RowCount:0, ArgLen:0, start time: 2022-12-28 11:13:41.69 +0800 CST, Err:<nil>, ErrCount:0, SnapshotVersion:0"]
[2022/12/28 14:42:59.102 +08:00] [INFO] [ddl_worker.go:678] ["[ddl] run DDL job"] [worker="worker 2, tp add index"] [job="ID:4476, Type:add index, State:running, SchemaState:write reorganization, SchemaID:51, TableID:214, RowCount:0, ArgLen:0, start time: 2022-12-28 11:13:41.69 +0800 CST, Err:<nil>, ErrCount:0, SnapshotVersion:0"]
[2022/12/28 15:02:49.460 +08:00] [INFO] [ddl_worker.go:861] ["[ddl] wait latest schema version changed"] [worker="worker 2, tp add index"] [ver=3486] ["take time"=53.689792ms] [job="ID:4476, Type:add index, State:running, SchemaState:write reorganization, SchemaID:51, TableID:214, RowCount:0, ArgLen:0, start time: 2022-12-28 11:13:41.69 +0800 CST, Err:<nil>, ErrCount:0, SnapshotVersion:0"]
[2022/12/28 15:02:49.461 +08:00] [INFO] [ddl_worker.go:678] ["[ddl] run DDL job"] [worker="worker 2, tp add index"] [job="ID:4476, Type:add index, State:running, SchemaState:write reorganization, SchemaID:51, TableID:214, RowCount:0, ArgLen:0, start time: 2022-12-28 11:13:41.69 +0800 CST, Err:<nil>, ErrCount:0, SnapshotVersion:0"]
What is the reason for the slow execution of this DDL? Is it due to the large data changes in the table? Additionally, how can this problem be resolved?