日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發布時間:2025/3/20 数据库 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql的hash分区_MySQL中hash和key分区值的计算方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

MySQL中hash和key分區值的計算方法

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

對于hash 分區,使用%操作符,每個partition key只能是int類型,通過

partition key%3(比如定義了三個分區)來把記錄分布三個不同的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在第二個分區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)

對于使用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 |

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

我發現對于key partition的規律是每兩個值落在同一步分區里面,其他沒有什么規律字,只是為什么樣這樣分配到不同的

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。