MySQLSchema design (1) the paradigm cannot be amp; #39; fan amp; #39; bitsCN.com
Codd, the father of RDBMS, proposed a paradigm in the early 1970 s. its starting point was to reduce data redundancy in the database and improve data consistency. But redundancy is a luxury, because the storage space in that age was extremely expensive. After understanding this background and continuing to deepen the paradigm, we aim to better utilize and break the norms and standards. After all, the paradigm brings about some problems:
● Tightly coupled tables are strongly dependent on each other. as the business grows rapidly, it will lead to difficulties in splitting.
After understanding the paradigm moves, it is necessary to discover the limitations of the moves, either forget the moves, or create their own moves. this has the anti-paradigm
If the optimizer is the brain and the storage engine is the hands and feet, MySQL's brain is weak at present. when encountering some subqueries or more complex Join operations, it is easy to have a short-circuited mind, the execution plan of the driver table and slot is incorrect.... The constructor of Schema in the design of paradigm is that Join costs are usually required, while the anti-Paradigm Schema can avoid Join because all data is in a table. The most direct and effective way to reduce Join operations is through table field redundancy. How to implement redundancy? Below are several implementation methods:
①Static data-based redundancy
Predicate-based redundancy
Redundancy based on party functions
Sort-based redundancy
However, increasing redundancy will inevitably sacrifice the consistency of some data. We need to prioritize data consistency issues. It does not hurt users much, and users are not too concerned about the data, which is tolerable. However, we need to process the fatal and sensitive data at the application layer, such as secondary verification and regular sampling check. Will this be a problem, the write query frequency and read query frequency must be weighed.
The second advantage of the anti-paradigm design is that because the related columns are located in the same table, this can also effectively develop a robust index policy, that is, in the anti-paradigm, more emphasis on indexing, the foreign key is weakened. Assume that you have a video and entertainment website and want to view the 10 most recently released U.S. blockbusters. the following may be the case after normalization:
mysql > SELECT title,actor_name -> FROM film -> INNER JOIN actor ON film.actor_id=actor.id -> WHERE actor.area='AMERICA' -> ORDER BY film.published DESC LIMIT 10;
mysql > SELECT title,actor_name -> FROM actor_film -> WHERE area='AMERICA' -> ORDER BY film.published DESC LIMIT 10;
By Chiba
Good Luck!
BitsCN.com