Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.Original topic: LockKeys_time占用时长大的sql该怎么优化
[Overview] Scenario + Problem Overview
The SQL statement is a very simple update, where id is the primary key, and the table has approximately 90,000 rows. This update has taken anywhere from 3 to 9 seconds.
update t1 set col_1='a', col_2='b', col_3='c' where id=123;
I checked the slow_query table, and the SQL execution time is mostly spent on LockKeys_time.
[Problem] Current Issues Encountered
- What does lockkeys_time mean? I couldn’t find it in the official documentation; it feels like lock waiting?
- How can I optimize this kind of SQL?
[TiDB Version]
V-5.4.0
[Execution Plan]
id task estRows operator info actRows execution info memory disk
Update_9 root 0 N/A 0 time:4.61s, loops:2, , lock_keys: {time:844.1µs, region:2, keys:2, lock_rpc:784.261µs, rpc_count:2, retry_count:1} 0 Bytes N/A
└─Point_Get_1 root 1 table:xxx, index:PRIMARY(id), lock 1 time:4.61s, loops:3, Get:{num_rpc:2, total_time:644.2µs} N/A N/A