MySQL分区表partition线上修改分区字段(三)

2014-11-24 16:45:39 · 作者: · 浏览: 1
(1) Find the next power of 2 greater than num. We call this value V; it can be calculated as:
V = POWER(2, CEILING(LOG(2, num)))
(Suppose that num is 13. Then LOG(2,13) is 3.7004397181411. CEILING(3.7004397181411) is 4, and V = POWER(2,4), which is 16.)
(2) Set N = F(column_list) & (V - 1).
(3) While N >= num:
Set V = CEIL(V / 2)
Set N = N & (V - 1)
[注释] & 在SQL里面的计算原理为:比如
把十进制转化进制成二进制,就得到了 http://zh.wikipedia.org/wiki/%E4%BA%8C%E8%BF%9B%E5%88%B6
首先按右对齐,例如变成0011和1000,按照每一位的数字来判断,如果两个都是1,则结果的相应位置就是1,否则就是0
如果是1011和1000,结果就是1000
如果是0110和1010,则结果就是0010
但是3是0011,8 是1000,所以3&8结果就是0
CEILING(X) CEIL(X): 返回不小于X 的最小整数值。
LOG(X) LOG(B,X) :若用一个参数调用,这个函数就会返回X 的自然对数。
POWER(X,Y) : 返回X 的Y乘方的结果值。
数据分布在哪个片区的计算方法:
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 & CEILING(8 / 2)
= 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.