我有一个名为“ transaction”的innoDB表,具有约150万行。我想对该表进行分区(可能在“ gas_station_id”列上,因为它在联接查询中使用了很多),但是我在《MySQL 5.7参考手册》中已经读到了
该表的分区表达式中使用的所有列都必须是该表可能具有的每个唯一键(包括任何主键)的一部分。
我有两个问题:
ALTER TABLE transaction PARTITION BY LIST(gas_station_id) ( PARTITION p1 VALUES IN (9001), PARTITION p2 VALUES IN (9002),.....
)KEY
,但收到以下错误(我认为是因为id并非所有唯一键的一部分。):#1053-唯一索引必须在表的分区功能中包含所有列
这是“交易”表的结构:
编辑,这是SHOW CREATE TABLE显示的内容:
CREATE TABLE `transaction` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`terminal_transaction_id` int(11) NOT NULL,
`fuel_terminal_id` int(11) NOT NULL,
`fuel_terminal_serial` int(11) NOT NULL,
`xboard_id` int(11) NOT NULL,
`gas_station_id` int(11) NOT NULL,
`operator_id` varchar(16) NOT NULL,
`shift_id` int(11) NOT NULL,
`xboard_total_counter` int(11) NOT NULL,
`fuel_type` tinyint(2) NOT NULL,
`start_fuel_time` int(11) NOT NULL,
`end_fuel_time` int(11) DEFAULT NULL,
`preset_amount` int(11) NOT NULL,
`actual_amount` int(11) DEFAULT NULL,
`fuel_cost` int(11) DEFAULT NULL,
`payment_cost` int(11) DEFAULT NULL,
`purchase_type` int(11) NOT NULL,
`payment_ref_id` text,
`unit_fuel_price` int(11) NOT NULL,
`fuel_status_id` int(11) DEFAULT NULL,
`fuel_mode_id` int(11) NOT NULL,
`payment_result` int(11) NOT NULL,
`card_pan` varchar(20) DEFAULT NULL,
`state` int(11) DEFAULT NULL,
`totalizer` int(11) NOT NULL DEFAULT '0',
`shift_start_time` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `terminal_transaction_id` (`terminal_transaction_id`,`fuel_terminal_id`,`start_fuel_time`) USING BTREE,
KEY `start_fuel_time_idx` (`start_fuel_time`),
KEY `fuel_terminal_idx` (`fuel_terminal_id`),
KEY `xboard_idx` (`xboard_id`),
KEY `gas_station_id` (`gas_station_id`) USING BTREE,
KEY `purchase_type` (`purchase_type`) USING BTREE,
KEY `shift_start_time` (`shift_start_time`) USING BTREE,
KEY `fuel_type` (`fuel_type`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1665335 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT
简短答案:请勿使用PARTITION。让我们看一下查询,以帮助加快查询速度。
长答案:
SHOW CREATE TABLE
和慢SELECT
。PRIMARY
或UNIQUE
键的末尾。您将失去唯一性测试。本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句