当前位置:网站首页>Brief description of SQL optimization problems

Brief description of SQL optimization problems

2022-07-06 18:15:00 Programming for Hongmeng

SQL Optimization of the 7 In terms of

  1. Create index
  2. Avoid index invalidation
  3. Lock granularity ( Row lock or watch lock )
  4. Paging query optimization
  5. Avoid querying all fields
  6. analysis SQL Implementation plan of
  7. show profile analysis SQL Execution performance

Create index

  • It is forbidden to create a separate index for each column in a table
  • Every Innodb Table must have a primary key
  • Pay attention to the field order of the combined index
  • Override index first
  • Avoid using foreign key constraints

Avoid index invalidation ( Failure scenario )

  • With % At the beginning LIKE Inquire about
  • Operations on index columns , function upper() etc. ,or、!=、<>、not in wait
  • Composite index created , But the query conditions are not satisfied “ The leftmost match ” principle
  • Use... In query conditions or, And or There is no condition in the index before and after , Then the indexes involved will not be used

Lock granularity ( Row lock   still   Table locks )

  • MySQL Our storage engines fall into two broad categories : MyISAM and InnoDB 
  • MyISAM Only supported Table locks
  • InnoDB Support Row lock and Table locks
  • update operation when , In order to ensure the accuracy of table data , Usually Lock , In order to improve the high concurrency of the system , We usually recommend Row lock , Reduce lock conflicts 、 Lock wait time . therefore , Storage engines usually choose InnoDB

Paging query optimization

Avoid querying all fields

analysis SQL Implementation plan of

show profile analysis SQL Execution performance


The follow-up will gradually improve ... Make a point in this chapter first

原网站

版权声明
本文为[Programming for Hongmeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061013049901.html