https://blog.csdn.net/webnum/article/details/78313525

 

分片规则:字符串拆分hash

一、conf/schema.xml文件

  1.  
    <?xml version="1.0"?>
  2.  
    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
  3.  
    <mycat:schema xmlns:mycat="http://io.mycat/">
  4.  
    <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
  5.  
    <table name="partition_by_string" primaryKey="ord_no" dataNode="dn$0-2"
  6.  
    rule="partition-by-string" />
  7.  
    </schema>
  8.  
    <dataNode name="dn0" dataHost="dh-1" database="db0"/>
  9.  
    <dataNode name="dn1" dataHost="dh-1" database="db1"/>
  10.  
    <dataNode name="dn2" dataHost="dh-1" database="db2"/>
  11.  
    <dataHost name="dh-1" maxCon="1000" minCon="10" balance="0"
  12.  
    writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
  13.  
    <heartbeat>select user()</heartbeat>
  14.  
    <writeHost host="hostM1" url="localhost:3306" user="root"
  15.  
    password="123456">
  16.  
    </writeHost>
  17.  
    </dataHost>
  18.  
    </mycat:schema>

二、conf/rule.xml文件

  1.  
    <?xml version="1.0" encoding="UTF-8"?>
  2.  
    <!DOCTYPE mycat:rule SYSTEM "rule.dtd">
  3.  
    <mycat:rule xmlns:mycat="http://io.mycat/">
  4.  
    <tableRule name="partition-by-string">
  5.  
    <rule>
  6.  
    <columns>ord_no</columns>
  7.  
    <algorithm>partition-by-string</algorithm>
  8.  
    </rule>
  9.  
    </tableRule>
  10.  
    <function name="partition-by-string"
  11.  
    class="io.mycat.route.function.PartitionByString">
  12.  
    <property name="partitionLength">512</property> <!-- zero-based -->
  13.  
    <property name="partitionCount">2</property>
  14.  
    <property name="hashSlice">-6:0</property>
  15.  
    </function>
  16.  
    </mycat:rule>

三、规则文件信息

四、测试用到的sql

  1.  
    =============按照ord_no字段 字符串hash ================
  2.  
    CREATE TABLE partition_by_string (ord_no varchar(20) NULL,`db_nm` varchar(20) NULL);
  3.  
    INSERT INTO `partition_by_string` (ord_no,db_nm) VALUES (171022237582, database());
  4.  
    INSERT INTO `partition_by_string` (ord_no,db_nm) VALUES (171022553756, database());
  5.  
    select * from partition_by_string;

五、注意事项

分片数量必须小于等于dataNode数

六、参数说明

length代表字符串hash求模基数,count分区数,其中length*count=1024

hashSlice hash预算位,即根据子字符串中int值 hash运算

0 代表 str.length(), -1 代表 str.length()-1,大于0只代表数字自身

可以理解为substring(start,end),start为0则只表示0

例1:值“45abc”,hash预算位0:2 ,取其中45进行计算

例2:值“aaaabbb2345”,hash预算位-4:0 ,取其中2345进行计算

mycat1.6.5分片(字符串拆分hash)的更多相关文章

  1. 2016/4/5 Ajax ①用户名 密码 登陆 注册 ② 判断用户名是否已存在 ③点击按钮出现民族选项下拉菜单 ④DBDA类 加入Ajaxquery方法 数组变字符串 字符串拆分

    ①登陆   注册    查表匹配    0405Ajax.php   ②判断用户名是否存在 <!DOCTYPE html> <html lang="en"> ...

  2. UTF-8编码的字符串拆分成单字、获取UTF-8字符串的字符个数的代码及原理

    一.字符编码简介 1. ASCII码 在计算机内部,所有的信息最终都表示为一个二进制的字符串.每一个二进制位(bit)有0和1两种状态,因此八个二进制位就可以组合出256种状态,这被称为一个字节(by ...

  3. SQL2000/2005字符串拆分为列表通用函数

    ------------------------------------------------------------------ --  Author : htl258(Tony) --  Dat ...

  4. redis 2 字符串 和 hash

    string是最简单的类型,一个key对应一个value,string类型是二进制安全的.redis的string可以包含任何数据,比如JPG图片或者序列化的对象 操作    set    设置key ...

  5. sql之cursor的简介和字符串拆分(split)与游标的使用

     字符串拆分(split)与游标的使用 CREATE TABLE Plates ( ,), ) NOT NULL, [BusinessId] INT NOT NULL, ) ),),), SELECT ...

  6. SQL 字符串拆分

    字符串拆分: ALTER FUNCTION [dbo].[f_Split](@sText nvarchar(max),@split NVARCHAR(20)) RETURNS @t TABLE (id ...

  7. php将长字符串拆分为指定最大宽度的字符串数组

    /** * 将字符串拆分为指定最大宽度的字符串数组.单字节字符宽度为1,多字节字符通常宽度为2 * @param string $msg 要拆分的字符串 * @param int $width 结果数 ...

  8. 截取字符(pos,copy,Leftstr,MidStr,RightStr)以逗号为准把字符串拆分,判断字符串是否有数字、字母(大小写), 去掉字符串空格

    1.copy(a,b,c) 举个例子: str := “123456”;str1 := Copy(Str,2,3);结果就是 str1 等于 234.Copy有3个参数,第一个是你要处理的字符串,第二 ...

  9. Java字符串拆分和字符串连接

    Java字符串拆分/连接 public class LierString{ //------------------------------------------------------------ ...

随机推荐

  1. 【Lintcode】363.Trapping Rain Water

    题目: Given n non-negative integers representing an elevation map where the width of each bar is 1, co ...

  2. 洛谷【P1908】逆序对

    题目传送门:https://www.luogu.org/problemnew/show/P1908 所谓逆序对,就是序列中\(a[i]>a[j]\)且\(i<j\)的有序对. 所以我们在归 ...

  3. HDOJ1242(延时迷宫BFS+优先队列)

    Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  4. HDOJ1114(完全背包)

    #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const ...

  5. js强加方法

    (function () { Array.prototype.removeItem=function (item) { var index=this.indexOf(item); if(index!= ...

  6. 弱网测试--使用fiddle进行弱网测试

    数据源于:http://blog.csdn.net/eleven521/article/details/19089671 弱网测试原理以及方法(一)一.为什么要进行弱网测试?按照移动特性,各种网络连接 ...

  7. python 基础 列表生成式

    data = {'a':'abc';'b':'bac','c':'cba'} [v for k,v in data] 结果 ['abc','bca','cba'] 格式 [x for x in  内容 ...

  8. ffmpeg+HLS实现直播与回放

    Nginx配置视频服务器 server { listen ; server_name localhost; location /hls{ add_header Access-Control-Allow ...

  9. [Android Lint] xxx is not translated in xxx 的解决方法

    CLEAN项目即可 转自BLOG http://blog.csdn.net/feng88724/article/details/8835664

  10. EPEL for CentOS or Redhat

    注:地址可能会变 RHEL/CentOS 7 64 Bit # wget http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release ...