我正在尝试通过删除冗余键来优化表的架构。percona 工具包和 common_schema 都告诉我以下键是多余的:
mysql> SELECT redundant_index_name, sql_drop_index FROM redundant_keys;
+----------------------+-------------------------------------------------------------------------------+
| redundant_index_name | sql_drop_index |
+----------------------+-------------------------------------------------------------------------------+
| deviceName | ALTER TABLE `reporting`.`tbCardData` DROP INDEX `deviceName` |
+----------------------+-------------------------------------------------------------------------------+
1 rows in set (0.18 sec)
mysql> show create table `reporting`.`tbCardData`;
CREATE TABLE `tbCardData` (
`pkCardDataId` bigint(12) unsigned NOT NULL AUTO_INCREMENT,
`deviceName` varchar(64) DEFAULT NULL,
`shelfId` smallint(3) unsigned DEFAULT NULL,
`cardId` smallint(3) unsigned DEFAULT NULL,
`cardName` varchar(64) DEFAULT NULL,
`cardType` smallint(3) unsigned DEFAULT NULL,
`cardSubType` smallint(3) unsigned DEFAULT NULL,
`cardSpareGroupId` smallint(3) unsigned DEFAULT NULL,
`cardSerialNum` varchar(64) DEFAULT NULL,
`cardCarrierSerialNum` varchar(64) DEFAULT NULL,
`dom` tinyint(2) unsigned NOT NULL DEFAULT '0',
`updateTime` int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`pkCardDataId`),
UNIQUE KEY `devchascarddom` (`deviceName`,`shelfId`,`cardId`,`dom`),
KEY `deviceName` (`deviceName`),
KEY `dom` (`dom`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
我知道 deviceName Key 和唯一键 devchascarddom 共享最左边的属性 deviceName,但在我看来唯一键出现一次,而列表中有几个 deviceName。我想我要说的是,在这里删除 Key deviceName 对我来说似乎没有意义,但我不是 mysql 专家——我应该放弃它还是这只是这些工具向我报告的方式'将不得不丢弃?