当前位置:网站首页>Mysq index optimization and how to avoid deadlock

Mysq index optimization and how to avoid deadlock

2022-06-22 08:25:00 ambition_ forever

1、 Use overlay indexes to avoid backtracking .

2、 Optimize queries using self incrementing fields as primary keys .

3、 Prefix index , Reduce index presence pages , Then the query is reduced io, Increase of efficiency .

        order by Cannot use prefix index , Cannot use prefix index as overlay index .

4、 If... Is used in query criteria or, And or There is no condition in the index before and after , Then the index will not be used .

5、 You can try to pass force index To force the use of indexes .

6、mysql Transaction isolation through Lock to achieve , Atomicity and consistency of transactions are achieved through undolog and mvcc Realization .

The persistence of transactions is achieved through redolog + binlog To guarantee

7、 The specific implementation algorithm of row lock record lock、gap lock as well as next-key lock. Common deadlocks are in rr Under transaction isolation level select for update Will add gap lock.

8、 Avoid deadlocks Set timeout innodb_lock_wait_timeout To set the timeout , Avoid waiting for each other ; Avoid long affairs , Disassemble the transaction , Reduce the probability of conflicts with other transactions . Turn on Deadlock Detection innodb_deadlock_detect = on Turn on Deadlock Detection , When it happens mysql Choose rollback .

9、 Shared locks and exclusive locks belong to row locks , Intention lock belongs to table lock .

原网站

版权声明
本文为[ambition_ forever]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202220528292171.html