delete 操作耗时1.3min

执行delete 操作,条件是主键,但是时间比较长,看了下执行计划主要时间耗费在prewrite 阶段,不是很理解执行计划



prewrite 阶段:主要是检测数据有没有上锁,想问下backoff 阶段呢?

你看执行计划里有提示backoff的内容没

1 个赞

实际你这图看着就有点问题,到底是prewrite耗时还是commit耗时啊,上面显示是prewrite耗时,但是下面的耗时又是在commit阶段的backoff耗时。。。

删了多少条数据?

是啥数据,资源使用情况如何

执行计划就是这样显示的,我也不知道到底是什么阶段的耗时

就删除一条数据,手动执行很快,但是应用反馈放在程序里面就很慢

是在哪个地方有显示?

后面的内容看看

id task estRows operator info actRows execution info memory disk
Delete_2 root 0 N/A 0 time:1.68ms, loops:1, commit_txn: {prewrite:1m20.1s, wait_prewrite_binlog:800ns, backoff: {time: 1m20s, prewrite type: [txnLock]}, slowest_prewrite_rpc: {total: 0.002s, region_id: 137292, store: 9.1.65.131:20160, tikv_wall_time: 1.29ms, scan_detail: {get_snapshot_time: 301.7µs, rocksdb: {block: {cache_hit_count: 8, read_count: 1, read_byte: 10.4 KB, read_time: 182.4µs}}}, write_detail: {store_batch_wait: 5.78µs, propose_send_wait: 0s, persist_log: {total: 59.6µs, write_leader_wait: 50ns, sync_log: 29.4µs, write_memtable: 2.67µs}, commit_log: 259.4µs, apply_batch_wait: 16.7µs, apply: {total:68.2µs, mutex_lock: 0s, write_leader_wait: 0s, write_wal: 12.9µs, write_memtable: 18.9µs}}}, resolve_lock: 40ms, region_num:15, write_keys:15, write_byte:691} 145.5 KB N/A
└─Batch_Point_Get_1 root 1 table:vsMark, index:PRIMARY(visaSerialNo, visaCode), keep order:false, desc:false 1 time:1.51ms, loops:2, BatchGet:{num_rpc:2, total_time:1.41ms}, scan_detail: {total_process_keys: 2, total_process_keys_size: 367, total_keys: 2, get_snapshot_time: 368.5µs, rocksdb: {block: {cache_hit_count: 18}}} N/A N/A
![image 690x77](upload://6GdhTrW3BAkh5m4tRnUVBtq5pIe.png)

锁的问题

1 个赞

这是写写冲突了,参考这里排查下
https://docs.pingcap.com/zh/tidb/stable/troubleshoot-write-conflicts#如何解决写写冲突问题

好的 我看下 谢谢

好嘞 我这边让开发看看业务端能不能改下

DELETE 操作时间过长,您可以考虑以下优化策略:

  1. 分批删除(Batch Delete): 将大量的删除操作分成多个较小的批次进行,以减少单个事务的数据量,从而减轻 prewrite 阶段的负担。
  2. 调整事务隔离级别(Transaction Isolation Level): 降低事务的隔离级别可能会减少冲突检测的开销,但同时会降低隔离性。
  3. 调整索引结构: 表的索引结构会影响 DELETE 操作的性能,可能需要重新评估索引的设计。