原創: 管長龍mysql
咱們已經經過以前的六篇文章,介紹了 DBLE 和 MyCat 常見的六種分片算法,那麼咱們來作個總結吧!算法
DBLE 與 MyCat 對應分片算法名和異同sql
除了以上六種常見的分片算法以外,DBLE 還獨有一種分片算法:跳躍字符串算法。spa
具體配置以下:code
#rule.xml <function name="jumphash" class="jumpStringHash"> <property name="partitionCount">2</property> <property name="hashSlice">0:2</property> </function>
partitionCont:分片數量xml
hashSlice:分片截取長度blog
該算法來自於 Google 的一篇文章《A Fast, Minimal Memory, Consistent Hash Algorithm》其核心思想是經過幾率分佈的方法將一個hash值在每一個節點分佈的機率變成1/n,而且能夠經過更簡便的方法能夠計算得出,並且分佈也更加均勻。字符串
注意事項:分片字段值爲NULL時,數據恆落在0號節點之上;當真實存在於mysql的字段值爲not null的時候,報錯 "Sharding column can't be null when the table in MySQL column is not null"string
至此,咱們DBLE中支持的七種分片算法就介紹完了,相信讀者朋友對 DBLE 的使用也慢慢熟悉。hash
系列文章的最後:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dble:rule SYSTEM "rule.dtd"> <dble:rule xmlns:dble="http://dble.cloud/" version="9.9.9.9"> <tableRule name="sharding-by-enum"> <rule> <columns>id</columns> <algorithm>enum</algorithm> </rule> </tableRule> <tableRule name="sharding-by-range"> <rule> <columns>id</columns> <algorithm>rangeLong</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash"> <rule> <columns>id</columns> <algorithm>hashLong</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash2"> <rule> <columns>id</columns> <algorithm>hashLong2</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash3"> <rule> <columns>id</columns> <algorithm>hashLong3</algorithm> </rule> </tableRule> <tableRule name="sharding-by-mod"> <rule> <columns>id</columns> <algorithm>hashmod</algorithm> </rule> </tableRule> <tableRule name="sharding-by-hash-str"> <rule> <columns>id</columns> <algorithm>hashString</algorithm> </rule> </tableRule> <tableRule name="sharding-by-date"> <rule> <columns>calldate</columns> <algorithm>partbydate</algorithm> </rule> </tableRule> <tableRule name="sharding-by-pattern"> <rule> <columns>id</columns> <algorithm>pattern</algorithm> </rule> </tableRule> <!-- enum partition --> <function name="enum" class="Enum"> <property name="mapFile">partition-hash-int.txt</property> <property name="defaultNode">0</property><!--the default is -1,means unexpected value will report error--> <property name="type">0</property><!--0 means key is a number, 1 means key is a string--> </function> <!-- number range partition --> <function name="rangeLong" class="NumberRange"> <property name="mapFile">autopartition-long.txt</property> <property name="defaultNode">0</property><!--he default is -1,means unexpected value will report error--> </function> <!-- Hash partition,when partitionLength=1, it is a mod partition--> <!--MAX(sum(count*length[i]) must not more then 2880--> <function name="hashLong" class="Hash"> <property name="partitionCount">8</property> <property name="partitionLength">12