抱歉发了这么长的帖子!
我有一个包含约30个表的数据库(InnoDB引擎).其中只有两个表,即"transaction"和"shift"相当大(第一个表有150万行,而shift表有23k行).现在一切正常,我对当前的数据库大小没有问题.
然而,我们将有一个类似的数据库(相同的数据类型、设计等等)但是要大得多,例如,"transaction"表将有大约1 billion records个(每天大约230万个事务),我们正在考虑如何在MySQL中处理如此大量的数据?(它是读写密集型的).我阅读了很多相关帖子,想看看Mysql(更具体地说是InnoDB引擎)能否在数十亿条记录上表现良好,但我仍然有一些问题.以下是我读过的一些相关帖子:
- Can MySQL reasonably perform queries on billions of rows?
- Is InnoDB (MySQL 5.5.8) the right choice for multi-billion rows?
- Best data store for billions of rows
- How big can a MySQL database get before performance starts to degrade
- Why MySQL could be slow with large tables?
- Can Mysql handle tables which will hold about 300 million records?
到目前为止,我对提高超大表性能的理解是:
- (对于我的innoDB表)增加
innodb_buffer_pool_size
(例如,最多80%的RAM). - 在表上有适当的索引(在查询中使用EXPLAN)
- 对表进行分区
- MySQL分片或集群
以下是我的问题/困惑:
关于分区,我怀疑我们是否应该使用它.一方面,很多人建议在桌子很大的时候提高性能.另一方面,我读过很多帖子,说它不会提高查询性能,也不会让查询运行得更快(例如,here和here).此外,我在MySQL Reference Manual中读到InnoDB foreign keys and MySQL partitioning are not compatible(我们有外键).
关于索引,目前它们的性能很好,但据我所知,对于非常大的表,索引更具限制性(正如Kevin Bedell在他的答案here中提到的).此外,索引加快了读取速度,同时降低了写入速度(插入/更新).那么,对于新的类似项目,我们将有这么大的数据库,我们应该首先插入/加载所有数据,然后创建索引吗?(以加快插入速度)
如果我们不能对我们的大表("事务"表)使用分区,那么有什么替代选项可以提高性能?(MySQl变量设置除外,例如
innodb_buffer_pool_size
).我们应该使用Mysql集群吗?(我们也有很多加入)
EDIT
这是我们最大的名为"transaction"的表的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` text NOT NULL,
`shift_id` int(11) NOT NULL,
`xboard_total_counter` int(11) NOT NULL,
`fuel_type` int(11) 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` text,
`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
谢谢你抽出时间,