zoukankan      html  css  js  c++  java
  • 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

    MySQL 8.0 Reference Manual  /  ...  /  LINEAR HASH Partitioning

    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:

    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 = V / 2

      • Set 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.

     PREV   HOME   UP   
     
    二阶线性散列分区


    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)

     
     
     
  • 相关阅读:
    几款网络测试工具总结
    Linux安装telnet
    Linux下iptables 禁止端口和开放端口
    mysql创建某个数据库中的某张表 只读用户
    查看nginx版本号的几种方法
    Ngxtop-Nginx日志实时分析利器
    Nginx监控运维
    oracle经典书籍推荐
    华为典型局域网组网案例介绍(1)
    技术说明 路由器是如何工作的呢? 一个简单的解释
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10107605.html
Copyright © 2011-2022 走看看