Multi-column partitions in MySQL 5.5

Source: Internet
Author: User

For MySQL 5.5DatabaseMulti-column partitioningThis is what we will introduce in this article. We will introduce this part through an instance. Let's take a look at it!

Multi-column partitioning

The COLUMNS keyword now allows the string and date COLUMNS to be defined as partition COLUMNS, and multiple COLUMNS to define a partition. You may have seen some examples in the official documentation, such:

 
 
  1. CREATE TABLE p1 (    
  2.   a INT,    
  3.   b INT,    
  4.   c INT   
  5. )    
  6. PARTITION BY RANGE COLUMNS (a,b)    
  7. (    
  8.   PARTITION p01 VALUES LESS THAN (10,20),    
  9.   PARTITION p02 VALUES LESS THAN (20,30),    
  10.   PARTITION p03 VALUES LESS THAN (30,40),    
  11.   PARTITION p04 VALUES LESS THAN (40,MAXVALUE),    
  12.   PARTITION p05 VALUES LESS THAN (MAXVALUE,MAXVALUE)    
  13. );    
  14.  
  15. CREATE TABLE p2 (    
  16.   a INT,    
  17.   b INT,    
  18.   c INT   
  19. )    
  20. PARTITION BY RANGE COLUMNS (a,b)    
  21. (    
  22.   PARTITION p01 VALUES LESS THAN (10,10),    
  23.   PARTITION p02 VALUES LESS THAN (10,20),    
  24.   PARTITION p03 VALUES LESS THAN (10,30),    
  25.   PARTITION p04 VALUES LESS THAN (10,MAXVALUE),    
  26.   PARTITION p05 VALUES LESS THAN (MAXVALUE,MAXVALUE)    
  27. )  

There are also other examples of partition by range columns (a, B, c. Because I have been using MySQL 5.1 for a long time, I don't know much about the meaning of Multi-column partitions. What does LESS THAN () mean? What will happen if the next partition is less than (10, 20? On the contrary, what if it is (20, 30?

All these questions require an answer. Before answering these questions, they need to better understand what we are doing.

At the beginning, it may be a bit confusing. When all partitions have a value of different ranges, in fact, they only partition a column in the table, but this is not the case. In the following example

 
 
  1. CREATE TABLE p1_single (    
  2.   a INT,    
  3.   b INT,    
  4.   c INT   
  5. )    
  6. PARTITION BY RANGE COLUMNS (a)    
  7. (    
  8.   PARTITION p01 VALUES LESS THAN (10),    
  9.   PARTITION p02 VALUES LESS THAN (20),    
  10.   PARTITION p03 VALUES LESS THAN (30),    
  11.   PARTITION p04 VALUES LESS THAN (40),    
  12.   PARTITION p05 VALUES LESS THAN (MAXVALUE)    
  13. );  

It is different from the previous table p1. If you insert 10, 1, 1) in table p1, it will enter the first partition. On the contrary, in the p1_single table, it will enter the second partition because (10, 1) is smaller than (10, 10). If you only focus on the first value, you have not realized that you are comparing a tuple, instead of a single value.

Now let's analyze the most difficult part. What happens when you need to determine where a line should be placed? How do you determine the value of an operation similar to (10, 9) <(10, 10? The answer is actually very simple. When you sort them, use the same method to calculate the values of the two records.

 
 
  1. a=10    
  2. b=9    
  3. (a,b) < (10,10) ?    
  4. # evaluates to:    
  5. (a < 10)    
  6. OR   
  7. ((a = 10) AND ( b < 10))    
  8. # which translates to:    
  9. (10 < 10)    
  10. OR   
  11. ((1010 = 10) AND ( 9 < 10))  

If there are three columns, the expression will be longer, but not more complex. First, test the smaller than calculation on the first project. If two or more partitions match the calculation, then test the second project. If there are more than one candidate partition, test the third project.

The introduction of MySQL 5.5 Multi-column partitioning is here. I hope this introduction will help you.

Source: http://lujia35.iteye.com/blog/718899.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.