Optimization: partition

Feature

Partition conducive to manage a very large table, which uses the logic divide and conquer the partition introduced the concept of partition key, the partition key according to an interval value (or range), a particular value list or hash functions perform data aggregation, let the data according to the rules in different partitions

 

Partition type

range partition

Given a continuous range of values ​​to partition section, a field value satisfies this range will be assigned to the partition. Field values ​​are applied to successive sections of the field, such as a date range, consecutive numbers.

grammar

create table <table> (

// field

) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1

partition by range (partition field) (

partition <partition name> values ​​less than (Value),

partition <partition name> values ​​less than (Value),

...

partition <Partition name> values ​​less than maxvalue

);

Field Meaning

less than: means less than

Value: indicates less than a specific value, such as less than (10) then the value field is less than the partition will be assigned to the partition 10

maxvalue: represents a maximum value

note

1: range corresponding partition key value must be a numeric value, may be used range columns (fields partition) made of non-int partition type, such as string, may be used as a date of year (), to_days (), to_seconds (), etc. function

2: Either no primary key table structure using range partitioning, partition field must either be a primary key.

 

list partition

Setting a plurality of partition fixed value, if the value of a field in the list will be assigned the value of this set to the partition. Applies to discrimination field value is not high, or if the value is limited, especially such characteristics as enumerated columns

grammar

create table <table> (

// field

) ENGINE = database engine DEFAULT CHARSET = utf8 AUTO_INCREMENT = 1

partition by LIST (partition field or expression returns an integer value of the field-based) (

partition <partition name> values ​​IN (Value1, Value2, Value3),

...

partition <partition name> values ​​IN (Value4, Value5),

);

 

hash partitioning

Is mainly used to read the hot dispersion, may ensure that data in a predetermined number of partitions evenly distributed. Performing a Hash partition table, mysql partition key will apply a hash function, the data should be placed in order to determine which partition partitions the N

mysql supports two hash partitioning

1: General hash partitions using modulo arithmetic, corresponding to an expression expr can calculate to which it is stored in the partition

2: linear hash partitioning algorithm used is a power of 2 of a linear

 

key partition

Similar to hash partitioning

 

Child partitions

Partition table for each partition divided again, also known as a composite partition, support for sub-range and list partition, i.e. can sub-partitions hash partitions partition key may be used. Composite partitions are ideal for holding a very large amount of data records

 

Partition advantage

1: and a single disk or file system partition compared to, it can store more data

2: optimize queries. When the partition condition contained in the where clause to scan only the necessary one or more partitions to improve query efficiency; involving simultaneously the sum () and the count () function of such aggregate queries, each partition can be easily the parallel processing, and ultimately just summary results of all partitions get

3: For already expired or no saved data, you can quickly delete data by deleting data related to these partitions

4: to spread data across multiple disks queries, to obtain greater query throughput

 

 

 

The difference between the partition and the partition table

Achieved on the way

1: mysql sub-sub-table is a real table, a table is divided into many tables after every small table is a table completely positive, corresponds to three files, one data file .MYD, .MYI index file, .frm file table structure.

2: partition is not the same, after a large table partition, he was a table, the table does not become two, but he blocks stored data becomes more

 

Data processing

1: sub-table, the data points are stored in the table, a summary table just housing, accessing data in a place in which one part table

2: partition, there is no concept of partition table, partition, but the files are stored data is divided into many small pieces, table, or is it a table after partition. Data processing is done by themselves.

 

Improve the performance

1: part tables, single table concurrency improves, disk I / O performance is improved. Why concurrency to improve it, because it takes time to search for a shortened, if high concurrency appear, the total table according to different queries, concurrent pressure into different small tables inside. Disk I / O performance out how high it, would have been a very large file .MYD .MYD now allocated to each small table to go.

2: mysql proposed the concept of partition, I think wanted to break through the disk I / O bottlenecks, want to improve literacy disks to increase performance mysql.

At this point, the focus of measuring the partition table and points of different points table when the focus is on data access, mysql on how to improve concurrency; and partition it, how to break the disk reading and writing skills, so as to improve the performance of mysql.

 

Points table and partitions are not contradictory, can cooperate with each other for the big number of visits, and more table data table, we can take the form of sub-tables and partitions combined (if merge this sub-table mode, can not partition with words you can use the other sub-table test), little traffic, but a lot of table data table, we can take the partition of way, etc.

 

 

Published 50 original articles · won praise 2 · Views 2278

Guess you like

Origin blog.csdn.net/eafun_888/article/details/104738696