【 TiDB 使用环境】生产环境
【 TiDB 版本】5.0.2
【遇到的问题:问题现象及影响】
执行如下ddl,一直卡主不动,持续时间超过3小时,
alter table tb_xxx add index idx_yyyy(commissioner_id, month_id, city_id);
期间发现表的数据行数从2000w行左右,然后慢慢降到1000w行左右,然后现在慢慢涨到1900w行左右了,发现先有delete操作,然后insert操作导致的。
admin show ddl jobs中的row_count始终为0, 另外大概每20分钟会有如下类型的日志输出:
[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:, 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:, 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:, 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:, 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:, 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:, ErrCount:0, SnapshotVersion:0”]
请问这个ddl执行慢的原因是什么呢?是因为表的数据变化大导致的吗?另外又该如何解决这种问题呢?