Question

I am trying to add partitioning on a MySQL database table schema for my database table is as

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_group_id` tinyint(3) unsigned NOT NULL DEFAULT '2',
  `username` varchar(50) NOT NULL,
  `email` varchar(80) NOT NULL,
  `password` varchar(50) NOT NULL,
  `first_name` varchar(25) DEFAULT NULL,
  `last_name` varchar(25) DEFAULT NULL,
  `gender` enum('m','f','u') NOT NULL DEFAULT 'u' COMMENT 'm=>Male, f=>Female, u=>Unspecified',
  `profile_image` varchar(255) DEFAULT NULL,
  `reset_key` varchar(50) DEFAULT NULL,
  `block` enum('y','n') NOT NULL DEFAULT 'n' COMMENT 'y=>blocked, n=>notblocked',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=1 ;

When I run following partitioning query on table

ALTER TABLE users PARTITION BY RANGE(id) (
    PARTITION p0 VALUES LESS THAN (200000),
    PARTITION p1 VALUES LESS THAN (400000),
    PARTITION p2 VALUES LESS THAN (600000),
    PARTITION p3 VALUES LESS THAN (800000),
    PARTITION p4 VALUES LESS THAN (1000000),
    PARTITION p5 VALUES LESS THAN (1200000),
    PARTITION p6 VALUES LESS THAN (1400000),
    PARTITION p7 VALUES LESS THAN (1600000),
    PARTITION p8 VALUES LESS THAN (1800000),
    PARTITION p9 VALUES LESS THAN (2000000)
);

it is giving me error message as

#1503 - A UNIQUE INDEX must include all columns in the table's partitioning function enter image description here

I am using MySQL Community Server - 5.5.16

can please anybody tell me what is error in my query?

Was it helpful?

Solution 2

after changing indexing on table it is working

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `user_group_id` tinyint(3) unsigned NOT NULL DEFAULT '2',
  `username` varchar(50) NOT NULL,
  `email` varchar(80) NOT NULL,
  `password` varchar(50) NOT NULL,
  `first_name` varchar(25) DEFAULT NULL,
  `last_name` varchar(25) DEFAULT NULL,
  `gender` enum('m','f','u') NOT NULL DEFAULT 'u' COMMENT 'm=>Male, f=>Female, u=>Unspecified',
  `profile_image` varchar(255) DEFAULT NULL,
  `reset_key` varchar(50) DEFAULT NULL,
  `modify_username` enum('0','1') DEFAULT '0',
  `block` enum('y','n') NOT NULL DEFAULT 'n' COMMENT 'y=>blocked, n=>notblocked',
  `status` enum('0','1') DEFAULT '0',
  `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `modified` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `id_username_email` (`id`,`username`,`email`),
  KEY `username` (`username`)
  KEY `email` (`email`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC

OTHER TIPS

The docs says it all :

This section discusses the relationship of partitioning keys with primary keys and unique keys. The rule governing this relationship can be expressed as follows: All columns used in the partitioning expression for a partitioned table must be part of every unique key that the table may have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top