Update shows execution time as 50 seconds

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

Original topic: update 显示执行时间为50S

| username: 胡杨树旁

[TiDB Usage Environment] Production Environment / Testing / PoC
[TiDB Version]
[Reproduction Path] What operations were performed that led to the issue
[Encountered Issue: Problem Phenomenon and Impact]
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]




Upon checking the slow queries, it was found that there are many updates taking 50 seconds to execute, and some updates with relatively shorter execution times. Upon checking the execution times separately, it was found that the SQLs taking 50 seconds to execute did not show any lock conflict information.

| username: WalterWj | Original post link

  1. Check if there are any changes in the execution plan and whether the index used is appropriate.
  2. Check what kind of lock it is and optimize it in the business logic.
    TiDB 锁冲突问题处理 | PingCAP 文档中心
| username: 胡杨树旁 | Original post link

These types of updates are based on the primary key, and if the primary key is updated, it should normally be very fast.

| username: WalterWj | Original post link

Okay, that rules out the possibility that the execution plan is incorrect, causing the slowness.

Next, let’s check if there are any resource bottlenecks or unreasonable parameters in the locks and cluster that are preventing optimal resource utilization.

| username: 胡杨树旁 | Original post link

The overall resource usage of the cluster is not much different from before. I don’t know why this update is taking so long to execute.

| username: WalterWj | Original post link

Then let’s check the lock situation. See if the official documentation posted above is helpful.

| username: 胡杨树旁 | Original post link

Conflicts occur not only when updating the same data, right? But looking at those 50s SQLs, the updated values of the primary keys are all different.

| username: Billmay表妹 | Original post link

Check if this article is helpful to you~

| username: 胡杨树旁 | Original post link

Okay, thank you, cousin.

| username: Jiawei | Original post link

I think it’s still a locking issue. I suggest checking the logs again.

| username: 胡杨树旁 | Original post link

The logs mainly focus on what content? I looked at the execution time of two SQL statements, some have lock time and some don’t. Does the lock duration mean it has never been released?

| username: Lucien-卢西恩 | Original post link

Has this investigation been completed? Any progress?

| username: 我是咖啡哥 | Original post link

The time is all spent on locking. It must be due to multithreading and concurrent modifications of the same data. You need to develop and modify the program logic to avoid simultaneous modifications.

| username: 胡杨树旁 | Original post link

The application side reported that there were multiple modifications to the same record, causing the subsequent script waiting time to become increasingly longer.

| username: Lucien-卢西恩 | Original post link

Have you already optimized the business logic of the application?

| username: 胡杨树旁 | Original post link

The application side said to check it out.