Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: update 上锁耗时长
A simple update statement takes 6 seconds. I checked the execution time and it seems to be stuck on locking. What could be the reason for this?
Let’s look at the execution plan.
The table is locked. Due to lock conflicts or errors, the plan may fail and retry execution multiple times. This time does not include the natural time of the preceding executions before the last execution (Note: The time in the execution plan does not include this preceding time).
The execution plan is very simple
Check the locks in the CLUSTER_TIDB_TRX table.
This table only records the current moment’s state, once it’s gone, it’s gone.
Has this SQL been executing continuously, or does it only execute at certain times?
This will only be triggered when certain conditions are met, not always.
Next time you execute it, check it out. There should be a lock.
Check if there is any information related to locks recorded in the logs.
Check for lock conflicts to see if there are concurrent transactions.
Take a look at the lock information in the system table.
Adjust the isolation level to see if it is the RC isolation level, and check if the where condition has an index.
This locking issue is difficult to troubleshoot, and it mainly needs to be investigated from the business perspective.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.