日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

mysql的hash分区_MySQL中hash和key分区值的计算方法

發(fā)布時(shí)間:2025/3/20 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql的hash分区_MySQL中hash和key分区值的计算方法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

MySQL中hash和key分區(qū)值的計(jì)算方法

mysql中有一種叫作key作為partition key的類型.來看看記錄是怎么分布的

對(duì)于hash 分區(qū),使用%操作符,每個(gè)partition key只能是int類型,通過

partition key%3(比如定義了三個(gè)分區(qū))來把記錄分布三個(gè)不同的artition里面

mysql> create table t13 ( a int,b int) partition by hash(a) partitions 3

mysql>insert into t14 values(10,1);

mysql>insert into t14 values(11,1);

mysql>insert into t14 values(12,1);

10%3=1 所以第一條記錄是在p1里面,11%3=2在第二個(gè)分區(qū)p2里面,以此類推.

mysql> explain partitions select * from t13 where a=10;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t13?? | p1???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t13 where a=11;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t13?? | p2???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t13 where a=12;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t13?? | p0???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

對(duì)于使用key partition 的方法,官方文檔說是使用了一種password的方法.

mysql>create table t14 (a int,b int) partition by key(a) partitions 3

insert into t14 values(10,1);

insert into t14 values(11,1);

insert into t14 values(12,1);

insert into t14 values(13,1);

insert into t14 values(14,1);

insert into t14 values(15,1);

insert into t14 values(16,1);

mysql> explain partitions select * from t14 where a=10;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t14?? | p0???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=11;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t14?? | p0???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=12;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t14?? | p1???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=13;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t14?? | p1???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=14;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t14?? | p2???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

1 row in set (0.00 sec)

mysql> explain partitions select * from t14 where a=15;

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

| id | select_type | table | partitions | type | possible_keys | key? | key_len | ref? | rows | Extra?????? |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

|? 1 | SIMPLE????? | t14?? | p2???????? | ALL? | NULL????????? | NULL | NULL??? | NULL |??? 2 | Using where |

+----+-------------+-------+------------+------+---------------+------+---------+------+------+-------------+

我發(fā)現(xiàn)對(duì)于key partition的規(guī)律是每?jī)蓚€(gè)值落在同一步分區(qū)里面,其他沒有什么規(guī)律字,只是為什么樣這樣分配到不同的

分區(qū)里面,沒有很好的解釋。如果使用password函數(shù),這些值的結(jié)果根本就不一樣.有知道的朋友可以和我交流一下.

總結(jié)

以上是生活随笔為你收集整理的mysql的hash分区_MySQL中hash和key分区值的计算方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。