当前位置:网站首页>Database design (3): database maintenance and optimization

Database design (3): database maintenance and optimization

2022-06-26 04:28:00 good writings make people copy them

What to do in maintenance and optimization

One . Maintain data dictionary

1. Use third-party tools to maintain the data dictionary

2. Use the prepared column field of the database itself to maintain the data dictionary

Two . Maintain index

How to select the right column to index

 1. Appear in the WHERE clause ,GROUP BY clause ,OREDER BY Column in clause

2. Columns with high selectivity should be placed in front of the index

3. Do not include too long data types in the index . Before use only 16 Bytes are indexed , Or fields that are too large , Conduct md5 transformation , Then go to index

matters needing attention :

1. The more indexes, the better , Too many indexes will not only reduce the write efficiency , And it will reduce the efficiency of reading .

Every time you write a record , The index should be maintained , The cost of maintenance is large .

Read operations , because SQL The optimizer will select the appropriate... Based on the index information and statistics sql The index of . If there are too many indexes ,SQL The process by which the optimizer selects an index affects efficiency

2. Maintain index fragmentation on a regular basis

The creation and maintenance of indexes consume , Indexes take up physical space , And with the increase of the amount of data .

 3. stay SQL In the sentence Do not use Force index key .

The original index used due to the change of data volume , It may not apply in the future . If forced indexing is used , It will affect the efficiency of the database , If you delete the index , Developers don't know , The query will be wrong .

3、 ... and . Maintenance table structure

matters needing attention :

1. Use online tools to change the structure

Different kinds of triggers can exist in the same table , But there cannot be more than one of the same kind .

2. At the same time, maintain the data dictionary

3、 Control the width and size of the table

The database is suitable for operation

 1. The batch operation VS One by one operation

The database is suitable for batch operation , One by one operation is suitable for completion in the program

2. No use select * This kind of operation

Use select * Query and add all columns IO burden , Because the query except for a large number of unused fields

3. Control the use of user-defined functions

Using too many user-defined functions , May affect the index

4. Do not use full-text indexes in the database

Full text indexing requires the creation of additional index files , To maintain the index . And full-text indexing is not very friendly to Chinese support . If you really need it , Suggest using search engine .

Four . Split the table horizontally or vertically when appropriate

1. Split Vertically

2. Horizontal split

 

 

原网站

版权声明
本文为[good writings make people copy them]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180531084681.html