Mysql Partition 理论知识总结
简述:
本文内容主要 Giuseppe Maxia 曾在Mysql Conference & Expo 2010发表关于 <Mysql Partition in Mysql 5.1 & 5.5> 经由整理后的内容,原文在下面的Presentation URL,本文用于自身学习 。我自身关于分区与未分区的测试,打算发表于另一篇博文。
Giuseppe Maxia Blog
http://datacharmer.blogspot.com/
http://datacharmer.com/
Presentation URL http://en.oreilly.com/mysql2010/public/schedule/detail/12431
------------------------------------------------------------------
1.why partition
数据量太大,以至于indexes大小超出RAM能的保存范围时
2.物理分区与逻辑分区的区别:
好比一张纸查一小块区域,物理分区是分成各碎片,逻辑分区则是折叠起来隐藏不需要的部分
------------------------------------------------------------------
3.在5.1中解析分区表的查询
mysql> explain partitions select * from click_statistics where add_time between "2011-07-25" and "2011-07-26" ;
+----+-------------+---------------+-----------------+-------+---------------+--------------+---------+------+-------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------------+-----------------+-------+---------------+--------------+---------+------+-------+-------------+
| 1 | SIMPLE | statistics | p201012,p201107 | range | idx_reg_time | idx_reg_time | 8 | NULL | 49180 | Using where |
+----+-------------+---------------+-----------------+-------+---------------+--------------+---------+------+-------+-------------+
1 row in set (0.03 sec)
.查询partition信息
select partition_name part,
from_days(partition_expression) expr,
partition_descriptiton val
from information_schema.partitions
where table_name='t1' ;
------------------------------------------------------------------
4.各分区类型的介绍
.Partition ranges must be listed smallest to greatest and must be integers
.The primary key must include all columns in the partitioning expression.
.HASH(expr) must return an integer
.HASH partition-mysql decides row placement using mod;
.Key partition,unlike HASH,the partitioning expression does not have to be an integer,the hashing algorithm is similar to PASSWORD();
.RANGE,LIST and HASH must use integer values.
.No stored functions,stored procedures,or UDFs
------------------------------------------------------------------
5.RANGE,LIST and HASH 分区支持的函数
ABS()
CEILING()
DAY()
DAYOFMONTH()
DAYOFWEEK()
DAYOFYEAR()
DATEDIFF()
EXTRACT()
FLOOR()
HOUR()
MICROSECOND()
MINUTE()
MOD()
MONTH()
QUARTER()
SECOND()
TIME_TO_SEC()
TO_DAYS()
WEEKDAY()
YEAR()
YEARWEEK()
-------------------------------------------------------------------
6.
.Indexed are partitioned along with the data
.partition keys must be unique constraint
.MYISAM - When partition , DATA DIRECTORY and INDEX DIRECTORY parameter can be used per partition
.INNODB - if innodb_file_per_table is not set, the partitions are in the centralized table space,if set each partition has an .ibd file
.when need partition by date , thinking ?
可取方案 YEAR(date_column) / TO_DAYS(date_column) 意义明了,查询条件确定能使用到分区
------------------------------------------------------------------
7.Advanced partitions
(to differentiate roles on master and slave - fast insert on the master with HASH partitions ,fast statistics in a slave with range partitions)
. Subpartitioning
RANGE or LIST partitions can be subpartitioned with HASH or KEY
.当没有匹配的partition分配时 ERROR 1526,insert 失败,此时partitions as constraints
------------------------------------------------------------------
8.Benchmarking partition
(If needed,remove PK from partitioned table)
(restart the server before each test)
(Do NOT mix partitioned and unpartitioned table in ther same server)
(Measure more than once)
Innodb
disk usage(expect more than myisam)
CPU usage
MyISAM
2 file handles per partition
If more than one partitioned table,count total file handles
Archive
CPU usage
memory usage
------------------------------------------------------------------
9.Partitons Maintenance
.For RANGE partitioning,partitions can only be added to the end。最末尾,加上值更大的类别
.For LIST partitioning,partitions can be added that use different values 新增一个类别
.For HASH and KEY partitioning,Adding partitions will reorganize the data using the hashing algorithm. 重组
.For HASH and KEY partitioning,DROP PARTITION does not work,instead,use coalesce to merge partititons, 并非删除记录,而是分区数量减小,
ALTER TABLE ... COALESCE PARTITION 2;
.REORGANIZE PARTITION - split or merge partitions
.REMOVE PARTITIONING - reverts to an unpartitioned table
.CHECK PARTITION - same as check table
.REPAIR PARTITION - same as repair table
.ANALYZE PARTITION -same as analyze table
.OPTIMIZE PARTITION - same as optimize table
.A perl script that creates partitioning statements
.mysqldump_partition_backup
.drop_oldest_partition (procedure+event per month)
.check & repair test - via move .MYI
------------------------------------------------------------------
10.实验部分 (略)
Partitions with InnoDB - Slower than MyISAM / But more robust / Requires more storage
相同记录,不同表引擎的数据文件大小
group 1 : innodb / myisam / archive
group 2 : innodb partititoned(whole) / (file per table) /myisam partitioned / archive partitoned
Benchmark results:
Partitions with InnoDB
Partitions with Archive
wget http://launchpad.net/mysql-sandbox/mysql-sandbox-3/mysql-sandbox-3/+download/MySQL-Sandbox-3.0.15.tar.gz
wget http://launchpad.net/test-db/employees-db-1/1.0.6/+download/employees_db-dump-files-1.0.5.tar.bz2
-----------------------------------
leveraging replication 杠杆作用- 以不同组合的复制架构 满足不同的使用需求
Master[INNODB NOT PARTITIONED]"concurrent insert" --- |
|---- > Slave1 [INNODB NOT PARTITIONED] "concurrent read"
|------ > Slave2 [INNODB PARTITIONED BY RANGE]"concurrent batch processing"
|-------- > Slave3 [MyISAM PARTITIONED BY RANGE] "large batch processing"
解析架构1: 满足大并发读写 ,又满足并发批处理,大型批处理
Master[INNODB PARTITIONED BY HASH]"concurrent insert" ----|
|---- > Slave1[INNODB NOT PARTITIONED]"concurrent read"
|------ > Slave2[MYISAM PARTITIONED BY RANGE]"large batch processing"
解析架构2: 架构2在架构1的基础上削剪了slave2
Master[INNODB PARTITIONED BY HASH]"concurrent insert" ----|
|---- > Slave1 [ARCHIVE PARTITIONED BY RANGE(locations)]"dimensional processing"
|------ > Slave2 [ARCHIVE PARTITIONED BY RANGE(date)]"dimensional processing"
|------ > Slave3 [ARCHIVE PARTITIONED BY RANGE(product)]"dimensional processing"
解析架构3: 各个按不同的标准分区,以满足快速根据不同条件查询,且使用Archive引擎
-----------------------------------
Mysql 5.5对于partition的增强
PARTITION BY RANGE COLUMNS ,并且可以按两列来分区,典型的如gender+hire_date,男分N个,女分N个
PARTITION BY LIST COLUMNS ,
TO_SECONDS
Mysql Partition 理论知识总结的更多相关文章
- Mysql优化理论知识
参考文章 http://blog.51cto.com/lizhenliang/2095526 ()硬件优化 如果有条件一定要SSD固态硬盘代替SAS机械硬盘,将RAID级别调整为RAID1+,相对于R ...
- MySQL系列理论知识
内容: 1.视图 2.触发器 3.事务 4.存储过程 5.内置函数 6.流程控制 7.索引与慢查询优化 —————————————————————————————— 1.视图: 1.视图是什么: 视图 ...
- 商业智能BI-基础理论知识总结 ZT
因为要加入一个BI项目,所以最近在研究BI相关的知识体系,由于这个方面的知识都是比较零散,开始都很多概念,不知道从何入手,网上找的资料也不多,特别是实战案例方面更少,这里还是先把理论知识理解下吧,分享 ...
- 小D课堂 - 新版本微服务springcloud+Docker教程_3-02CAP理论知识
笔记 2.分布式应用知识CAP理论知识 简介:讲解分布式核心知识CAP理论 CAP定理: 指的是在一个分布式系统中,Consistency(一致性). Availabi ...
- js中函数的一些理论知识
函数的一些理论知识 1. 函数: 执行一个明确的动作并提供一个返回值的独立代码块.同时函数也是javascript中的一级公民(就是函数和其它变量一样). 2.函数的 ...
- 用VC进行COM编程所必须掌握的理论知识
一.为什么要用COM 软件工程发展到今天,从一开始的结构化编程,到面向对象编程,再到现在的COM编程,目标只有一个,就是希望软件能象积方块一样是累起来的,是组装起来的,而不是一点点编出来的.结构化编程 ...
- 图形学理论知识 BRDF 双向反射分布函数(Bidirectional Reflectance Distribution Function)
图形学理论知识 BRDF 双向反射分布函数 Bidirectional Reflectance Distribution Function BRDF理论 BRDF表示的是双向反射分布函数(Bidire ...
- TestNG学习-001-基础理论知识
此 文主要讲述用 TestNG 的基础理论知识,TestNG 的特定,编写测试过程三步骤,与 JUnit4+ 的差异,以此使亲对 TestNG 测试框架能够有一个简单的认知. 希望能对初学 TestN ...
- mysql Partition(分区)初探
mysql Partition(分区)初探 表数据量大的时候一般都考虑水平拆分,即所谓的sharding.不过mysql本身具有分区功能,可以实现一定程度 的水平切分. mysql是具有MERG ...
随机推荐
- JS火狐与IE的差别
function isIE(){ //ie? ) return true; else return false; } if(!isIE()){ //firefox innerText define H ...
- 3.linux安装vsftpd服务
1.首先查看本地是否安装了vsftpd rpm -qa |grep vsftpd 2.安装vsftpd: yum install vsftpd 3.查询当前ftp状态 chkconfig --list ...
- Linux基础命令(三)
一.常用命令—文件目录类命令 1.ls 列出指定或默认目录的文件信息 使用形式: ls [选项] [目录名] 实例: $ls $ls –als $ls /home/sq/Desktop $ls ./D ...
- elasticsearch学习一、安装和配置
原文链接:http://jingyan.baidu.com/article/48206aead42b53216bd6b372.html ElasticSearch是一个基于Lucene的搜索服务器.它 ...
- Optimal Logging
by Anthony Vallone How long does it take to find the root cause of a failure in your system? Five mi ...
- hdoj1325 Is It A Tree?
Is It A Tree?题目链接 题意: 多组测试数据, 每组数据有多个数对, 表示一条有向边(即第一个数是第二个数的父节点), 以 0,0 为一组测试数据结束标志.当输入-1,-1时测试结束. 从 ...
- 错误编码 = 10022 错误消息 = SDK 组件 Qupaisdk 启动出错,错误消息为 [Qupaisdk], the android stack error message is Fail to start the plugin, which is caused by No implem
so没有load到.几个可能,1.缺少so--在群共享下载拷贝到armeabi-v7a 2.so没有打入apk--检查打出来的apk.解压打开看下libs下面有没有so. 3.abi平台问题.检查平 ...
- MVC小系列(五)【在过滤器里引入重定向】
在过滤器里引入重定向 过滤器的引入:如果用户进行一个操作,但没有登录,可以在Post方法上加个过滤器以验证用户是否登录,如果登录成功,则继续进行操作,如果没有登录,则实现Url的重定向,进行登录页 授 ...
- Android在onCreate()中获得控件尺寸
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceSt ...
- IDE开发<LER-Studio>(1)::UI设计
LER-Studio主要使用Microsoft Ribbon界面(fluentUI),大致为Office 2007 black. 首先创建MFC程序,基于多文档视图,Ribbon界面,基类选择CVie ...