简体   繁体   中英

Partitioning of table in mysql for MYISAM eninge based on year

I am trying to partition the table based on the year range.

but i'm getting the following error "#1503 - A PRIMARY KEY must include all columns in the table's partitioning function".

Following is my query

CREATE TABLE IF NOT EXISTS `t2123` (
  `j_id` int(11) NOT NULL AUTO_INCREMENT,
  `u_id` int(11) NOT NULL,
  `w_id` int(5) NOT NULL,
  `p_id` int(5) NOT NULL,
  `s_p_id` int(5) NOT NULL,
  `p_t` tinyint(3) unsigned NOT NULL,
  `a_n` int(5) NOT NULL,    
  `type` enum('GP','NGP','PGP','PAGP') NOT NULL,
  `p_p` int(11) NOT NULL,
  `s_p` int(11) NOT NULL,
  `p_c` float NOT NULL,
  `s_c` float NOT NULL,
  `s_p_p_c` float NOT NULL DEFAULT '0',
  `g_d` date NOT NULL,
 `datetimes` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
  `c_c` double  DEFAULT '0',
  `c_m` double DEFAULT '0',
  `c_y` double  DEFAULT '0',
  `c_k` double  DEFAULT '0' ,
  `c_total` double  DEFAULT '0' ,
  `p_a` float  DEFAULT '0',
  PRIMARY KEY (`j_id`),
  UNIQUE KEY(j_id, g_d),

  KEY `u_id` (`u_id`),
  KEY `w_id` (`w_id`),
  KEY `p_id` (`p_id`),
  KEY `s_p_id` (`s_p_id`),
  KEY `a_n` (`a_n`),
  KEY `g_d` (`g_d`)  
) engine=myisam  PARTITION BY RANGE  (j_id + year(g_d)) (
    PARTITION t2_2012 VALUES LESS THAN (2012),
    PARTITION t2_2013 VALUES LESS THAN (2013)
);

Please suggest me how can I create the partition?

As the error message advises:

A PRIMARY KEY must include all columns in the table's partitioning function

Your partitioning function refers to j_id and g_d while your primary key only covers j_id .

By the way, your UNIQUE constraint is useless ( UNIQUE KEY(j_id, g_d) ) because j_id is already unique by definition (it is primary key).

In fact you probably want your primary key on (j_id, g_d)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM