MYCAT10种常见分片规则之四 — PartitionByMod(简单取模)
一、使用场景
可以用于分片列为整数类型的表。
二、使用说明
1.分片列Mod分片基数。
2.类全名:io.mycat.route.funcation.PartitionByMod
示意图如下:

rule.xml 配置如下:
<tableRule name="customer_login">
<rule><columns>customer_id</columns>
<algorithm>mod-long</algorithm></rule>
</tableRule>
<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
<property name="count">2</property>
</function>
解释:
-> rule 标签中 customer_id 代表整型数字的取模字段。
-> property 标签中count 值2 代表按2 取模,模值则为0和1
本文详细介绍了MyCat数据库中间件中的PartitionByMod分片规则,适用于整数类型分片列的场景。通过示例展示了如何配置rule.xml实现按指定基数进行取模分片。
1043

被折叠的 条评论
为什么被折叠?



