mysql 5.6 分区与不分区的区别
mysql> CREATE TABLE t1 ( id INT, date DATETIME DEFAULT CURRENT_TIMESTAMP) ENGINE=Innodb;
Query OK, rows affected mysql> insert into t1 values(, '2013-05-23 12:59:39');
Query OK, row affected mysql> insert into t1 values(, '2013-05-23 12:59:43');
insert into t1 values(, '2013-05-23 12:59:44');
insert into t1 values(, '2013-07-04 19:35:45');
insert into t1 values(, '2014-04-04 19:35:45' );
insert into t1 values(, '2014-05-04 19:35:45' );
insert into t1 values(, '2015-05-04 19:35:45');
insert into t1 values(, '2015-05-05 19:35:45');
insert into t1 values(, '2017-05-05 19:35:45');
insert into t1 values(,'2018-05-05 19:35:45' );
Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected mysql> select * from t1;
+----+---------------------+
| id | date |
+----+---------------------+
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
+----+---------------------+
rows in set mysql> explain select * from t1;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
row in set mysql> EXPLAIN SELECT * FROM t1 WHERE date >= '2014-03-05 19:00:12' AND date <= '2016-03-05 18:45:12';
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
row in set mysql> CREATE TABLE t2 ( id INT, date DATETIME DEFAULT CURRENT_TIMESTAMP) ENGINE=Innodb
PARTITION BY RANGE (YEAR(date)) (
PARTITION p2013 VALUES LESS THAN(),
PARTITION p2014 VALUES LESS THAN(),
PARTITION p2015 VALUES LESS THAN(),
PARTITION p2016 VALUES LESS THAN(),
PARTITION p2017 VALUES LESS THAN(),
PARTITION p2099 VALUES LESS THAN MAXVALUE
) ;
Query OK, rows affected mysql> show create table t2;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`id` int() DEFAULT NULL,
`date` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (YEAR(date))
(PARTITION p2013 VALUES LESS THAN (2014) ENGINE = InnoDB,
PARTITION p2014 VALUES LESS THAN (2015) ENGINE = InnoDB,
PARTITION p2015 VALUES LESS THAN (2016) ENGINE = InnoDB,
PARTITION p2016 VALUES LESS THAN (2017) ENGINE = InnoDB,
PARTITION p2017 VALUES LESS THAN (2018) ENGINE = InnoDB,
PARTITION p2099 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */ |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
row in set mysql> SELECT table_name,partition_name,table_rows FROM information_schema.PARTITIONS WHERE table_schema=database() AND table_name='t2';
+------------+----------------+------------+
| table_name | partition_name | table_rows |
+------------+----------------+------------+
| t2 | p2013 | |
| t2 | p2014 | |
| t2 | p2015 | |
| t2 | p2016 | |
| t2 | p2017 | |
| t2 | p2099 | |
+------------+----------------+------------+
rows in set mysql> EXPLAIN SELECT * FROM t2;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
row in set mysql> insert into t2 select * from t1;
Query OK, rows affected
Records: Duplicates: Warnings: mysql> explain select * from t2;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
row in set mysql> select * from t2;
+----+---------------------+
| id | date |
+----+---------------------+
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
+----+---------------------+
rows in set mysql> SELECT table_name,partition_name,table_rows FROM information_schema.PARTITIONS WHERE table_schema=database() AND table_name='t2';
+------------+----------------+------------+
| table_name | partition_name | table_rows |
+------------+----------------+------------+
| t2 | p2013 | |
| t2 | p2014 | |
| t2 | p2015 | |
| t2 | p2016 | |
| t2 | p2017 | |
| t2 | p2099 | |
+------------+----------------+------------+
rows in set mysql> EXPLAIN PARTITIONS SELECT * FROM t2 WHERE date >= '2014-03-05 19:00:12' AND date <= '2016-03-05 18:45:12';
+----+-------------+-------+-------------------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------------------+------+---------------+------+---------+------+------+-------------+
| | SIMPLE | t2 | p2014,p2015,p2016 | ALL | NULL | NULL | NULL | NULL | | Using where |
+----+-------------+-------+-------------------+------+---------------+------+---------+------+------+-------------+
row in set mysql>

mysql 5.6 分区与不分区的区别的更多相关文章
- MySQL学习笔记十三:表分区
1.分区一般用于非常大的表,采用“分而治之”的策略,将一个很大的对象分成多个小对象进行管理,每个分区都是一个独立的对象. 分区使用分区键将数据根据范围值,特定列值或HASH值等规则分布在不同的分区中. ...
- Mysql --分区(4)List分区
LIST分区 LIST分区是建立离散的值列表告诉数据库特定的值属于哪个分区,LIST分区在很多方面类似于RANGE分区,区别在LIST分区是从属于一个枚举列表的值得集合,RANGE分区是从属于一个连续 ...
- Mysql --分区(3)range分区
3.分区类型 RANGE分区 按照range分区的表是利用取值范围将数据分成分区,区间要连续并且不能互相重叠,使用values less than操作符进行分区定义 CREATE TABLE tnp ...
- mysql的分区技术(建立分区)
-- mysql建立表分区,使用range方法建立: create table t_range( id int(11), money int(11) unsigned not null, date d ...
- mysql表分区、查看分区
原文地址:http://blog.csdn.net/feihong247/article/details/7885199 一. mysql分区简介 数据库分区 数据库分区是一种物理数据库设 ...
- mysql分区之range分区
随着互联网的发展,各方面的数据越来越多,从最近两年大数据越来越强的呼声中就可见一斑. 我们所做的项目虽算不上什么大项目,但是由于业务量的问题,数据也是相当的多. 数据一多,就很容易出现性能问题,而为了 ...
- MySQL 横向表分区之RANGE分区小结
MySQL 横向表分区之RANGE分区小结 by:授客 QQ:1033553122 目录 简介 1 RANGE分区 1 创建分区表 1 查看表分区 2 新增表分区 2 新增数据 3 分区表查询 3 删 ...
- mysql数据库优化(三)--分区
mysql的分区,分表 分区:把一个数据表的文件和索引分散存储在不同的物理文件中. 特点:业务层透明,无需任何修改,即使从新分表,也是在mysql层进行更改(业务层代码不动) 分表:把原来的表根据条件 ...
- mysql 表分区 查看表分区 修改表分区
原文地址:http://blog.csdn.net/feihong247/article/details/7885199 一. mysql分区简介 数据库分区 数据库分区是一种物理数据库设 ...
- mysql分区表之二:MySQL的表的四种分区类型介绍
一.什么是表分区 通俗地讲表分区是将一大表,根据条件分割成若干个小表.mysql5.1开始支持数据表分区了.如:某用户表的记录超过了600万条,那么就可以根据入库日期将表分区,也可以根据所在地将表分区 ...
随机推荐
- java设计模式--单例
GOF23(group of four)---由4个大牛总结的JAVA23种常用的设计模式,归根结底都是为了代码的可扩展性. 设计模式中一种比较重要的思想就是:开闭原则,尽量做到对扩展开放,对修改关闭 ...
- vsftpd服务安装配置
服务器:centos6.5 32位 192.168.1.114 1.安装 yum -y install vsftpd 2.启动 /etc/init.d/vsftpd start 3.配置 配置文件 ...
- 内存不够怎么办? 1.5.1 关于隔离 1.5.2 分段(Segmention) 1.5.3 分页(Paging)
小结: 1. 内存不够怎么办?1.5.1 关于隔离1.5.2 分段(Segmention)1.5.3 分页(Paging) <程序员的自我修养——链接.装载与库>
- PHP之后期静态绑定
PHP后期静态绑定的(late static bindings) 理解PHP延迟静态绑定 static::中的static其实是运行时所在类的别名,并不是定义类时所在的那个类名.这个东西可以实现在父类 ...
- docker disable restart--run privileged
--restart=unless-stopped option, as @Shibashis mentioned, or update the restart policy (this require ...
- Chap3:文件系统中跳转[The Linux Command Line]
1 introduce the following commands pwd - Print name of current working directory cd-Change directory ...
- pip list 和 pip freeze
https://blog.csdn.net/vitaminc4/article/details/76576956 Pip’s documentation statespip descripti ...
- CF891C Envy 最小生成树/虚树
正解:最小生成树/虚树 解题报告: 传送门! sd如我就只想到了最暴力的想法,一点儿优化都麻油想到,,,真的菜到爆炸了QAQ 然后就分别港下两个正解QAQ 法一,最小生成树 这个主要是要想到关于最小生 ...
- logback logback.xml常用配置详解(二)<appender>
转自:http://aub.iteye.com/blog/1101260 logback 常用配置详解(二) <appender> <appender>: <append ...
- Codefoces 432C Prime Swaps(数论+贪心)
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u011328934/article/details/26094917 题目连接:Codefoces ...