Dhileepan
Dhileepan

Reputation: 2047

A primary must include all columns in the table's partitioning location error?

I tried to create a table with range partitioning. But it shows the following error:

A primary must include all columns in the table's partitioning location.

This is my SQL statement:

CREATE TABLE `tbl_emp_confirmation` (
  `fld_id` int(11) NOT NULL AUTO_INCREMENT,
  `fldemp_id` varchar(100) DEFAULT NULL,
  `fldempname` varchar(100) DEFAULT NULL,
  `fldjoindate` varchar(100) DEFAULT NULL,
  `fldconfirmdate` Date NOT NULL,
  `fldresigndate` varchar(100) DEFAULT NULL,
  `fldstatus` varchar(50) DEFAULT NULL,
  `fldcon_status` varchar(100) DEFAULT NULL,
  UNIQUE KEY `fld_id` (`fld_id`),
  KEY `in_empconfirmation` (`fldemp_id`,`fldempname`,`fldjoindate`,`fldconfirmdate`)
  ) PARTITION BY RANGE ( Month(fldconfirmdate))
  (PARTITION p_JAN VALUES LESS THAN (TO_DAYS('2011-01-01')),
 PARTITION p_FEB VALUES LESS THAN (TO_DAYS('2011-02-01')),
 PARTITION p_MAR VALUES LESS THAN (TO_DAYS('2011-03-01')),
 PARTITION p_APR VALUES LESS THAN (TO_DAYS('2011-04-01')),
 PARTITION p_MAY VALUES LESS THAN (TO_DAYS('2011-05-01')),
 PARTITION p_MAX VALUES LESS THAN MAXVALUE );

Upvotes: 24

Views: 51014

Answers (1)

jmoro
jmoro

Reputation: 338

You are partitioning data using fldconfirmdate, which is part of your PK, but not a part of your UNIQUE KEY fld_id.

This is extracted from the MySQL manual:

In other words, every unique key on the table must use every column in the table's partitioning expression.

Which means that, making fldconfirmdate to be a part of your UNIQUE KEY 'fld_id´ will solve the problem.

CREATE TABLE `tbl_emp_confirmation` (
  `fld_id` int(11) NOT NULL AUTO_INCREMENT,
  `fldemp_id` varchar(100) DEFAULT NULL,
  `fldempname` varchar(100) DEFAULT NULL,
  `fldjoindate` varchar(100) DEFAULT NULL,
  `fldconfirmdate` Date NOT NULL,
  `fldresigndate` varchar(100) DEFAULT NULL,
  `fldstatus` varchar(50) DEFAULT NULL,
  `fldcon_status` varchar(100) DEFAULT NULL,
  UNIQUE KEY `fld_id` (`fld_id`, `fldconfirmdate`),
  KEY `in_empconfirmation` (`fldemp_id`,`fldempname`,`fldjoindate`,`fldconfirmdate`)
  ) PARTITION BY RANGE ( Month(fldconfirmdate))
  (PARTITION p_JAN VALUES LESS THAN (TO_DAYS('2011-01-01')),
 PARTITION p_FEB VALUES LESS THAN (TO_DAYS('2011-02-01')),
 PARTITION p_MAR VALUES LESS THAN (TO_DAYS('2011-03-01')),
 PARTITION p_APR VALUES LESS THAN (TO_DAYS('2011-04-01')),
 PARTITION p_MAY VALUES LESS THAN (TO_DAYS('2011-05-01')),
 PARTITION p_MAX VALUES LESS THAN MAXVALUE );

Upvotes: 22

Related Questions