MySQL Performance Optimization (c) table structure optimization

First, select the appropriate data type

1. be able to save your data using the smallest data type.
2. Using a simple data type. int varchar type is simpler than in the mysql process.
3. Use not null-defined fields as much as possible.
4. The text as little as possible regardless of the type is not available Preferably, the non-used part tables.
Int * used to store log time, using FROM_UNIXTINE () (obtained date), UNIX_TIMESTAMP () (obtained time stamp) functions to convert two
* bigint used to deposit ip address, using INET_ATON (), INET_NTOA () function of two to convert

 

Second, the paradigm of the table and the anti-paradigm design

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

First introduce the database paradigm defined as follows

The first paradigm : Let R when all the attributes are not decomposed at a more basic data unit, said R satisfies the first paradigm is abbreviated as 1NF. The first paradigm is to meet the minimum requirements for the standardization of relational schema. Otherwise, there will be a lot of basic operations can not be implemented in a relational schema.

Description : Each column attributes are attribute values can not be divided, ensuring atomicity of each column. The two similar or the same or similar properties as far as possible the same properties combined column, to ensure that no redundant data is generated.

The second paradigm : If the first normal form relational schema R and R have all non-primary attributes are totally dependent on the properties of each of the candidate key of R, R, said second normal, abbreviated as 2NF.

Description: each row of data can only be associated with one of the columns that line of data only one thing. Repeated as long as the data in the data column, the table it should be split open.


Third Pattern : Let R be a relational model of the first condition is satisfied Paradigm, R X is an arbitrary set of properties, if X is dependent on non-transmission of one candidate keyword any R, R satisfies said third paradigm, referred to simply as 3NF .

Description: data can not transfer relationship exists, that is not related to the primary key attribute is directly related rather than an indirect relationship. Like: a -> b -> c containing such a relationship between the attribute is inconsistent with the third paradigm.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

1, based on the paradigm to optimize usage

Paradigm design specification database means, the current paradigm comes generally refers to a third design patterns, that is, the data sheet does not exist in the non-key fields of the transfer function depends any candidate key section is in line with the third paradigm.

Table following problem does not meet the requirements of the third paradigm:
1. Data redundancy :( classification, classification described) recorded for each of the goods will
2. Insert abnormal data
3. The data update anomalies
delete abnormal data 4

 

2, optimization-based anti-paradigm usage

Anti-normalization means in order to consider the efficiency of the query table had an appropriate increase in line with the third paradigm of redundancy to achieve the purpose of optimizing the query, the anti-normalization is a trade off space for operation time.

 

 

This is a lesson in learning Mu Network "performance optimization of MySQL optimization" and refer others to do the video recording finishing.

 

Guess you like

Origin www.cnblogs.com/lovechengyu/p/11491419.html