How to page through a query after sub-table mysql database? Mysql sub-library sub-table program?

Reference
1. If only for paging, may be considered such a part table is the table id of the range, and the id is continuous, such that the first table id 1-100000, a second 100000-20 million and this page should be no problem.

2. If other sub-table, it is recommended to build a sphinx index, and then query paging, our company now is so dry

Mysql sub-library sub-table program

1. Why did you watch:

When the data reaches tens of millions a table, query time you spent time become more, if the joint inquiry, I think there might have died there. The purpose of the score sheet in this, reduce the burden of the database, shorten the query time.

mysql there is a table lock mechanism and a locking row, in order to ensure data integrity. You can not lock the table represents operate on this table, so I have to finish the job on the operating table. Line lock, too, I have to wait another sql operation finished these pieces of data, in order to operate these pieces of data.

  1. mysql proxy:amoeba

Do mysql cluster, using the amoeba.

From the top of the java program is concerned, you do not need to know the source of the primary server and from the server, that is transparent from the main database server for the top terms. You can be configured by amoeba.

And 3. large amount of data frequently accessed table, divided into several tables

For example, a database table for a site platform - the company table, a large amount of data, this data can be projected out of the large scale, we will advance the separation of a table of N, N is the number, according to the actual situation.

 某网站现在的数据量至多是5000万条,可以设计每张表容纳的数据量是500万条,也就是拆分成10张表,

So how to determine whether the data a particular table is full of it? To be added to the table data, records do first before inserting the number of tables operating in the block, when <5 million data directly inserted, when the threshold has been reached, you can create a new segment in the program database table ( or have previously created), then insert operation.

  1. Using the merge storage engine to achieve sub-meter

If you want to separate the existing large scale data more painful, the most painful thing is to change the code, because the program inside the sql statement has been written. Merge with the storage engine to achieve sub-table, this method is suitable.

for example:

------------------- ----------------- ---------- gorgeous dividing line ---------------------

Database Architecture

1, a simple MySQL master-slave replication:

MySQL master copy from resolved separate read and write the database, improves the performance and a good read, which is as follows:

From the main replication process shown below:

However, master-slave replication has also brought a host of other performance bottlenecks:

  1. Write can not be extended

  2. Can not write cache

  3. Copy Delay

  4. Lock model rise

  5. Table larger cache rate has dropped

That somehow solve the problems, which produces the following optimization program, take a look.

2, MySQL a vertical partition

If the business was independent enough to cut, and that the data from different services into different database server will be a good program, but just in case one of the business collapse, it will not affect the normal running of other services, and also played a load diversion role, greatly enhance the handling capacity of the database. After the database schema vertical sections is as follows:

However, although between business has sufficient independence, but always a little more or less between some business contact, such as users, and each business will basically associated Moreover, this partitioning approach can not solve a single table data skyrocketing amount of problems, so why not try it split horizon?

3, MySQL slice level (Sharding)

This is a very good idea, according to certain rules to the user (by hash id) packet, and sends the set of user data stored in a database slice, i.e. a Sharding, such as the number of users, simply a server configured to, the following diagram:

How to determine a user's shard of it, you can build a shard of users and corresponding data tables, each request to start this list to find the user's shard id, then other relevant data from the corresponding shard in, as shown below :

Guess you like

Origin www.cnblogs.com/djwhome/p/12536018.html