Works sub-library sub-table

A data table the physical vertical or horizontal segmentation algorithm or some of the tool is achieved by HASH

Applicable scene

1, the number of single table records or reach one million million level

2, problem-solving table lock
sub-table manner

The level of sub-table: a big table, after splitting can reduce the number of pages in the query needs to read the data and indexes, while also reducing the number of layers of the index, increase the number of queries

 

Applicable scene

1, the data in the table itself independence, such as data table records in various regions carved table or data in different periods, in particular, some of the data used, some not commonly used.

2, the data needs to be stored in the plurality of media.

Examples: qq login, particularly since qq number, now by modulo algorithm to optimize sql, sub-table 99, by modulo 100, the remainder of this data is determined table !!!
horizontal shear disadvantages min

1, to increase the complexity of the application, require multiple table names during normal query, all the data required to operate UNION

2, in many database applications this complexity will outweigh the advantages it brings, will increase the number of disk reads a query index layer

Vertical Table

And a number of columns of the primary key in a table, and the primary key and additional columns in different tables of

 

 

 

Applicable scene

1, if a certain column of the table used, some other columns are not used

2, the data line can be made small, a data page can store more data, reducing the I / O frequency and the query

Example: The figure is split vertically, with a transcript, there are student id, student name, student questions, students answer, but you will find sql statement is

select * from tt where id = "8"; this time the recall list, there will be topics and answers, this table is relatively large, this time to the subject, and answers break off, leaving an information table on it, the query time information directly query the table, rather than query topics and answers, but large-scale enterprise projects will put some big files are stored in a special picture or a file server, so those of us who do not need to consider the

Shortcoming


Shortcoming points table

Some points of the policy table logic algorithm based on the application layer, once the logic algorithms, and the whole sub-table logic will change, poor scalability

For the application layer, logic algorithms, increasing the development cost

MySQL replication and load balancing principle

MySQL master-slave replication works

On the primary data repository higher recording binary log

Copy from the library main library logs to their relay log

Read relay log event from the library, from the library into the weight data

MySQL master-slave replication problem

Data distribution: free to start or stop replication, and geographically distributed data backup
load balancing: single server reduces the pressure of
high availability and failover: application helps avoid single point of failure
upgrade test: You can use a later version of MySQL as from storehouse

Problem-solving approach

Fully grasp the points table of the partition principle and application scenarios, in the interview, such questions are usually more flexible, companies will encounter problems of some of the existing scenario, we can partition points table, MySQL replication, load balancing application scenarios to answer under the circumstances

Exams

Set the number of site users in ten million, but only 1% of the number of active users, how to optimize database access speed increase active users?
A:
can be used, the active users in one sub-area, no active users in another sub-area itself is less active than the user data area, it is possible to improve the access speed of the active users.

Also the level of sub-table, the active user points at a table, not active users divided in another table, you can improve access speed active users.

Guess you like

Origin www.cnblogs.com/weigy/p/12564086.html