3

我有以下当前已分区的 MySQL 表。

我想在“message_read”键上添加子分区 - 这是为了优化通过分区搜索未读消息。

CREATE TABLE `messages` (
  `pid` int(50) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
  `userid1` int(10) unsigned NOT NULL COMMENT 'Message Sender',
  `userid2` int(10) unsigned NOT NULL COMMENT 'Message Receiver',
  `message` text NOT NULL COMMENT 'Actual Message',
  `message_read` tinyint(1) NOT NULL DEFAULT '0' COMMENT '0=Not Read & 1=Read',
  `datetime` datetime NOT NULL COMMENT 'Date Time',
  PRIMARY KEY (`pid`,`datetime`),
  KEY `userid1` (`userid1`),
  KEY `userid2` (`userid2`),
  KEY `message_read` (`message_read`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (TO_DAYS(`datetime`))
(PARTITION p0 VALUES LESS THAN (735234) ENGINE = InnoDB,
 PARTITION p1 VALUES LESS THAN (735265) ENGINE = InnoDB,
 PARTITION p2 VALUES LESS THAN (735293) ENGINE = InnoDB,
 PARTITION p3 VALUES LESS THAN (735324) ENGINE = InnoDB,
 PARTITION p4 VALUES LESS THAN (735354) ENGINE = InnoDB,
 PARTITION p5 VALUES LESS THAN (735385) ENGINE = InnoDB,
 PARTITION p6 VALUES LESS THAN (735415) ENGINE = InnoDB) */

当前分区在日期时间戳上。我如何添加到“message_read”的子分区中?

谢谢你

4

2 回答 2

0

您需要将 message_read 添加到主键。然后(您可以使用哈希或键进行子分区):

CREATE TABLE `messages` (
  `pid` INT(50) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
  `userid1` INT(10) UNSIGNED NOT NULL COMMENT 'Message Sender',
  `userid2` INT(10) UNSIGNED NOT NULL COMMENT 'Message Receiver',
  `message` TEXT NOT NULL COMMENT 'Actual Message',
  `message_read` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '0=Not Read & 1=Read',
  `datetime` DATETIME NOT NULL COMMENT 'Date Time',
  PRIMARY KEY (`pid`,`datetime`, message_read),
  KEY `userid1` (`userid1`),
  KEY `userid2` (`userid2`),
  KEY `message_read` (`message_read`)
) ENGINE=INNODB DEFAULT CHARSET=utf8
PARTITION BY RANGE (TO_DAYS(`datetime`))
SUBPARTITION BY HASH (message_read)
(PARTITION p0 VALUES LESS THAN (735234)(SUBPARTITION s0, SUBPARTITION s1),
 PARTITION p1 VALUES LESS THAN (735265)(SUBPARTITION s2, SUBPARTITION s3),
 PARTITION p2 VALUES LESS THAN (735293)(SUBPARTITION s4, SUBPARTITION s5),
 PARTITION p3 VALUES LESS THAN (735324)(SUBPARTITION s6, SUBPARTITION s7),
 PARTITION p4 VALUES LESS THAN (735354)(SUBPARTITION s8, SUBPARTITION s9),
 PARTITION p5 VALUES LESS THAN (735385)(SUBPARTITION s10, SUBPARTITION s11),
 PARTITION p6 VALUES LESS THAN (735415)(SUBPARTITION s12, SUBPARTITION s13)) ;

希望这就是你要找的。

谢谢,你

于 2013-03-13T15:59:15.607 回答
0

在这种情况下 - 由于每个分区分为两部分,mysql如何将记录划分给子分区?毕竟mysql不知道每个分区/子分区会输入多少条记录

于 2013-05-13T09:34:19.533 回答