简述: 
本文内容主要 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 理论知识总结的更多相关文章

  1. Mysql优化理论知识

    参考文章 http://blog.51cto.com/lizhenliang/2095526 ()硬件优化 如果有条件一定要SSD固态硬盘代替SAS机械硬盘,将RAID级别调整为RAID1+,相对于R ...

  2. MySQL系列理论知识

    内容: 1.视图 2.触发器 3.事务 4.存储过程 5.内置函数 6.流程控制 7.索引与慢查询优化 —————————————————————————————— 1.视图: 1.视图是什么: 视图 ...

  3. 商业智能BI-基础理论知识总结 ZT

    因为要加入一个BI项目,所以最近在研究BI相关的知识体系,由于这个方面的知识都是比较零散,开始都很多概念,不知道从何入手,网上找的资料也不多,特别是实战案例方面更少,这里还是先把理论知识理解下吧,分享 ...

  4. 小D课堂 - 新版本微服务springcloud+Docker教程_3-02CAP理论知识

    笔记 2.分布式应用知识CAP理论知识     简介:讲解分布式核心知识CAP理论 CAP定理:             指的是在一个分布式系统中,Consistency(一致性). Availabi ...

  5. js中函数的一些理论知识

      函数的一些理论知识 1. 函数:                执行一个明确的动作并提供一个返回值的独立代码块.同时函数也是javascript中的一级公民(就是函数和其它变量一样). 2.函数的 ...

  6. 用VC进行COM编程所必须掌握的理论知识

    一.为什么要用COM 软件工程发展到今天,从一开始的结构化编程,到面向对象编程,再到现在的COM编程,目标只有一个,就是希望软件能象积方块一样是累起来的,是组装起来的,而不是一点点编出来的.结构化编程 ...

  7. 图形学理论知识 BRDF 双向反射分布函数(Bidirectional Reflectance Distribution Function)

    图形学理论知识 BRDF 双向反射分布函数 Bidirectional Reflectance Distribution Function BRDF理论 BRDF表示的是双向反射分布函数(Bidire ...

  8. TestNG学习-001-基础理论知识

    此 文主要讲述用 TestNG 的基础理论知识,TestNG 的特定,编写测试过程三步骤,与 JUnit4+ 的差异,以此使亲对 TestNG 测试框架能够有一个简单的认知. 希望能对初学 TestN ...

  9. mysql Partition(分区)初探

    mysql Partition(分区)初探   表数据量大的时候一般都考虑水平拆分,即所谓的sharding.不过mysql本身具有分区功能,可以实现一定程度 的水平切分.  mysql是具有MERG ...

随机推荐

  1. word ppt excel文档转换成pdf

    1.把word文档转换成pdf (1).添加引用 using Microsoft.Office.Interop.Word; 添加引用 (2).转换方法 /// <summary> /// ...

  2. linq to ef(相当于sql中in的用法)查询语句

    select * from DoctorInfo doctor where doctor.HosDepartId in (select Id from HospitalDepartment hd wh ...

  3. C#获取当前路径,获取当前路径的上一层路径

    C#获取当前路径的方法如下: (1)string path1 = System.Environment.CurrentDirectory; //C:\...\bin\Debug -获取和设置当前工作目 ...

  4. ios NSMethodSignature and NSInvocation 消息转发

    1.首先获取消息转发时连个函数内部具体内容 MARK:这里是拿[@"xxxxx" length]调用拿来举例说明 (lldb) po signature <NSMethodS ...

  5. Spring MVC 3.0 返回JSON数据的方法

    Spring MVC 3.0 返回JSON数据的方法1. 直接 PrintWriter 输出2. 使用 JSP 视图3. 使用Spring内置的支持// Spring MVC 配置<bean c ...

  6. 关于cnpm的一点小bug

    在实际工作中,一个项目完成后,在上线前,常常需要把代码进行压缩,一般是用gulp或者 webpack 进行压缩.(小妹是用gulp) gulp是运行在node 环境下的. 所以首先,下载并安装了nod ...

  7. JSON.parse 函数应用 (复制备忘)

    JSON.parse 函数 JSON.parse 函数 (JavaScript) 将 JavaScript 对象表示法 (JSON) 字符串转换为对象. 语法 JSON.parse(text [, r ...

  8. UVA 11549 CALCULATOR CONUNDRUM(Floyd判圈算法)

    CALCULATOR CONUNDRUM   Alice got a hold of an old calculator that can display n digits. She was bore ...

  9. python 自动化之路 day 08_2 网络编程

    本节内容 Socket介绍 Socket参数介绍 基本Socket实例 Socket实现多连接处理 通过Socket实现简单SSH 通过Socket实现文件传送 作业:开发一个支持多用户在线的FTP程 ...

  10. Qt标准对话框之QColorDialog

    Qt中提供了一些标准的对话框,用于实现一些常用的预定义功能,比如本节中将要介绍的颜色对话框——QColorDialog. 在不同的系统平台下,颜色对话框的显示效果可能会有所不同,主要因系统主题风格而异 ...