Range coverage PROBLEM: The INSERT statement fails when the value of the corresponding partition key in the inserted record is not in the range defined by the partition. The above example, what happens if I insert a record of store_id = 30? When we partition above, the maximum value is 20, if inserting a record more than 20, will be error:mysql> INSERT INTO EMP (ID, store_id) VALUES (2,1526 for -
- Tip 30 This value does not have a corresponding partition. Solutions A. Estimate the value of the partition key and add the partition in time. B. When partitioning is set, the
values less than maxvalue
clause is used, MaxValue represents the largest possible integer value. C. Try to select all the fields that can be overwritten as partition keys, such as 12 months of the year.
- In a range partition, the value of the partition key, if NULL, is treated as a minimum value.
8. List partitionA list partition is a set of discrete values that tells the database which partition a particular value belongs to. Grammar:
// Exp is a column name or an expression inch (3,5) // values of 3 and 5 in the P0 partition )
Unlike range, the list partition does not have to be in any particular order of life. For example:
mysql>, id int not null , -store_id int not null -> ; ) -> partition by list (store_id) (-> ; Partition P0 values in (3 , 5 ), , partition P1 values in ( 2 , 6 , 7 , 9 );
Note If the value of the partition key that the inserted record corresponds to is not in the value specified by the list partition, the insertion fails. Also, List cannot provide maxvalue as the range partition does.
9. Columns PartitionThe partition type introduced in MySQL5.5 resolves the problem that the range partition and the list partition only support integer partitioning before the 5.5 release. Columns partitions can be subdivided into a range columns partition and a list columns partition, they all support Integer, DateTime, and string three-big data types. (Text and BLOB types are not supported as partition keys) The columns partition also supports multi-column partitioning (this is not expanded in detail here).
Ten. Hash partitionHash partitioning is primarily used to disperse hot-spot readings, ensuring that data is distributed as evenly as possible in predetermined numbers of partitions. MySQL supports two types of hash partitioning: regular hash partitioning and linear hash partitioning. A. Regular hash partitioning: Using the modulo algorithm syntax:
4;
The above statement, according to the store_id 4 modulo, determines the record storage location. For example store_id = 234 of the record, MOD (234,4) = 2, so it will be stored in the second partition.
the advantages and disadvantages of regular hash partitioning : the ability to distribute the data as evenly as possible. Cons: not suitable for frequently changing needs of partitions. If I were to add two new partitions and now have 6 partitions, then the result of the MoD (234,6) would be inconsistent with the results of the previous mod (234,4), so that most of the data would need to be recalculated. To solve this problem, MySQL provides a linear hash partition.
B. Linear hash Partitioning: The partitioning function is a linear 2 exponentiation algorithm. Grammar:
4;
Unlike regular hash, the "Liner" keyword. Algorithm Introduction: Assuming that the partition number to save the record is n,num to a non-negative integer, representing the number of partitions divided into, then n can be obtained by the following steps:
Step 1. Find a power of 2 greater than or equal to NUM, the value of which is v,v can be obtained by the following formula:
V = Power (2,ceiling (Log (2,num)))
For example: just set up 4 partitions, Num=4,log (2,4) =2,ceiling (2) =2,power (2,2) = 4, i.e. v=4
Step 2. Set N=f (column_list) & (V-1)
For example: Just v=4,store_id=234 corresponds to the n value, n = 234& (4-1) =2
Step 3. When N>=num, set v=ceiling (V/2),n=n& (V-1)
For example: Store_id=234,n=2<4, so N is the value of 2, can be.
Assuming the above calculated n=5, then v=ceiling (4/2) =2,n=5& (2-1) = 1, that is, in the first partition.
advantages and disadvantages of linear hashing : MySQL can handle more quickly when partition maintenance (add, delete, merge, split partition). Disadvantage: The data distribution between each partition of the linear hash is not very balanced compared with the regular hash partition.
One. Key partitionLike hash partitioning, hash partitioning allows user-defined expressions to be used, but the key partition does not allow user-defined expressions. Hash only supports integer partitioning, while key partitioning supports other types of columns except BLOBs and text as partition keys. Grammar:
4; // Exp is a list of 0 or more field names
When the key partition, exp can be empty, if empty, the default is to use the primary key as the partition key, when there is no primary key, the non-null unique key is selected as the partition key.
12. Sub-partitionsThe partition table splits each partition again and becomes a composite partition.
13. Partitioning for null value handlingMYSQ allows the partition key value to be null, the partition key may be a field or a user-defined expression. In general, MySQL treats null values as 0 values or a minimum value when partitioning.
Attention
Range partition: Null values are treated as minimum values
List partition: The null value must be listed, otherwise it will not be accepted
Hash/key partition: null value is treated as 0 value
14. Partition ManagementPartition management includes additions, deletions, and queries for partitions.
- Add Partition:
For range partitions and list partitions:
ALTER TABLE TABLE_NAME ADD partition (partition P0 values ... (exp))
The content behind values differs depending on the type of partition.
For hash partitions and key partitions:
8;
- The above statement refers to the addition of 8 partitions.
- Delete Partition
For range partitions and list partitions:
// P0 is the name of the partition to be deleted
The partition is deleted and all data in that partition is also deleted. At the same time, if the partition is deleted and the partition cannot overwrite all the values, the data will be inserted with an error.
For hash and key partitioning:
2 // reduce the partition to a total of 2
- Coalesce [? k???? Les] VI. Union, merger
- Partition query 1) query How many partitions there are in a table
Mysql>Select-Partition_name,-Partition_expression,-Partition_description,-table_rows- from-information_schema.partitions-whereTable_schema='Test'and table_name ='EMP';+----------------+----------------------+-----------------------+------------+| Partition_name | partition_expression | partition_description | Table_rows |+----------------+----------------------+-----------------------+------------+| P0 | store_id |Ten|0|| P1 | store_id | -|1|+----------------+----------------------+-----------------------+------------+