LINEAR HASH Partitioning
MySQL :: MySQL 8.0 Reference Manual :: 23.2.4.1 LINEAR HASH Partitioning https://dev.mysql.com/doc/refman/8.0/en/partitioning-linear-hash.html
23.2.4.1 LINEAR HASH Partitioning
MySQL also supports linear hashing, which differs from regular hashing in that linear hashing utilizes a linear powers-of-two algorithm whereas regular hashing employs the modulus of the hashing function's value.
Syntactically, the only difference between linear-hash partitioning and regular hashing is the addition of the LINEAR
keyword in the PARTITION BY
clause, as shown here:
CREATE TABLE employees (
id INT NOT NULL,
fname VARCHAR(30),
lname VARCHAR(30),
hired DATE NOT NULL DEFAULT '1970-01-01',
separated DATE NOT NULL DEFAULT '9999-12-31',
job_code INT,
store_id INT
)
PARTITION BY LINEAR HASH( YEAR(hired) )
PARTITIONS 4;
Given an expression expr
, the partition in which the record is stored when linear hashing is used is partition number N
from among num
partitions, where N
is derived according to the following algorithm:
Find the next power of 2 greater than
num
. We call this valueV
; it can be calculated as:V = POWER(2, CEILING(LOG(2, num)))
(Suppose that
num
is 13. ThenLOG(2,13)
is 3.7004397181411.CEILING(3.7004397181411)
is 4, andV
=POWER(2,4)
, which is 16.)Set
N
=F
(column_list
) & (V
- 1).While
N
>=num
:Set
V
=V
/ 2Set
N
=N
& (V
- 1)
Suppose that the table t1
, using linear hash partitioning and having 6 partitions, is created using this statement:
CREATE TABLE t1 (col1 INT, col2 CHAR(5), col3 DATE)
PARTITION BY LINEAR HASH( YEAR(col3) )
PARTITIONS 6;
Now assume that you want to insert two records into t1
having the col3
column values '2003-04-14'
and '1998-10-19'
. The partition number for the first of these is determined as follows:
V = POWER(2, CEILING( LOG(2,6) )) = 8
N = YEAR('2003-04-14') & (8 - 1)
= 2003 & 7
= 3
(3 >= 6 is FALSE: record stored in partition #3)
The number of the partition where the second record is stored is calculated as shown here:
V = 8
N = YEAR('1998-10-19') & (8 - 1)
= 1998 & 7
= 6
(6 >= 6 is TRUE: additional step required)
N = 6 & ((8 / 2) - 1)
= 6 & 3
= 2
(2 >= 6 is FALSE: record stored in partition #2)
The advantage in partitioning by linear hash is that the adding, dropping, merging, and splitting of partitions is made much faster, which can be beneficial when dealing with tables containing extremely large amounts (terabytes) of data. The disadvantage is that data is less likely to be evenly distributed between partitions as compared with the distribution obtained using regular hash partitioning.
V = POWER(2, CEILING(LOG(2, num)))
Set N = F(column_list) & (V - 1).
While N >= num:
Set V = V / 2
Set N = N & (V - 1)
LINEAR HASH Partitioning的更多相关文章
- 压缩映射:简单最邻近搜索-(SLH)Simple Linear Hash
Compact Projection: Simple and Efficient Near Neighbor Search with Practical memory Requirement Auto ...
- 分区实践 A PRIMARY KEY must include all columns in the table's partitioning function
MySQL :: MySQL 8.0 Reference Manual :: 23 Partitioning https://dev.mysql.com/doc/refman/8.0/en/parti ...
- HASH Partitioning--转载
原文地址:https://dev.mysql.com/doc/refman/5.1/en/partitioning-hash.html HASH Partitioning [+/-] 18.2.3.1 ...
- MySQL 分区表 partition线上修改分区字段,后续进一步学习partition (1)
公司线上在用partition,有一个表的分区字段错了,需要重建,结果发现没有办法像修改主键字段或者修改索引字段那样直接一条sql搞定.而是需要建临时表,有down time,所以去仔细看了文档,研究 ...
- 13.1.17 CREATE TABLE Syntax
13.1.17 CREATE TABLE Syntax 13.1.17.1 CREATE TABLE ... LIKE Syntax 13.1.17.2 CREATE TABLE ... SELECT ...
- MySQL HASH分区
200 ? "200px" : this.width)!important;} --> 介绍 基于给定的分区个数,将数据分配到不同的分区,HASH分区只能针对整数进行HASH ...
- hash 分区的用途是什么?
Hash partitioning enables easy partitioning of data that does not lend itself to rangeor list partit ...
- Mysql --分区表(6)Hash分区
HASH分区 HASH分区主要用来分散热点读,确保数据在预先确定个数的分区中尽可能平均分布.对一个表执行HASH分区时,MySQL会对分区键应用一个散列函数,以此确定数据应当放在N个分区中的哪个分区 ...
- Mysql 分区(range,list,hash)转载
MySQL支持RANGE,LIST,HASH和KEY四种分区.其中,每个分区又都有一种特殊的类型.对于RANGE分区,有RANGE COLUMNS分区.对于LIST分区,有LIST COLUMNS分区 ...
随机推荐
- (转)引用---FFMPEG解码过程
视频播放过程 首先简单介绍以下视频文件的相关知识.我们平时看到的视频文件有许多格式,比如 avi, mkv, rmvb, mov, mp4等等,这些被称为容器(Container), 不同的容器格式规 ...
- 【Java面试题】13 Anonymous Inner Class (匿名内部类) 是否可以extends(继承)其它类,是否可以implements(实现)interface(接口)?
1.什么是匿名内部类? 内部类,存在于另一个类内部的类,而匿名内部类,顾名思义,就是没有名字的内部类. 2.为什么需要匿名内部类? 每个inner class都能够各自继承某一实现类(implemen ...
- c++ time_t
type struct tm <ctime> Time structure Structure containing a calendar date and time broken dow ...
- ANSI 转 UTF-8
ANSI和UTF-8格式都不太了解,各自好像都有好几种,下载了一个库,文件基本都是ANSI格式,linux显示乱码,原来都是在虚拟机一个个的“另存为“完成的,这次文件有点多,因此需要用命令完成. 以下 ...
- 编写Unity3D着色器的三种方式
不管你会不会写Unity3D的shader,估计你会知道,Unity3D编写shader有三种方式,这篇东西主要就是说一下这三种东西有什么区别,和大概是怎样用的. 先来列一下这三种方式: fixed ...
- spring配置文件中bean标签
<bean id="beanId"(1) name="beanName"(2) class="beanClass"(3) parent ...
- 超全面的JavaWeb笔记day22<文件上传>
文件上传概述 1 文件上传的作用 例如网络硬盘!就是用来上传下载文件的. 在智联招聘上填写一个完整的简历还需要上传照片呢. 2 文件上传对页面的要求 上传文件的要求比较多,需要记一下: 1. 必须使用 ...
- J2EE开发推荐工具
- Python 入门(六)Dict和Set类型
什么是dict 我们已经知道,list 和 tuple 可以用来表示顺序集合,例如,班里同学的名字: ['Adam', 'Lisa', 'Bart'] 或者考试的成绩列表: [95, 85, 59] ...
- oracle SUM函数
select change_type as change_type, sum(points1) as points from (select DECODE(p.change_type, , ' 兑换商 ...