今天业务反馈一直遇到锁超时问题,排查过程中发现一个奇怪的现象。TIDB_TRX有一条记录,记录了被锁的sql,但是没有持有锁的语句信息,而且本身这个表只有一条记录,但是ALL_SQL_DIGESTS这个字段记录了两个,有点让人迷糊,不知道这是啥情况。
如下是tidb的日志信息
[2025/10/24 16:28:10.802 +08:00] [WARN] [session.go:2150] ["run statement failed"] [conn=3513313490] [session_alias=] [schemaVersion=80096] [error="[tikv:1205]Lock wait timeout exceeded; try restarting transaction"] [session="{\n \"currDBName\": \"wizard2\",\n \"id\": 3513313490,\n \"status\": 3,\n \"strictMode\": true,\n \"txn\": \"461712769879375887\",\n \"user\": {\n \"Username\": \"?\",\n \"Hostname\": \"?\",\n \"CurrentUser\": false,\n \"AuthUsername\": \"projsa\",\n \"AuthHostname\": \"%\",\n \"AuthPlugin\": \"mysql_native_password\"\n }\n}"]
[2025/10/24 16:28:10.802 +08:00] [INFO] [conn.go:1160] ["command dispatched failed"] [conn=3513313490] [session_alias=] [connInfo="id:3513313490, addr:xxxx:41244 status:11, collation:utf8mb4_bin, user:?"] [command=Query] [status="inTxn:1, autocommit:1"] [sql="SELECT `user_id` , `name` , `name_update_time` , `resident_country` , `text_language` , `voice_language` , `country_code` , `akamai_based_signup_country` , `last_play_time` , `selected_emblem_id` , `selected_degree_id` , `comment` , `birth` , `register_birth_time` , `is_parental_consent` , `create_time` , `last_logout_time` , `account_transition_viewer_id` FROM `user_info` WHERE `user_id`=? AND delete_time=0 FOR UPDATE"] [txn_mode=PESSIMISTIC] [timestamp=461712769879375887] [err="[tikv:1205]Lock wait timeout exceeded; try restarting transaction"]
MySQL [information_schema]> select * from TIDB_TRX\G
*************************** 1. row ***************************
ID: 461712769879375887
START_TIME: 2025-10-24 16:27:20.763000
CURRENT_SQL_DIGEST: 396b0ec0c326a75fa43de27c3055c900c6fc8a970176600a429f091cea639aa7
CURRENT_SQL_DIGEST_TEXT: select `user_id` , `name` , `name_update_time` , `resident_country` , `text_language` , `voice_language` , `country_code` , `akamai_based_signup_country` , `last_play_time` , `selected_emblem_id` , `selected_degree_id` , `comment` , `birth` , `register_birth_time` , `is_parental_consent` , `create_time` , `last_logout_time` , `account_transition_viewer_id` from `user_info` where `user_id` = ? and `delete_time` = ? for update
STATE: LockWaiting
WAITING_START_TIME: 2025-10-24 16:27:20.799355
MEM_BUFFER_KEYS: 0
MEM_BUFFER_BYTES: 0
SESSION_ID: 3513313490
USER: ?
DB: ?
ALL_SQL_DIGESTS: ["9a4170a059f3113e196bdac9c156d6cecf3ccbef8eb238b878d04e61aa7d9741","396b0ec0c326a75fa43de27c3055c900c6fc8a970176600a429f091cea639aa7"]
RELATED_TABLE_IDS: 55377
WAITING_TIME: 18.41762807
1 row in set (0.011 sec)
MySQL [information_schema]>
processlist 如下
MySQL [information_schema]> show processlist;
+------------+---------+--------------------+--------------------+---------+------+----------------------------+------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+------------+---------+--------------------+--------------------+---------+------+----------------------------+------------------------------------------------------------------------------------------------------+
| 3513313492 | xxxxxx | 7.23.32.234:41256 | wizard2 | Sleep | 11 | autocommit | NULL |
| 3512730024 | monitor | 7.221.53.120:59146 | NULL | Sleep | 87 | | NULL |
| 3513315448 | root | 127.0.0.1:37902 | information_schema | Query | 0 | autocommit | show processlist |
| 3513313496 | xxxxxx | 7.21.53.120:55930 | wizard2 | Sleep | 5 | autocommit | NULL |
| 3513313488 | xxxxxx | 7.21.54.120:50024 | wizard2 | Sleep | 5 | autocommit | NULL |
| 3513313490 | xxxxxx | 7.21.13.120:41244 | wizard2 | Query | 37 | in transaction; autocommit | SELECT `user_id`,`name`,`name_update_time`,`resident_country`,`text_language`,`voice_language`,`coun |
+------------+---------+--------------------+--------------------+---------+------+----------------------------+------------------------------------------------------------------------------------------------------+
6 rows in set (0.001 sec)
MySQL [information_schema]>