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 ...
随机推荐
- ionic 手机端如何嵌入视频iframe
需求说明:后台提供功能,可以通过富文本编辑器[summernote]上传优酷的视频链接地址(这里需要注意:优酷视频提供多种操作方式 下面截图说明,先做个标记): 客户端是通过ionic开发的:而上传的 ...
- jBPM5 vs Actitivi
http://www.blogways.net/blog/2013/07/16/activiti-jbpm-compare.html jBPM是目前市场上主流开源工作引擎之一,在创建者Tom Baey ...
- ACM——3n+1
3n+1 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交:937 测试通过:386 描述 对于任意大于1的自然 ...
- onActivityResult不被执行的问题。
1.首先,返回的Activity必须使用startActivityForResult启动. 2.其次,在返回的Activity中必须保证setResult方法在finish方法之前执行,否则onAct ...
- iOS开发——TTS文本发音
iOS的文本转发音,从iOS7开始,iOS系统自带这个功能.能够实现中文.英文的发音.而且实现的起来非常方便.就像我看到有的博主说的三行代码搞定. (在iOS7之前(目前已不适配了),比如iOS6实现 ...
- 不一样的编码风格--Lambda表达式
Lambda表达式也是C#3.0中最重要的特性之一. 1.Lambda表达式的简介 Lambda表达式可以理解为一个匿名方法,它可以包含表达式和语句,并且用于创建委托或转换为表达式树.在使用Lambd ...
- Greedy is Good
作者:supernova 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=greedyAlg Joh ...
- 用eclipse建立简单WebService客户端,使用WSDL,用于短信接口发送
使用工具:eclipse 标准版,不用任何插件. 操作步骤: 建立java Project 命名为mess: 再在project上右键,选择other,选择web service文件类别,选择web ...
- DevExpress 控件使用之BarManager
DevExpress 开发的控件有很强的实力,不仅功能丰富,应用简便,而且界面华丽,更可方便定制.对于编程人员来说是个不错的选择.它的菜单栏控件更具代表,完全可以替代开发环境提供的基本控件,而让您编写 ...
- Eyeshot Ultimate 学习笔记(4)
动画 Eyeshot的官方Demo中有一个功能是近期项目需要用到的,就是动画效果.其中主要运用到BlockReference类,该类下的两个方法MoveTo(Dictionary<string, ...