tidb 出现写写冲突的原因

你问的这个是乐观事务写写冲突中的,但看你测试好像是悲观事务

按照你的测试过程跑了下,悲观事务,没出现pessimistic write conflict:joy:

[2022/07/29 17:41:59.575 +08:00] [INFO] [conn.go:1115] [“command dispatched failed”] [conn=493] [connInfo=“id:493, addr:10.1.48.44:45680 status:11, collation:utf8_general_ci, user:root”] [command=Query] [status=“inTxn:1, autocommit:1”] [sql=“insert into sbtest99 values(1,200000,‘18018173308’,‘18018173308’)”] [txn_mode=PESSIMISTIC] [err=“[kv:1062]Duplicate entry ‘1’ for key ‘PRIMARY’”]

如果是乐观事务,在SESSION1在insert的时候不会报错,在COMMIT的时候会报write conflict,未报Duplicate entry

ERROR 9007 (HY000): Write conflict, txnStartTS=434919573708603394, conflictStartTS=434919572109524993, conflictCommitTS=434919580091809794, key={tableID=759, indexID=1, indexValues={200000, 1, }} primary={tableID=759, indexID=1, indexValues={200000, 1, }} [try again later]