MySQL分区与传统的分库分表
则下面的查询没有操作分区,由于partitions中包括了全部的分区: mysql> explain partitions select * from salaries where salary > 100000G; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: salaries partitions: p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18 type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 2835486 Extra: Using where 只有在where前提中插手分区列才气起到浸染,过滤掉不必要的分区: mysql> explain partitions select * from salaries where salary > 100000 and from_date > '1998-01-01'G; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: salaries partitions: p15,p16,p17,p18 type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 1152556 Extra: Using where 与平凡搜刮一样,在运算符左侧行使函数将使分区过滤失效,纵然与分区函数想同也一样: mysql> explain partitions select * from salaries where salary > 100000 and year(from_date) > 1998G; *************************** 1. row *************************** id: 1 select_type: SIMPLE table: salaries partitions: p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18 type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 2835486 Extra: Using where 分区和分表的较量传统分表后,count、sum等统计操纵只能对全部切分表举办操纵后之后在应用层再次计较得出最后统计数据。而分区表则不受影响,可直接统计。 Queries involving aggregate functions such as SUM() and COUNT() can easily be parallelized. A simple example of such a query might be SELECT salesperson_id, COUNT(orders) as order_total FROM sales GROUP BY salesperson_id;. By “parallelized,” we mean that the query can be run simultaneously on each partition, and the final result obtained merely by summing the results obtained for all partitions. 分区对原体系窜改最小,分区只涉及数据库层面,应用层不必要做出窜改。 分区有个限定是主表的全部独一字段(包罗主键)必需包括分区字段,而分表没有这个限定。 分表包罗垂直切分和程度切分,而分区只能起到程度切分的浸染。 转自:http://www.jianshu.com/p/89311703b320 (编辑:湖南网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |