How to Optimize Long Locking Time When Inserting Data in TiDB?

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

Original topic: tidb插入数据 上锁耗时非常长,如何优化?

| username: TiDBer_y9IRzLWc

【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】Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots / Logs / Monitoring】


As shown in the picture, how can this situation be optimized?

| username: xfworld | Original post link

Optimization can only be done from a business perspective to reduce conflicts.

Alternatively, simulate an optimistic mode by adding a version field. Only when the versions are equal can an update be performed.

Or use caching to solve this local hotspot data issue.

The above is for reference only.

| username: longzhuquan | Original post link

  1. Reduce concurrency. 2. Optimize logic at the business layer to reduce conflicts. 3. Optimize the SQL itself to shorten execution time. Essentially, it’s all about reducing lock conflict time.
| username: redgame | Original post link

Let the application change the logic.

| username: TiDB_C罗 | Original post link

Check the logs, it shouldn’t be a regular insert, could it be an insert into update?

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.