mycat分片规则

范围分片

	<tableRule name="auto-sharding-long">
		<rule>
			<columns>id</columns>
			<algorithm>rang-long</algorithm>
		</rule>
	</tableRule>


	<function name="rang-long"
		class="io.mycat.route.function.AutoPartitionByLong">
		<property name="mapFile">autopartition-long.txt</property>
	</function>

默认id分片,id为1-500万为第一个节点分片
在这里插入图片描述

取模分片

默认通过id取模进行分片

	<tableRule name="mod-long">
		<rule>
			<columns>id</columns>
			<algorithm>mod-long</algorithm>
		</rule>
	</tableRule>

	<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
		<!-- how many data nodes -->
		<property name="count">3</property>
	</function>

枚举分片

通过设置字段<sharding_id>的值进行分片

	<tableRule name="sharding-by-intfile">
		<rule>
			<columns>sharding_id</columns>
			<algorithm>hash-int</algorithm>
		</rule>
	</tableRule>

	<function name="hash-int"
		class="io.mycat.route.function.PartitionByFileMap">
		<property name="mapFile">partition-hash-int.txt</property>
	</function>

字段值为10000 为0节点的数据
字段值为10010 为1节点的数据
在这里插入图片描述

应用指定分片

默认没有,根据字段值,截取字段进行分片

	<tableRule name="sharding-by-subString">
		<rule>
			<columns>user_id</columns>
			<algorithm>partbySubString</algorithm>
		</rule>
	</tableRule>

	<function name="partbySubString"
		class="io.mycat.route.function.PartitionDirectBySubString">
		<property name="startIndex">0</property> <!-- 第几位开始截取 -->
		<property name="size">3</property> <!-- 截取几位 -->
		<property name="partitionCount">3</property> <!-- 分为几个节点 -->
		<property name="defaultPartition">0</property> <!-- 如果超出分片节点默认进入哪个节点 -->
	</function>

按月分片

默认通过create_time进行分片
sEndDate与sBeginDate需要对应分片节点,超出结束时间的会从新进行计算:04为第一个节点,05为第二个节点。。。。

	<tableRule name="sharding-by-month">
		<rule>
			<columns>create_time</columns>
			<algorithm>partbymonth</algorithm>
		</rule>
	</tableRule>
	
	<function name="partbymonth"
		class="io.mycat.route.function.PartitionByMonth">
		<property name="dateFormat">yyyy-MM-dd</property> <!-- 时间格式 -->
		<property name="sBeginDate">2015-01-01</property> <!-- 开始时间 -->
		<property name="sEndDate">2015-03-31</property> <!-- 结束时间 -->
	</function>

按天分片

	<tableRule name="sharding-by-date">
		<rule>
			<columns>create_time</columns>
			<algorithm>partbydate</algorithm>
		</rule>
	</tableRule>
	
	<function name="partbyDate"
		class="io.mycat.route.function.PartitionByDate">
		<property name="dateFormat">yyyy-MM-dd</property> <!-- 时间格式 -->
		<property name="sBeginDate">2015-01-01</property> <!-- 开始时间 -->
		<property name="sEndDate">2015-01-31</property> <!-- 结束时间 -->
		<property name="sPartionDate">10</property> <!-- 每十天一个分片 -->
	</function>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值