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万条,那么就可以根据入库日期将表分区,也可以根据所在地将表分区 ...
随机推荐
- Mysql thread 与 OS thread
测试环境信息如下: OS:Ubuntu 16.04 LTS Mysql:Mysql 5.7.18,使用docker images运行的实例 Mysql如何处理client请求 在Mysql中,连接管理 ...
- [knowledge] big data things
http://hadoop.apache.org/ https://spark.apache.org/ https://nifi.apache.org/ https://www.cloudera.co ...
- 12.2RAC搭建记录
12.2RAC环境搭建记录 安装前资源检查 资源限制要求/etc/security/limits.conf Table 6-1 Installation Owner Resource Limit Re ...
- jquery基础学习之动画篇(四)
一,动画效果 hide() show() 隐藏与显示 hide(options) 隐藏 对应display:none,有参数就会变成动画, $(document).click(function () ...
- kubernetes的Controller Manager
1. Controller Manager简介 Controller Manager作为集群内部的管理控制中心,负责集群内的Node.Pod副本.服务端点(Endpoint).命名空间(Namespa ...
- java Scanner和Random的Demo
import java.util.Scanner;//导入包 import java.util.Random; public class ScannerDemo{ public static void ...
- 洛谷P3602 Koishi Loves Segments 贪心
正解:贪心 解题报告: 传送门! 首先在学习贪心的入门题的时候我们就知道,当x=1的时候,也就是每条线段不能相交的时候的做法——就按右端点排序然后能选就选,也就是会议安排问题,原因显然?就你选右端点更 ...
- 天梯赛训练2 7-8 矩阵A乘以B
知道矩阵A*B的规则按照规则来做就好了 #include <bits/stdc++.h>#include <stdio.h>using namespace std;int a[ ...
- nodejs 学习四 处理回调地狱
面对下面回调,你面对这样代码,你心里难道不百万只羊驼吗? nodejs 提供了util.promisify方法,来解决这类问题.(类似es6 种是提供了Promise的方法). const fs = ...
- intellij idea建立maven项目
配置jdk 配置mvn http://jingyan.baidu.com/article/d8072ac45d3660ec94cefd51.html 右键“计算机”,选择“属性”,之后点击“高级系统设 ...