The task status of adding a unique index remains in the running state

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 添加唯一索引任务状态一直处于running状态

| username: Mwkk

[TiDB Usage Environment] Production Environment / Testing / Poc
[TiDB Version] v7.1.4
[Reproduction Path] What operations were performed to cause the issue
[Encountered Issue: Issue Phenomenon and Impact]
[Resource Configuration] Enter TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachments: Screenshots/Logs/Monitoring]
Adding a unique index to a table with 37 rows remains in the running state. The table structure is as follows:
CREATE TABLE wechat_video_channels_account (
id bigint(0) NOT NULL AUTO_INCREMENT COMMENT ‘Auto-increment ID’,
account_id varchar(255) NOT NULL COMMENT ‘Unique ID of the account in the video channel’,
account_name varchar(255) NOT NULL COMMENT ‘Account name’,
update_time datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT ‘Update time’,
create_time datetime NOT NULL COMMENT ‘Creation time’,
PRIMARY KEY (id) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=90001;

The index addition statement is ALTER TABLE lego_star_test.wechat_video_channels_account ADD UNIQUE INDEX accountid_uidx(account_id);

| username: zhanggame1 | Original post link

First, check if the table select * from tidb_mdl_view; has any data.

Also, how large is the data volume?

| username: TIDB-Learner | Original post link

If the data is very small and adding an index is very slow, then there might be some special operations, such as causing locks.

| username: Mwkk | Original post link

There is no data when viewing this table, it only has 37 rows of data.

| username: TI表弟 | Original post link

Check the monitoring, CPU, and IO status.

| username: Mwkk | Original post link

[2024/05/29 18:51:18.585 +08:00] [INFO] [index.go:620] [“[ddl] run add index job”] [job=“ID:9923, Type:add index, State:running, SchemaState:none, SchemaID:192, TableID:9875, RowCount:0, ArgLen:6, start time: 2024-05-29 18:40:33.992 +0800 CST, Err:[ddl:-1][Lightning:PD:ErrCreatePDClient]create pd client error: [pd] unmatched cluster id, ErrCount:151, SnapshotVersion:0, UniqueWarnings:0”] [indexInfo=“{"id":4,"idx_name":{"O":"accountid_uidx","L":"accountid_uidx"},"tbl_name":{"O":"","L":""},"idx_cols":[{"name":{"O":"account_id","L":"account_id"},"offset":1,"length":-1}],"state":0,"backfill_state":0,"comment":"","index_type":1,"is_unique":true,"is_primary":false,"is_invisible":false,"is_global":false,"mv_index":false}”]

| username: Mwkk | Original post link

The relevant error log is on this.

| username: Mwkk | Original post link

Disabling the fast DDL feature allows indexes to be added normally.

| username: Jack-li | Original post link

High pressure on the Region leader node may also affect the execution speed of DDL.