MySQL sub-library sub-table interview knowledge

Scene analysis
Web development work, also, or huge amounts of data and development work, knowledge sub-libraries, sub-table, partition, etc. are necessary.
Interview, there may also be asked. However, as an experienced Coder, unfamiliar sub-library sub-table technology does have some low.
Basic concepts
points table, able to solve problems caused by excessive single-table data query efficiency is decreased;
sub-libraries, the face of high concurrent read and write access, when the master database server can not carry writes pressure, regardless of the extension slave server at this time it would be meaningless. At this point, you need to pass data sub-library strategy to enhance the ability of concurrent access to the database.
Advantages, sub-library, the optimized sub-table data storage technology to effectively reduce the burden on the database server, the query response time to shorten.

Sub-library data, sub-table storage scene conditions

Relational database
master-slave architecture (master-slave)
single table the amount of data in the millions-level
faced with high concurrent access to the database
sub-libraries, sub-table implementation strategy

Keyword modulo realize the data access route.
Sub-libraries

For example
according to the functions
the user library, libraries goods orders libraries, library and other log
by region,
each city or a similar provincial libraries, such as: db_click_bj, db_click_sh such as
landscape / horizontal partition table: solve table records too big problem (level of segmentation)

The main problem:

Single table is too large performance problems caused by;
single table over a single large server space problems caused.
A field by points

Such as: a user data table is divided into three attachment points Annex Table pre_forum_attachment_ [0 | 1 | 2] , and an attachment index table (tid stored relationship and attachments id), is determined in accordance with Annex tid stored in the last part table in which .
By date points table
for the log, statistics class data table by year, month, day, week points table. Such as: traffic statistics click_201801, click_201802
achieved through the merge MySQL storage engine
needs to create sub-tables, summary tables, summary tables need to merge storage engine.
Sample Code
Create Table log_merge (
dt datetime Not null,
info VARCHAR (100) Not null,
  index (dt)
) = Merge Engine
Union = (log_2017, log_2018) INSERT_METHOD = Last;

Longitudinal / vertical part table: solving the problem of excessive column (vertical slicing)

Vertically table common methods are divided according to the activity list, according to the importance of the points table and so on.
The main problem:
between the table and the table resource contention issues;
lock contention probability small;
to achieve core and non-core tiered storage, such as landing UDB library is split into a two three libraries;
database synchronization pressure problem.
Specific strategies
are often a combination of table columns query on a table, the fields could be considered common Memory engine.
Field is not frequently used alone as a table.
The text, blob other large fields on the split schedule. Such as: the user table into the main table articles and news from the table news_data, main memory table title, keywords, page views, etc., from a table stored specific content, templates, and so on.
Sub-library sub-table Notes
dimension problem
for the user purchase record data, according to the latitude of the user points table, then each user's transaction records are stored in the same table, so very quickly and very easy to find a user's purchases, but the case of a commodity to be purchased may be distributed in multiple tables, look up more trouble.
If the points table by product dimensions, easy to find merchandise purchases, but too much trouble to find personal trading records.
Common solutions:
to solve the table by sweeping way, too inefficient, not feasible.
Two data records, in accordance with a user latitude sub-table, a part table in accordance with the product dimensions.
By search engines to solve, but if the real-time requirement is high, the problem involves the real-time search.
Avoid sub-table join operations. The associated tables may not have the same database.
Avoid cross-database transactions
to avoid modifications in a transaction db0, db1 in the table, not only complicated to operate, but also affect the efficiency.
Many not less desirable part table; the latter may prevent the secondary split.
Try the same set of data unified DB server. For example, a seller of goods and trade information into db0, when db1 hung up when something related to a seller can be used normally. I.e., a plurality of data in the database to avoid dependence.

The References
Mysql quickly insert ten million test data making data mode pros and cons:. Https://www.2cto.com/database/201603/493032.html
method of test data of one million mysql made quickly insert data. The other three methods are summarized: https://www.cnblogs.com/endtel/p/5404065.html
sub-table and to achieve a simple example mysql database:. https://www.cnblogs.com/miketwais/articles/mysql_partition.html
mysql complete example of sub-library sub-table and the actual operation php code php code for:. https://blog.csdn.net/nuli888/article/details/52143065
the mySQL - A separate read and write on Amoeba: HTTPS: // WWW .2cto.com / database / 201610 / 555777.html

Guess you like

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