Common database optimization methods and solutions

1. Optimize direction

  1. SQL optimization and indexing . First, according to the needs write good SQL, and then establish an effective index in the table based on SQL. But the index can not be too much, otherwise it will affect query efficiency.
  2. Reasonable design database . Results of the design to the table according to the database three paradigms, the design should consider how to more effectively search.
  3. Optimize system configuration . For example: my.cnf file mysql database.

supplement

1.1 Field Type selection

  1. Less use INT, multi-use TINYINT, SMALLINT, if non-negative plus UNSIGNED
  2. VARCHAR length of the space allocated only really need
  3. Avoid using NULL, query optimization because it is difficult and takes up additional space index

1.2 database three paradigms

The first paradigm: Each field data table must be a minimum unit inseparably , to ensure that each column is atomic ;
second paradigm: a paradigm of post meet, each column of the table must have a unique property , must rely on the primary key ;
third paradigm: the paradigm satisfy two, each column of the table and only directly related to the primary key, rather than indirectly related (foreign key is directly related to), no field redundancy.

2. optimization

(1) code optimization . There are some performance issues because the code is written entirely unreasonable, sometimes under the direct modification can be solved. For example: for too many cycles, condition judgment made unnecessary, the same logic is repeated a plurality of times.
(2) positioning slow SQL, and optimization . Positioned by slow query log comes open or slow query the system to the specific problems of SQL, then explain, prifile stepwise tuning the like.
(3) rational use of the index . Since the index is space for time, it will affect the add, delete, change of efficiency frequently write table should not be indexed. Choose where, group by, order by, on the column clause appears as an index for the small dispersion of the column is not necessary to create the index.
(4) buffer
(5) sub-table
(6) separate read and write

Published 100 original articles · won praise 33 · views 5818

Guess you like

Origin blog.csdn.net/JAVA_I_want/article/details/104179254