Deadlock is caused by multiple transactions competing for the same resource. Whether it is two SQL statements in two transactions, the locking order of the resources being operated is different, or the locking order of the resources operated by one SQL statement in the two transactions is different. Why is the gap lock not locking in the scope, thus suspending another transaction's request for the resource?
I think specific issues should be dealt with in detail. Let’s take a detailed look at your two SQLs and then analyze them in detail