Restrictions on primary key constraints in Mysql partition tables

Source: Internet
Author: User

Mysql partition tables have certain restrictions on primary key constraints. The following describes the restrictions on primary key constraints for Mysql partition tables in Mysql for your reference.

Restrictions on Partitioning Keys, Primary Keys, and Unique Keys:

In Mysql 5.1, the unique constraints of a partition table are clearly defined. Each unique constraint must contain the partition key of the Mysql Partition Table and the primary key constraint ).
This sentence may not be easy to understand. Let's do a few experiments:

 
 
  1. CREATE TABLE t1    
  2. (      id INT NOT NULL,               
  3.        uid INT NOT NULL,         
  4.        PRIMARY KEY (id)  
  5. )  
  6. PARTITION BY RANGE (id)     
  7. (PARTITION p0 VALUES LESS THAN(5) ENGINE = INNODB,   
  8. PARTITION p1 VALUES LESS THAN(10) ENGINE = INNODB 
  9. );   
  10.  
  11. CREATE TABLE t1     
  12. (      id INT NOT NULL,  
  13.        uid INT NOT NULL,         
  14.        PRIMARY KEY (id)  
  15. )  
  16. PARTITION BY RANGE (id)     
  17. (PARTITION p0 VALUES LESS THAN(5) ENGINE = MyISAM DATA DIRECTORY='/tmp'INDEX DIRECTORY='/tmp',   
  18. PARTITION p1 VALUES LESS THAN(10) ENGINE = MyISAM DATA DIRECTORY='/tmp' INDEX DIRECTORY='/tmp' 
  19. );   
  20.  
  21. mysql> CREATE TABLE t1         
  22.      -> (      id INT NOT NULL,            
  23.      ->        uid INT NOT NULL,   
  24.      ->        PRIMARY KEY (id),      
  25.      ->        UNIQUE KEY (uid)      
  26.      -> )      
  27.      -> PARTITION BY RANGE (id)        
  28.      -> (PARTITION p0 VALUES LESS THAN(5),     
  29.      ->  PARTITION p1 VALUES LESS THAN(10)     
  30.      -> );  
  31. ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function  


 

MySQL environment variable configuration instructions

Example of defining MySQL transactions

Mysql Stored Procedure FAQs

Example of creating a MySQL Stored Procedure

Use of mysql ifnull Functions

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.