Mycat-server-1.6.5 常见分片方式

 Mycat-server-1.6.5 常见分片方式

1 安装

[root@hongquan1 soft]# tar zxvf Mycat-server-1.6.5-release-20180122220033-linux.tar.gz
[root@hongquan1 soft]# mv mycat/ /usr/local/
[root@hongquan1 soft]# tar xvf jdk-8u20-linux-x64.tar.gz
[root@hongquan1 soft]# mv jdk1.8.0_20/ /usr/local/mycat/
[root@hongquan1 mycat]# vim /usr/local/mycat/conf/wrapper.conf
wrapper.java.command=/usr/local/mycat/jdk1.8.0_20/bin/java
[root@hongquan1 mycat]# useradd mycat
[root@hongquan1 mycat]# chown -R mycat.mycat /usr/local/mycat
[root@hongquan1 conf]# vim log4j2.xml
<asyncRoot level="debug" includeLocation="true">
[root@hongquan1 mycat]# vim /usr/local/mycat/conf/schema.xml
<writeHost host="hostM1" url="192.168.20.118:3306" user="system"
password="mysql">
<!-- can have multi read hosts -->
<readHost host="hostS2" url="192.168.20.119:3306" user="system" password="mysql" />
</writeHost>
[root@hongquan1 mycat]# vim /usr/local/mycat/conf/server.xml
<user name="root" defaultAccount="true">
<property name="password">mysql</property>
<property name="schemas">TESTDB</property>
</user>
<user name="usermycat">
<property name="password">usermycat</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>

(system@127.0.0.1:3306) [(none)]>CREATE database db1;
(system@127.0.0.1:3306) [(none)]>CREATE database db2;
(system@127.0.0.1:3306) [(none)]>CREATE database db3;
[root@hongquan1 mycat]# /usr/local/mycat/bin/mycat start
Starting Mycat-server...
[root@hongquan1 ~]# tail -f -n 100 /usr/local/mycat/logs/wrapper.log
STATUS | wrapper | 2018/05/04 09:41:06 | --> Wrapper Started as Daemon
STATUS | wrapper | 2018/05/04 09:41:06 | Launching a JVM...
INFO | jvm 1 | 2018/05/04 09:41:06 | Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=64M; support was removed in 8.0
INFO | jvm 1 | 2018/05/04 09:41:06 | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
INFO | jvm 1 | 2018/05/04 09:41:06 | Copyright 1999-2006 Tanuki Software, Inc. All Rights Reserved.
INFO | jvm 1 | 2018/05/04 09:41:06 |
INFO | jvm 1 | 2018/05/04 09:41:07 | MyCAT Server startup successfully. see logs in logs/mycat.log
[root@hongquan1 mycat]# ps -ef|grep java
[root@hongquan1 mycat]# netstat -nltp | grep 8066
tcp 0 0 :::8066 :::* LISTEN 31908/java
[root@hongquan1 conf]# /sbin/iptables -I INPUT -p tcp --dport 8066 -j ACCEPT
[root@hongquan1 conf]# /etc/rc.d/init.d/iptables save
[mysql@hongquan1 ~]$ mysql -uroot -pmysql -h127.0.0.1 -P8066 -DTESTDB //reload @@config;
[mysql@hongquan1 ~]$ mysql -uroot -pmysql -h127.0.0.1 -P9066 -DTESTDB

2 数据库常见表配置

(root@127.0.0.1:8066) [TESTDB]> show databases;
(root@127.0.0.1:8066) [TESTDB]> show tables;
(root@127.0.0.1:8066) [TESTDB]> create table employee (id int not null primary key,name varchar(100),sharding_id int not null);
Query OK, 0 rows affected (0.07 sec)
(root@127.0.0.1:8066) [TESTDB]> explain create table employee (id int not null primary key,name varchar(100),sharding_id int not null);
+-----------+------------------------------------------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+------------------------------------------------------------------------------------------------+
| dn1 | create table employee (id int not null primary key,name varchar(100),sharding_id int not null) |
| dn2 | create table employee (id int not null primary key,name varchar(100),sharding_id int not null) |
+-----------+------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
(root@127.0.0.1:8066) [TESTDB]> insert into employee(id,name,sharding_id) values(1,'leader us',10000);
Query OK, 1 row affected (0.06 sec)
(root@127.0.0.1:8066) [TESTDB]> create table company(id int not null primary key,name varchar(100));
Query OK, 0 rows affected (0.06 sec)
(root@127.0.0.1:8066) [TESTDB]> explain create table company(id int not null primary key,name varchar(100));
+-----------+---------------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+---------------------------------------------------------------------+
| dn1 | create table company(id int not null primary key,name varchar(100)) |
| dn2 | create table company(id int not null primary key,name varchar(100)) |
| dn3 | create table company(id int not null primary key,name varchar(100)) |
+-----------+---------------------------------------------------------------------+
(root@127.0.0.1:8066) [TESTDB]> insert into company(id,name) values(1,'hp');
Query OK, 1 row affected (0.00 sec)
(root@127.0.0.1:8066) [TESTDB]> select * from employee;
+----+-----------+-------------+
| id | name | sharding_id |
+----+-----------+-------------+
| 1 | leader us | 10000 |
+----+-----------+-------------+
1 row in set (0.06 sec)
(root@127.0.0.1:8066) [TESTDB]> insert into employee(id,name,sharding_id) values(1,'leader us',10000);
ERROR 1062 (23000): Duplicate entry '1' for key 'PRIMARY'
(root@127.0.0.1:8066) [TESTDB]> explain select * from employee;
+-----------+----------------------------------+
| DATA_NODE | SQL |
+-----------+----------------------------------+
| dn1 | SELECT * FROM employee LIMIT 100 |
| dn2 | SELECT * FROM employee LIMIT 100 |
+-----------+----------------------------------+
(root@127.0.0.1:8066) [TESTDB]> insert into employee(id,name,sharding_id) values(2,'me',10010);
Query OK, 1 row affected (0.01 sec)
(root@127.0.0.1:8066) [TESTDB]> insert into employee(id,name,sharding_id) values(3,'mycat',10000);
Query OK, 1 row affected (0.00 sec)
(root@127.0.0.1:8066) [TESTDB]> insert into employee(id,name,sharding_id) values(4,'mycat1',10010);
Query OK, 1 row affected (0.01 sec)
(root@127.0.0.1:8066) [TESTDB]> select * from employee;

explain create table travelrecord (id bigint not null primary key,user_id varchar(100),traveldate DATE, fee decimal,days int);
explain insert into travelrecord (id,user_id,traveldate,fee,days) values(1,'wang','2014-01-05',510.5,3);
explain insert into travelrecord (id,user_id,traveldate,fee,days) values(7000001,'wang','2014-01-05',510.5,3);

(root@127.0.0.1:8066) [TESTDB]> expElain select * from travelrecord where id=1;
+-----------+---------------------------------------------------+
| DATA_NODE | SQL |
+-----------+---------------------------------------------------+
| dn1 | SELECT * FROM travelrecord WHERE id = 1 LIMIT 100 |

insert into company(id,name) values(1,'hp');
insert into company(id,name) values(2,'ibm');
insert into company(id,name) values(3,'oracle');
创建客户表:
create customer: create table customer(id int not null primary key,name varchar(100),company_id int not null,sharding_id int not null);
插入数据:
insert into customer (id,name,company_id,sharding_id )values(1,'wang',1,10000); //stored in db1;
insert into customer (id,name,company_id,sharding_id )values(2,'xue',2,10010); //stored in db2;
insert into customer (id,name,company_id,sharding_id )values(3,'feng',3,10000); //stored in db1;
创建表格orders,并插入数据:
create table orders (id int not null primary key ,customer_id int not null,sataus int ,note varchar(100) );
insert into orders(id,customer_id) values(1,1); //stored in db1 because customer table with id=1 stored in db1
insert into orders(id,customer_id) values(2,2); //stored in db2 because customer table with id=1 stored in db2
explain insert into orders(id,customer_id) values(2,2);
select customer.name ,orders.* from customer ,orders where customer.id=orders.customer_id;
热点新闻,用取摸的方式随机分配到dn1,dn2,dn3上
create table hotnews(id int not null primary key ,title varchar(400) ,created_time datetime);
insert into hotnews(id,title,created_time) values(1,'first',now()); 在分片1上
而Id为5,则到dn3上,5%3=2 ,即对应dn3的 index
其他:
goods表
create table goods(id int not null primary key,name varchar(200),good_type tinyint,
good_img_url varchar(200),good_created date,good_desc varchar(500), price double);
--一个主表,套一个子表,在套一个子表
----
<table name="t_user" primaryKey="user_id" autoIncrement="true" dataNode="dn1,dn2,dn3" rule="mod-long">
<childTable name="t_user_orders" primaryKey="ID" joinKey="user_id" parentKey="user_id">
<childTable name="t_order_items" primaryKey="ID" joinKey="order_id" parentKey="order_id" />
</childTable>
</table>

INSERT INTO db1.MYCAT_SEQUENCE(name,current_value,increment) VALUES ('T_USER', 1000, 2);
INSERT INTO db1.MYCAT_SEQUENCE(name,current_value,increment) VALUES ('T_USER_ORDERS', 1000, 3);
INSERT INTO db1.MYCAT_SEQUENCE(name,current_value,increment) VALUES ('T_ORDER_ITEMS', 1000, 4);
T_USER=dn1
T_USER_ORDERS=dn1
T_ORDER_ITEMS=dn1
select next value for MYCATSEQ_T_USER,next value for MYCATSEQ_T_USER_ORDERS,next value for MYCATSEQ_T_ORDER_ITEMS;

use test;
CREATE TABLE `t_user` (
`user_id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`user_name` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
`company_id` int(11) NOT NULL default 0,
`user_balance` decimal(12,2) not null default 0,
`user_phone` varchar(20) not null default '',
`user_email` varchar(200) not null default '',
`create_time` datetime not null default now(),
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1000011 DEFAULT CHARSET=utf8;

CREATE TABLE `t_user_orders` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) UNSIGNED NOT NULL default 0,
`order_id` int(11) NOT NULL,
`order_money` decimal(12,2) not null default 0,
`sataus` int(11) not null DEFAULT 1,
`note` varchar(100) DEFAULT NULL,
`create_time` datetime not null default now(),
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `t_order_items` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`order_id` int(11) NOT NULL,
`goods_id` int(11) not null,
`goods_money` decimal(12,2) not null,
`goods_count` int(11) not null default 1,
`sataus` int(11) DEFAULT NULL,
`note` varchar(100) DEFAULT NULL,
`create_time` datetime not null default now(),
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ERROR 1064 (HY000): insert sql using mycat seq,you must provide primaryKey value for explain

insert into t_user (user_id,user_name,company_id,user_balance,user_phone,user_email)values(next value for MYCATSEQ_T_USER,'yang',1,100.11,'8613550347939','yhq1314@163.com');
insert into t_user (user_id,user_name,company_id,user_balance,user_phone,user_email)values(next value for MYCATSEQ_T_USER,'hogn',2,12.11,'8613550347939','yhq1314@163.com');
insert into t_user (user_id,user_name,company_id,user_balance,user_phone,user_email)values(next value for MYCATSEQ_T_USER,'quan',3,9999.11,'8613550347939','yhq1314@163.com');

insert into t_user_orders(id,user_id,order_id,order_money,sataus,note) values(next value for MYCATSEQ_T_USER_ORDERS,1004,1000011,11.25,1,'abc');
insert into t_user_orders(id,user_id,order_id,order_money,sataus,note) values(next value for MYCATSEQ_T_USER_ORDERS,1006,1000013,36.28,1,null);
insert into t_user_orders(id,user_id,order_id,order_money,sataus,note) values(next value for MYCATSEQ_T_USER_ORDERS,1006,1000019,39.28,1,null);
insert into t_user_orders(id,user_id,order_id,order_money,sataus,note) values(next value for MYCATSEQ_T_USER_ORDERS,1006,1000022,12.28,1,null);

insert into t_order_items(id,order_id,goods_id,goods_money,goods_count,sataus)values (next value for MYCATSEQ_T_ORDER_ITEMS,1000011,1245798,1.36,1,1);
insert into t_order_items(id,order_id,goods_id,goods_money,goods_count,sataus)values (next value for MYCATSEQ_T_ORDER_ITEMS,1000011,124533,1.36,1,1);
insert into t_order_items(id,order_id,goods_id,goods_money,goods_count,sataus)values (next value for MYCATSEQ_T_ORDER_ITEMS,1000013,12451568,1.36,1,1);
insert into t_order_items(id,order_id,goods_id,goods_money,goods_count,sataus)values (next value for MYCATSEQ_T_ORDER_ITEMS,1000013,124557898,1.36,1,1);
insert into t_order_items(id,order_id,goods_id,goods_money,goods_count,sataus)values (next value for MYCATSEQ_T_ORDER_ITEMS,1000013,12457878,1.36,1,1);

explain select * from t_user where user_id=1004;
explain select *from t_user_orders where user_id=1004;
explain select a.*,b.* from t_user a,t_user_orders b where a.user_id=b.user_id and a.user_id=1004;
explain select a.user_id,b.order_id,c.goods_id,c.goods_money from t_user a,t_user_orders b,t_order_items c where a.user_id=b.user_id and b.order_id=c.order_id and a.user_id=1004;
explain select * from t_order_items;

select user_id,order_money,sum(order_money) as money from t_user_orders group by user_id order by order_money desc,user_id desc limit 10
select user_id,sum(order_money) as money from t_user_orders group by user_id order by order_money desc,user_id desc limit 10
ERROR 1105 (HY000): java.lang.IllegalArgumentException: all columns in order by clause should be in the selected column list!order_money


select t_order_items.* ,t_user_orders.* from t_order_items ,t_user_orders where t_order_items.order_id=t_user_orders.order_id;

select a.* ,b.* from t_order_items a ,t_user_orders b where a.order_id=b.order_id and b.order_id=1000011 ; #扫描所有分片
select a.* ,b.* from t_order_items a ,t_user_orders b where a.order_id=b.order_id and b.order_id=1000011 and b.user_id=1004; #扫描dn3,userid所在的分片节点
(root@127.0.0.1:8066) [TESTDB]> explain select *from t_user_orders where order_id=12345;
+-----------+--------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+--------------------------------------------------------------+
| dn1 | SELECT * FROM t_user_orders WHERE order_id = 12345 LIMIT 100 |
| dn2 | SELECT * FROM t_user_orders WHERE order_id = 12345 LIMIT 100 |
| dn3 | SELECT * FROM t_user_orders WHERE order_id = 12345 LIMIT 100 |
+-----------+--------------------------------------------------------------+
(root@127.0.0.1:8066) [TESTDB]> explain select *from t_user_orders where order_id=12345 and user_id=1006;
+-----------+----------------------------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+----------------------------------------------------------------------------------+
| dn2 | SELECT * FROM t_user_orders WHERE order_id = 12345 AND user_id = 1006 LIMIT 100 |
+-----------+----------------------------------------------------------------------------------+

select distinct a.user_id as a_user_id, b.order_id as b_order_id ,a.create_time from t_user a
inner join t_user_orders b on a.user_id=b.user_id order by a.create_time DESC limit 0,10;

(root@127.0.0.1:8066) [TESTDB]> explain select count(1) from (select user_id,order_money,sum(order_money) as money from t_user_orders group by user_id) a;
+-----------+---------------------------------------------------------------------------------------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+---------------------------------------------------------------------------------------------------------------------------------------------+
| dn1 | SELECT COUNT(1) AS COUNT0 FROM (SELECT user_id, order_money, SUM(order_money) AS money FROM t_user_orders GROUP BY user_id ) a LIMIT 100 |
| dn2 | SELECT COUNT(1) AS COUNT0 FROM (SELECT user_id, order_money, SUM(order_money) AS money FROM t_user_orders GROUP BY user_id ) a LIMIT 100 |
| dn3 | SELECT COUNT(1) AS COUNT0 FROM (SELECT user_id, order_money, SUM(order_money) AS money FROM t_user_orders GROUP BY user_id ) a LIMIT 100 |
+-----------+---------------------------------------------------------------------------------------------------------------------------------------------+
(root@127.0.0.1:8066) [TESTDB]> begin;
Query OK, 0 rows affected (0.00 sec)
(root@127.0.0.1:8066) [TESTDB]> insert into t_user_orders(id,user_id,order_id,order_money,sataus,note) values(next value for MYCATSEQ_T_USER_ORDERS,1006,12345,12.28,1,null);
Query OK, 1 row affected (0.00 sec)
(root@127.0.0.1:8066) [TESTDB]> insert into t_order_items(id,order_id,goods_id,goods_money,goods_count,sataus)values (next value for MYCATSEQ_T_ORDER_ITEMS,12345,12345,1.36,1,1);
Query OK, 1 row affected (0.06 sec)
(root@127.0.0.1:8066) [TESTDB]> commit;
select count(distinct user_id) from t_user_orders;
2018-05-09 01:44:16.555 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.ServerQueryHandler.query(ServerQueryHandler.java:57)) - ServerConnection [id=15, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]select count(distinct user_id) from t_user_orders
2018-05-09 01:44:16.555 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.cache.impl.EnchachePool.get(EnchachePool.java:71)) - SQLRouteCache hit cache ,key:TESTDBselect count(distinct user_id) from t_user_orders
2018-05-09 01:44:16.555 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:126)) - ServerConnection [id=15, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]select count(distinct user_id) from t_user_orders, route={
1 -> dn1{SELECT COUNT(DISTINCT user_id) AS COUNT0
FROM t_user_orders
LIMIT 100}
2 -> dn2{SELECT COUNT(DISTINCT user_id) AS COUNT0
FROM t_user_orders
LIMIT 100}
3 -> dn3{SELECT COUNT(DISTINCT user_id) AS COUNT0
FROM t_user_orders
LIMIT 100}
} rrs
------
[root@hongquan1 conf]# cat schema.xml|grep testbymonth2018
<table name="testbymonth2018" primaryKey="ID" subTables="testbymonth2018$1-12" dataNode="dn1" rule="sharding-by-month" />
[root@hongquan1 conf]# cat schema.xml|grep testbydate2018
<!-- table name="testbydate2018" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="sharding-by-date" /> -->

3 分片

1 sharding-by-month

#自然月分片 #只能使用BETWEEN 才能命中分片,否则全分片扫描(1 多库单表 2 单库多表),数据不能超过1年
===单库多表
<table name="testbymonth" primaryKey="ID" subTables="testbymonth2018$1-12" dataNode="dn1" rule="sharding-by-month" / >
<function name="partbymonth"
class="io.mycat.route.function.PartitionByMonth">
<property name="dateFormat">yyyy-MM-dd</property>
<property name="sBeginDate">2018-01-01</property>
</function>
===多库单表
<table name="mycatbymonth" primaryKey="ID" dataNode="dn$1-12" rule="sharding-by-month" />
<dataNode name="dn1" dataHost="192.168.124.55" database="db1" />
<dataNode name="dn2" dataHost="192.168.124.55" database="db2" />
.....
use db1;
CREATE TABLE `testbymonth20181` (`id` int not null,`name` varchar(60) NULL, create_time DATE ,PRIMARY KEY (`id`));
CREATE TABLE `testbymonth20182` (`id` int not null,`name` varchar(60) NULL, create_time DATE ,PRIMARY KEY (`id`));
CREATE TABLE `testbymonth20183` (`id` int not null,`name` varchar(60) NULL, create_time DATE ,PRIMARY KEY (`id`));
CREATE TABLE `testbymonth20184` (`id` int not null,`name` varchar(60) NULL, create_time DATE ,PRIMARY KEY (`id`));
(root@127.0.0.1:8066) [TESTDB]> explain insert into testbymonth2018 (id,name,create_time) values(1,'sq1', '2018-1-12');
+-----------+-------------------------------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+-------------------------------------------------------------------------------------+
| dn1 | INSERT INTO testbymonth20181 (id, name, create_time) VALUES (1, 'sq1', '2018-1-12') |
+-----------+-------------------------------------------------------------------------------------+
1 row in set (0.07 sec)

insert into testbymonth2018 (id,name,create_time) values(1,'sq1', '2018-1-12');
insert into testbymonth2018 (id,name,create_time) values(2,'sq2', '2018-1-22');
insert into testbymonth2018 (id,name,create_time) values(3,'sq3', '2018-2-5');
insert into testbymonth2018 (id,name,create_time) values(4,'sq4', '2018-2-12');
insert into testbymonth2018 (id,name,create_time) values(5,'sq5', '2018-3-12');

select * from testbymonth2018 where create_time>= '2018-1-01' and create_time<='2018-1-31'
(root@127.0.0.1:8066) [TESTDB]> explain select * from testbymonth2018 where create_time>= '2018-1-11' and create_time<='2018-1-11'
-> ;
+-----------+------------------------------------------------------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+------------------------------------------------------------------------------------------------------------+
| dn1 | SELECT * FROM testbymonth20181 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth201810 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth201811 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth201812 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20182 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20183 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20184 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20185 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20186 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20187 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20188 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
| dn1 | SELECT * FROM testbymonth20189 WHERE create_time >= '2018-1-11' AND create_time <= '2018-1-11' LIMIT 100 |
+-----------+------------------------------------------------------------------------------------------------------------+
12 rows in set (0.00 sec)

(root@127.0.0.1:8066) [TESTDB]> select * from testbymonth2018 where create_time>= '2018-1-11' and create_time<='2018-1-11';
ERROR 1105 (HY000): Table 'db1.testbymonth20188' doesn't exist
(root@127.0.0.1:8066) [TESTDB]> explain select * from testbymonth2018 where create_time BETWEEN '2018-1-01' and '2018-1-31';
+-----------+------------------------------------------------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+------------------------------------------------------------------------------------------------+
| dn1 | SELECT * FROM testbymonth20181 WHERE create_time BETWEEN '2018-1-01' AND '2018-1-31' LIMIT 100 |
+-----------+------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

(root@127.0.0.1:8066) [TESTDB]> select * from testbymonth2018 where create_time BETWEEN '2018-1-01' and '2018-1-31';
+----+------+-------------+
| id | name | create_time |
+----+------+-------------+
| 1 | sq1 | 2018-01-12 |
| 2 | sq2 | 2018-01-22 |
+----+------+-------------+
####只能使用BETWEEN 才能命中分片,否则全分片扫描

2 sharding-by-date

#按照日期(天)分片--1.6.5 取消了按天分片
<table name="testbydate2018" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="sharding-by-date" />

<tableRule name="sharding-by-date">
<rule> <columns>create_date</columns>
<algorithm>sharding-by-date</algorithm>
</rule>
</tableRule>
<function name="sharding-by-date" class="org.opencloudb.route.function.PartitionByDate">
<property name="dateFormat">yyyy-MM-dd</property> <!--日期格式-->
<property name="sBeginDate">2018-04-01</property> <!--开始日期-->
<property name="sPartionDay">10</property> <!--每分片天数-->
</function>

3 数据库自增主键,主键为Id,hash方式分片


[root@hongquan1 conf]# more /usr/local/mycat/conf/server.xml |grep sequnceHandlerType
<property name="sequnceHandlerType">2</property> ==>1
<!--<property name="sequnceHandlerType">0</property>-->
(root@127.0.0.1:9066) [TESTDB]> show @@sysparam;
| sequnceHandlerType | 数据库方式 | 指定使用Mycat全局序列的类型。
#数据库配置,创建 sequence 相关的表以及 function
#所有操作都在 db1 上
#创建 MYCAT_SEQUENCE 表
DROP TABLE IF EXISTS MYCAT_SEQUENCE;
– name sequence 名称
– current_value 当前 value
– increment 增长步长! mycat在数据库中一次读取多少个sequence

CREATE TABLE MYCAT_SEQUENCE (name VARCHAR(50) NOT NULL,current_value INT
NOT NULL,increment INT NOT NULL DEFAULT 100, PRIMARY KEY(name))
ENGINE=InnoDB;

#插入一条 sequence
INSERT INTO MYCAT_SEQUENCE(name,current_value,increment) VALUES ('PERSON',1, 1);
INSERT INTO db1.MYCAT_SEQUENCE(name,current_value,increment) VALUES ('GLOBAL', 1, 1);
INSERT INTO db1.MYCAT_SEQUENCE(name,current_value,increment) VALUES ('COMPANY', 2, 10);
INSERT INTO db1.MYCAT_SEQUENCE(name,current_value,increment) VALUES ('TABLE1', 2, 10);

#创建相关 function
DROP FUNCTION IF EXISTS `mycat_seq_currval`;
DELIMITER ;;
CREATE DEFINER=`system`@`%` FUNCTION `mycat_seq_currval`(seq_name VARCHAR(50)) RETURNS varchar(64) CHARSET latin1
DETERMINISTIC
BEGIN
DECLARE retval VARCHAR(64);
SET retval="-999999999,null";
SELECT concat(CAST(current_value AS CHAR),",",CAST(increment AS CHAR) ) INTO retval FROM MYCAT_SEQUENCE WHERE name = seq_name;
RETURN retval ;
END
;;
DELIMITER ;

DROP FUNCTION IF EXISTS `mycat_seq_nextval`;
DELIMITER ;;
CREATE DEFINER=`system`@`%` FUNCTION `mycat_seq_nextval`(seq_name VARCHAR(50)) RETURNS varchar(64) CHARSET latin1
DETERMINISTIC
BEGIN
UPDATE MYCAT_SEQUENCE
SET current_value = current_value + increment WHERE name = seq_name;
RETURN mycat_seq_currval(seq_name);
END
;;
DELIMITER ;

DROP FUNCTION IF EXISTS `mycat_seq_setval`;
DELIMITER ;;
CREATE DEFINER=`system`@`%` FUNCTION `mycat_seq_setval`(seq_name VARCHAR(50), value INTEGER) RETURNS varchar(64) CHARSET latin1
DETERMINISTIC
BEGIN
UPDATE MYCAT_SEQUENCE
SET current_value = value
WHERE name = seq_name;
RETURN mycat_seq_currval(seq_name);
END
;;
DELIMITER ;

vi sequence_db_conf.properties
PERSON=dn1
<table name="person" primaryKey="id" autoIncrement="true" dataNode="dn1,dn2,dn3" rule="mod-long" />

(root@127.0.0.1:9066) [TESTDB]> reload @@config;
(root@127.0.0.1:8066) [TESTDB]> select next value for MYCATSEQ_GLOBAL,next value for MYCATSEQ_GLOBAL;
ERROR 1003 (HY000): mycat sequnce err.java.lang.NullPointerException

[root@hongquan1 conf]# /usr/local/mycat/bin/mycat restart
(root@127.0.0.1:8066) [TESTDB]> select next value for MYCATSEQ_GLOBAL,next value for MYCATSEQ_GLOBAL;
+---+---+
| 2 | 3 |
+---+---+
| 2 | 3 |
+---+---+
1 row in set (0.24 sec)
select next value for MYCATSEQ_GLOBAL,next value for MYCATSEQ_COMPANY;

create table person(
id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
name varchar(16) not null,
school int(4) not null,
age int(3) not null,
addr varchar(32),
zcode int(10),
birth datetime,
score int(3),PRIMARY KEY (id))ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

insert into person(id,name,school,age,addr,zcode,birth,score)
values(next value for MYCATSEQ_PERSON,'xiaoming',100,19,'gz-tianhe',1254565,now(),90);

(root@127.0.0.1:8066) [TESTDB]> explain insert into person(id,name, school, age, addr, zcode, birth, score)
-> values(NEXT VALUE FOR MYCATSEQ_PERSON,'hh', 100, 30,
-> 'sabc-123','072450','1987-02-01',100);
ERROR 1064 (HY000): insert sql using mycat seq,you must provide primaryKey value for explain
(root@127.0.0.1:8066) [TESTDB]> show create table person;
(root@127.0.0.1:8066) [TESTDB]> explain select * from person;
+-----------+--------------------------------+
| DATA_NODE | SQL |
+-----------+--------------------------------+
| dn1 | SELECT * FROM person LIMIT 100 |
| dn2 | SELECT * FROM person LIMIT 100 |
| dn3 | SELECT * FROM person LIMIT 100 |
+-----------+--------------------------------+
3 rows in set (0.00 sec)

(root@127.0.0.1:8066) [TESTDB]> explain select * from person where id = 3;
+-----------+-----------------------------------+
| DATA_NODE | SQL |
+-----------+-----------------------------------+
| dn1 | select * from person where id = 3 |
+-----------+-----------------------------------+
1 row in set (0.00 sec)

(root@127.0.0.1:8066) [TESTDB]> explain select * from person where id = 5;
+-----------+-----------------------------------+
| DATA_NODE | SQL |
+-----------+-----------------------------------+
| dn3 | select * from person where id = 5 |
+-----------+-----------------------------------+

4 分片枚举,按照地理位置,比如省份


[root@hongquan1 conf]# vim schema.xml
<table name="t_vote" primaryKey="id" autoIncrement="true" dataNode="dn2,dn1,dn3" rule="sharding-by-intfile-province" />

INSERT INTO db1.MYCAT_SEQUENCE(name,current_value,increment) VALUES ('T_VOTE', 1, 2);
[root@hongquan1 conf]# vim sequence_db_conf.properties
T_VOTE=dn1
[root@hongquan1 conf]# vim rule.xml
<tableRule name="sharding-by-intfile-province">
<rule>
<columns>province</columns>
<algorithm>hash-int-province</algorithm>
</rule>
</tableRule>
<function name="hash-int-province" class="io.mycat.route.function.PartitionByFileMap">
<property name="mapFile">partition-hash-int-province.txt</property>
<property name="type">1</property>
<property name="defaultNode">0</property>
</function>
[root@hongquan1 conf]# vim partition-hash-int-province.txt
sichuan=0
guangdong=1
hunan=2
DEFAULT_NODE=2
[root@hongquan1 conf]# chmod 777 partition-hash-int-province.txt
[root@hongquan1 conf]# chown mycat:mycat partition-hash-int-province.txt
(root@127.0.0.1:8066) [TESTDB]> select next value for MYCATSEQ_T_VOTE;
explain create table t_vote (id int not null primary key,province varchar(100) not null);
insert into t_vote(id,province) values(1,'sichuan');
insert into t_vote(id,province) values(2,'guangdong');
insert into t_vote(id,province) values(3,'hunan');
explain select * from t_vote where province='hunan';
(root@127.0.0.1:8066) [TESTDB]> explain select * from t_vote where province='hunan';
+-----------+---------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+---------------------------------------------------------+
| dn3 | SELECT * FROM t_vote WHERE province = 'hunan' LIMIT 100 |
+-----------+---------------------------------------------------------+

5 ER分片


joinKey属性
插入子表的时候会使用这个列的值查找父表存储的数据节点。
parentKey属性
属性指定的值一般为与父表建立关联关系的列名。程序首先获取joinkey的值,再通过parentKey属性指定的列名产生查询语句,通过执行该语句得到父表存储在哪个分片上。从而确定子表存储的位置

<table name="customer" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile">
<childTable name="orders" primaryKey="ID" joinKey="customer_id" parentKey="id">
<childTable name="order_items" joinKey="order_id" parentKey="id" />
</childTable>
<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" parentKey="id" />
</table>

1).父表按照主键ID分片,子表的分片字段与主表ID关联,配置为ER分片
(1)第一种分片:父表按照主键ID分片
----1
<table name="er_test1" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="mod-long">
<childTable name="test1_child1" primaryKey="ID" joinKey="ID" parentKey="ID">
</childTable>
</table>

<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>

explain create table er_test1 (ID bigint not null AUTO_INCREMENT primary key ,test_col1 varchar(100),create_date datetime);
explain create table test1_child1 (ID bigint not null AUTO_INCREMENT primary key ,create_date datetime);

insert into er_test1 (ID,test_col1,create_date) values(1,'test1',now());
insert into er_test1 (ID,test_col1,create_date) values(2,'test2',now());
insert into er_test1 (ID,test_col1,create_date) values(3,'test3',now());
insert into test1_child1 (ID,create_date) values(1,now());

explain select * from er_test1 where id=2;
explain select * from test1_child1 where id=2;
(root@127.0.0.1:8066) [TESTDB]> explain select * from er_test1 where id=2;
+-----------+-----------------------------------+
| DATA_NODE | SQL |
+-----------+-----------------------------------+
| dn3 | select * from er_test1 where id=2 |
+-----------+-----------------------------------+
1 row in set (0.02 sec)

(root@127.0.0.1:8066) [TESTDB]> explain select * from test1_child1 where id=2;
+-----------+---------------------------------------+
| DATA_NODE | SQL |
+-----------+---------------------------------------+
| dn3 | select * from test1_child1 where id=2 |
+-----------+---------------------------------------+

2018-05-08 07:22:02.198 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:289)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB] explain select * from test1_child1 where id=2
2018-05-08 07:22:02.199 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.ServerQueryHandler.query(ServerQueryHandler.java:57)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]explain select * from test1_child1 where id=2
2018-05-08 07:22:02.199 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.cache.impl.EnchachePool.get(EnchachePool.java:77)) - SQLRouteCache miss cache ,key:TESTDBselect * from test1_child1 where id=2
2018-05-08 07:22:02.199 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.route.util.RouterUtil.findRouteWithcConditionsForTables(RouterUtil.java:1329)) - try to find cache by primary key
2018-05-08 07:22:02.199 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.cache.impl.EnchachePool.get(EnchachePool.java:77)) - TableID2DataNodeCache.TESTDB_TEST1_CHILD1 miss cache ,key:2
2018-05-08 07:22:02.199 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.route.util.RouterUtil.ruleByJoinValueCalculate(RouterUtil.java:931)) - found partion node (using parent partion rule directly) for child table to insert [dn3] sql :select * from test1_child1 where id=2
2018-05-08 07:22:02.199 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.route.util.RouterUtil.findRouteWithcConditionsForTables(RouterUtil.java:1437)) - found partion nodes (using parent partion rule directly) for child table to update [dn3] sql :select * from test1_child1 where id=2

----
---2
表设计:父表student,子表selectcourse
student(id,stu_id);
selectcourse(id,stu_id,cou_id);

在schema.xml中增加父表、子表定义:
<table name="student" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="mod-long">
<childTable name="selectcourse" primaryKey="ID" joinKey="stu_id" parentKey="id" />
</table>

在mysql客户端中执行创建表的语句:
create table student(id bigint not null primary key,stu_id bigint not null);
create table selectcourse(id bigint not null primary key,stu_id bigint not null,cou_id bigint not null);

插入父表记录
insert into student(id,stu_id) values(1,3001);
insert into student(id,stu_id) values(2,3002);

插入子表记录
insert into selectcourse(id,stu_id,cou_id) values(1,1,1); //同时观察日志
总结:直接使用父表的分片规则(id字段mod算法)来查找节点
(root@127.0.0.1:8066) [TESTDB]> explain select *from selectcourse where id=1;
+-----------+--------------------------------------+
| DATA_NODE | SQL |
+-----------+--------------------------------------+
| dn1 | select *from selectcourse where id=1 |
| dn2 | select *from selectcourse where id=1 |
| dn3 | select *from selectcourse where id=1 |
+-----------+--------------------------------------+
3 rows in set (0.00 sec)

(root@127.0.0.1:8066) [TESTDB]> explain select *from selectcourse where stu_id=1;
+-----------+-------------------------------------------------------+
| DATA_NODE | SQL |
+-----------+-------------------------------------------------------+
| dn2 | SELECT * FROM selectcourse WHERE stu_id = 1 LIMIT 100 |
+-----------+-------------------------------------------------------+

2018-05-08 07:26:05.073 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:289)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB] insert into selectcourse(id,stu_id,cou_id) values(1,1,1)
2018-05-08 07:26:05.073 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.ServerQueryHandler.query(ServerQueryHandler.java:57)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]insert into selectcourse(id,stu_id,cou_id) values(1,1,1)
2018-05-08 07:26:05.073 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.route.util.RouterUtil.routeByERParentKey(RouterUtil.java:889)) - found partion node (using parent partion rule directly) for child table to insert dn2 sql :INSERT INTO selectcourse (id, stu_id, cou_id)
VALUES (1, 1, 1)
2018-05-08 07:26:05.073 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:126)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]INSERT INTO selectcourse (id, stu_id, cou_id)
VALUES (1, 1, 1), route={
1 -> dn2{INSERT INTO selectcourse (id, stu_id, cou_id)
VALUES (1, 1, 1)}
} rrs
2018-05-08 07:26:05.074 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.SingleNodeHandler.execute(SingleNodeHandler.java:167)) - rrs.getRunOnSlave() null
2018-05-08 07:26:05.074 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.SingleNodeHandler.execute(SingleNodeHandler.java:169)) - node.getRunOnSlave() null
2018-05-08 07:26:05.074 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.SingleNodeHandler.execute(SingleNodeHandler.java:178)) - node.getRunOnSlave() null
2018-05-08 07:26:05.074 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.SingleNodeHandler.execute(SingleNodeHandler.java:180)) - node.getRunOnSlave() null
2018-05-08 07:26:05.074 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:96)) - rrs.getRunOnSlave() null
2018-05-08 07:26:05.074 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:127)) - rrs.getRunOnSlave() null
2018-05-08 07:26:05.098 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:378)) - release connection MySQLConnection [id=17, lastTime=1525735565064, user=system, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=53136, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{INSERT INTO selectcourse (id, stu_id, cou_id)
VALUES (1, 1, 1)}, respHandler=SingleNodeHandler [node=dn2{INSERT INTO selectcourse (id, stu_id, cou_id)
VALUES (1, 1, 1)}, packetId=1], host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]


---
2).父表的分片字段为其他字段,子表的分片字段与主表ID关联,配置为ER分片
---1
<table name="er_test2" primaryKey="id" dataNode="dn1,dn2,dn3" rule="sharding-by-intfile-tester2">
<childTable name="test1_child2" primaryKey="id" joinKey="id" parentKey="id"/>
</table>

<tableRule name="sharding-by-intfile-tester2">
<rule>
<columns>test_col2</columns>
<algorithm>hash-int-tester2</algorithm>
</rule>
</tableRule>
<function name="hash-int-tester2" class="io.mycat.route.function.PartitionByFileMap">
<property name="mapFile">partition-hash-int-tester2.txt</property>
<property name="type">1</property>
<property name="defaultNode">0</property>
</function>
### Caused by: org.xml.sax.SAXParseException; lineNumber: 39; columnNumber: 110; Attribute "parentKey" is required and must be specified for element type "childTable"
cat partition-hash-int-tester2.txt
a,b,c=0
d,e,f=1
g,h,i=2

create table er_test2 (ID bigint not null AUTO_INCREMENT primary key ,test_col2 varchar(100),create_date datetime);
create table test1_child2 (ID bigint not null,create_date datetime);
insert into er_test2 (ID,test_col2,create_date) values(3,'z',now());
insert into er_test2 (ID,test_col2,create_date) values(1,'a',now());
insert into er_test2 (ID,test_col2,create_date) values(2,'f',now());

insert into test1_child2 (ID,create_date) values(1,now());

---2
表设计:父表book,子表sail
book(id,book_id);
sail(id,book_id,custo_id);

在rule.xml中增加“mod-long-book”分片方法:分片字段为book_id
<tableRule name="mod-long-book">
<rule>
<columns>book_id</columns>
<algorithm>mod-long</algorithm>
</rule>
</tableRule>


在schema.xml中增加父表、子表定义:父表用"mod-long-book"方法分片,
<table name="book" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="mod-long-book">
<childTable name="sail" primaryKey="ID" joinKey="book_id" parentKey="id" />
</table>

在mysql客户端中执行创建表的语句:
create table book(id bigint not null primary key,book_id bigint not null);
create table sail(id bigint not null primary key,book_id bigint not null,customer_id bigint not null);

插入父表记录:
insert into book(id,book_id) values(1,3001);
insert into book(id,book_id) values(2,3002);

插入子表记录
insert into sail(id,book_id,customer_id) values(1,2,2001);//同时观察日志

---先按照book_id 进行分片,计算出分片节点,子表根据id进行父表关联,存入id相同的分片节点。父表的id必须先存在子表才能插入。
---子表的book_id并非父表的book_id,而是父表的book_id对应的主键id(parentKey="id")

(system@127.0.0.1:3306) [(none)]> select * from db2.book;
+----+---------+
| id | book_id |
+----+---------+
| 1 | 3001 |
(system@127.0.0.1:3306) [(none)]> select * from db2.sail;
+----+---------+-------------+
| id | book_id | customer_id |
+----+---------+-------------+
| 2 | 1 | 1111 |
(system@127.0.0.1:3306) [(none)]> select * from db3.book;
+----+---------+
| id | book_id |
+----+---------+
| 2 | 3002 |
+----+---------+
(system@127.0.0.1:3306) [(none)]> select * from db3.sail;
+----+---------+-------------+
| id | book_id | customer_id |
+----+---------+-------------+
| 1 | 2 | 2001 |
+----+---------+-------------+
(root@127.0.0.1:8066) [TESTDB]> explain insert into sail(id,book_id,customer_id) values(3,1,1231); ##根据book_id=1 找出父表book.id=1在哪一个分片节点,然后在此节点插入数据
(system@127.0.0.1:3306) [(none)]> select * from db2.sail; ###对应的book_Id相同的id,都落在同一个分片节点上面。
+----+---------+-------------+
| id | book_id | customer_id |
+----+---------+-------------+
| 2 | 1 | 1111 |
| 3 | 1 | 1231 |
+----+---------+-------------+

总结:先通过父表的id字段查询分片,再往相应的分片中插入数据。
比第一种方法多了一个“查找分片”的步骤。
(root@127.0.0.1:8066) [TESTDB]> explain select *from book where id =1;
+-----------+-------------------------------+
| DATA_NODE | SQL |
+-----------+-------------------------------+
| dn1 | select *from book where id =1 |
| dn2 | select *from book where id =1 |
| dn3 | select *from book where id =1 |
+-----------+-------------------------------+
3 rows in set (0.00 sec)

(root@127.0.0.1:8066) [TESTDB]> explain select *from book where book_id =3001;
+-----------+---------------------------------------------------+
| DATA_NODE | SQL |
+-----------+---------------------------------------------------+
| dn2 | SELECT * FROM book WHERE book_id = 3001 LIMIT 100 |
+-----------+---------------------------------------------------+

2018-05-08 07:35:46.426 DEBUG [BusinessExecutor0] (io.mycat.cache.impl.EnchachePool.putIfAbsent(EnchachePool.java:60)) - ER_SQL2PARENTID add cache ,key:TESTDB:select book.id from book where book.id=2 value:dn3
2018-05-08 07:35:46.426 DEBUG [BusinessExecutor2] (io.mycat.route.util.RouterUtil$3.onSuccess(RouterUtil.java:1692)) - found partion node for child table to insert dn3 sql :insert into sail(id,book_id,customer_id) values(1,2,2001)
2018-05-08 07:35:46.426 DEBUG [BusinessExecutor2] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:126)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]INSERT INTO sail (id, book_id, customer_id)
VALUES (1, 2, 2001), route={
1 -> dn3{insert into sail(id,book_id,customer_id) values(1,2,2001)}
} rrs

---2
(root@127.0.0.1:8066) [TESTDB]> explain insert into sail(id,book_id,customer_id) values(2,3001,2001);
ERROR 1064 (HY000): can't find (root) parent sharding node for sql:insert into sail(id,book_id,customer_id) values(2,3001,2001)

2018-05-08 07:39:37.846 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:289)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB] explain insert into sail(id,book_id,customer_id) values(2,3001,2001)
2018-05-08 07:39:37.846 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.ServerQueryHandler.query(ServerQueryHandler.java:57)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]explain insert into sail(id,book_id,customer_id) values(2,3001,2001)
2018-05-08 07:39:37.846 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.route.util.RouterUtil.processERChildTable(RouterUtil.java:1662)) - find root parent's node sql select book.id from book where book.id=3001
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.cache.impl.EnchachePool.get(EnchachePool.java:77)) - ER_SQL2PARENTID miss cache ,key:TESTDB:select book.id from book where book.id=3001
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.mysql.nio.handler.FetchStoreNodeOfChildTableHandler.execute(FetchStoreNodeOfChildTableHandler.java:76)) - find child node with sql:select book.id from book where book.id=3001
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.mysql.nio.handler.FetchStoreNodeOfChildTableHandler.execute(FetchStoreNodeOfChildTableHandler.java:84)) - execute in datanode dn1
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:96)) - rrs.getRunOnSlave() false
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:118)) - rrs.getRunOnSlave() false
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.mysql.nio.handler.FetchStoreNodeOfChildTableHandler.execute(FetchStoreNodeOfChildTableHandler.java:84)) - execute in datanode dn2
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:96)) - rrs.getRunOnSlave() false
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:118)) - rrs.getRunOnSlave() false
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.mysql.nio.handler.FetchStoreNodeOfChildTableHandler.execute(FetchStoreNodeOfChildTableHandler.java:84)) - execute in datanode dn3
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:96)) - rrs.getRunOnSlave() false
2018-05-08 07:39:37.847 DEBUG [BusinessExecutor1] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:118)) - rrs.getRunOnSlave() false
2018-05-08 07:39:37.847 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=7, lastTime=1525736377846, user=system, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=52816, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-08 07:39:37.847 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=2, lastTime=1525736377846, user=system, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=52824, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-08 07:39:37.847 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=4, lastTime=1525736377846, user=system, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=52822, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-08 07:39:37.905 WARN [BusinessExecutor0] (io.mycat.route.util.RouterUtil$3.onSuccess(RouterUtil.java:1682)) - io.mycat.server.NonBlockingSession@1ae6fc6binsert into sail(id,book_id,customer_id) values(2,3001,2001) err:can't find (root) parent sharding node for sql:insert into sail(id,book_id,customer_id) values(2,3001,2001)

(root@127.0.0.1:8066) [TESTDB]> explain insert into sail(id,book_id,customer_id) values(2,1,1111);
系统先执行sql select book.id from book where book.id=1,找到节点dn2
2018-05-08 07:42:34.063 DEBUG [BusinessExecutor2] (io.mycat.cache.impl.EnchachePool.putIfAbsent(EnchachePool.java:60)) - ER_SQL2PARENTID add cache ,key:TESTDB:select book.id from book where book.id=1 value:dn2
2018-05-08 07:42:34.064 DEBUG [BusinessExecutor1] (io.mycat.route.util.RouterUtil$3.onSuccess(RouterUtil.java:1692)) - found partion node for child table to insert dn2 sql :insert into sail(id,book_id,customer_id) values(2,1,1111)
2018-05-08 07:42:34.064 DEBUG [BusinessExecutor1] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:126)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]INSERT INTO sail (id, book_id, customer_id)
VALUES (2, 1, 1111), route={
1 -> dn2{insert into sail(id,book_id,customer_id) values(2,1,1111)}
} rrs

(root@127.0.0.1:8066) [TESTDB]> explain select *from sail where book_id=1;
+-----------+------------------------------------------------+
| DATA_NODE | SQL |
+-----------+------------------------------------------------+
| dn1 | SELECT * FROM sail WHERE book_id = 1 LIMIT 100 |
| dn2 | SELECT * FROM sail WHERE book_id = 1 LIMIT 100 |
| dn3 | SELECT * FROM sail WHERE book_id = 1 LIMIT 100 |
+-----------+------------------------------------------------+
2018-05-08 07:45:15.323 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:289)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB] explain select *from sail where book_id=1
2018-05-08 07:45:15.323 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.ServerQueryHandler.query(ServerQueryHandler.java:57)) - ServerConnection [id=1, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]explain select *from sail where book_id=1
2018-05-08 07:45:15.323 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.cache.impl.EnchachePool.get(EnchachePool.java:71)) - SQLRouteCache hit cache ,key:TESTDBselect *from sail where book_id=1

6 范围求模分片 auto-sharding-rang-mod

(root@127.0.0.1:9066) [TESTDB]> show @@processor;
+------------+--------+---------+-------------+---------+---------+--------------+--------------+------------+----------+----------+----------+
| NAME | NET_IN | NET_OUT | REACT_COUNT | R_QUEUE | W_QUEUE | FREE_BUFFER | TOTAL_BUFFER | BU_PERCENT | BU_WARNS | FC_COUNT | BC_COUNT |
+------------+--------+---------+-------------+---------+---------+--------------+--------------+------------+----------+----------+----------+
| Processor0 | 915941 | 9646 | 0 | 0 | 0 | 343597383680 | 83886080 | -409500 | 0 | 1 | 11 |
| Processor1 | 911157 | 11599 | 0 | 0 | 0 | 343597383680 | 83886080 | -409500 | 0 | 0 | 12 |
+------------+--------+---------+-------------+---------+---------+--------------+--------------+------------+----------+----------+----------+

7 一致性hash
<property name="count">2</property>
<table name="partition_by_murmur_hash" primaryKey="id" dataNode="dn$1-3" rule="sharding-by-murmur" />
CREATE TABLE partition_by_murmur_hash (id int(10) null,db_nm varchar(20) NULL);
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (1, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (2, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (3, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (4, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (5, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (6, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (7, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (8, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (9, database());
INSERT INTO `partition_by_murmur_hash` (id,db_nm) VALUES (10, database());
select * from partition_by_murmur_hash;


8 alter table t_user add(country_id int(10) UNSIGNED not null default 0)

2018-05-09 02:15:21.954 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=55, lastTime=1525803321951, user=system, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=true, threadId=227, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.20.119, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-09 02:15:31.111 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:289)) - ServerConnection [id=15, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB] alter table t_user add(country_id int(10) UNSIGNED not null default 0)
2018-05-09 02:15:31.111 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.ServerQueryHandler.query(ServerQueryHandler.java:57)) - ServerConnection [id=15, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]alter table t_user add(country_id int(10) UNSIGNED not null default 0)
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.NonBlockingSession.execute(NonBlockingSession.java:126)) - ServerConnection [id=15, schema=TESTDB, host=127.0.0.1, user=root,txIsolation=3, autocommit=true, schema=TESTDB]alter table t_user add(country_id int(10) UNSIGNED not null default 0), route={
1 -> dn1{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}
2 -> dn2{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}
3 -> dn3{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}
} rrs
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.<init>(MultiNodeQueryHandler.java:124)) - execute mutinode query alter table t_user add(country_id int(10) UNSIGNED not null default 0)
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:193)) - rrs.getRunOnSlave()-null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:203)) - node.getRunOnSlave()1-null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:205)) - node.getRunOnSlave()2-null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:96)) - rrs.getRunOnSlave() null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:127)) - rrs.getRunOnSlave() null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.MySQLConnection.synAndDoExecute(MySQLConnection.java:451)) - con need syn ,total syn cmd 1 commands schema change:true con:MySQLConnection [id=165, lastTime=1525803331112, user=system, schema=db1, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=88403, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:203)) - node.getRunOnSlave()1-null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:205)) - node.getRunOnSlave()2-null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:96)) - rrs.getRunOnSlave() null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:127)) - rrs.getRunOnSlave() null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:203)) - node.getRunOnSlave()1-null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.execute(MultiNodeQueryHandler.java:205)) - node.getRunOnSlave()2-null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:96)) - rrs.getRunOnSlave() null
2018-05-09 02:15:31.112 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDBNode.getConnection(PhysicalDBNode.java:127)) - rrs.getRunOnSlave() null
2018-05-09 02:15:31.113 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.okResponse(MultiNodeQueryHandler.java:254)) - received ok response ,executeResponse:false from MySQLConnection [id=165, lastTime=1525803331111, user=system, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=88403, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=io.mycat.backend.mysql.nio.MySQLConnection$StatusSync@42f7b530, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.258 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.okResponse(MultiNodeQueryHandler.java:254)) - received ok response ,executeResponse:true from MySQLConnection [id=21, lastTime=1525803331111, user=system, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=55218, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.258 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:378)) - release connection MySQLConnection [id=21, lastTime=1525803331111, user=system, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=55218, charset=utf8, txIsolation=3, autocommit=true, attachment=dn2{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.258 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=21, lastTime=1525803331111, user=system, schema=db2, old shema=db2, borrowed=true, fromSlaveDB=false, threadId=55218, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-09 02:15:31.258 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.okResponse(MultiNodeQueryHandler.java:254)) - received ok response ,executeResponse:true from MySQLConnection [id=160, lastTime=1525803331111, user=system, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=87464, charset=utf8, txIsolation=3, autocommit=true, attachment=dn3{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.258 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler.okResponse(MultiNodeQueryHandler.java:254)) - received ok response ,executeResponse:true from MySQLConnection [id=165, lastTime=1525803331111, user=system, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=88403, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.258 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:378)) - release connection MySQLConnection [id=160, lastTime=1525803331111, user=system, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=87464, charset=utf8, txIsolation=3, autocommit=true, attachment=dn3{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.259 DEBUG [$_NIOREACTOR-1-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=160, lastTime=1525803331111, user=system, schema=db3, old shema=db3, borrowed=true, fromSlaveDB=false, threadId=87464, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]
2018-05-09 02:15:31.259 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.server.NonBlockingSession.releaseConnection(NonBlockingSession.java:378)) - release connection MySQLConnection [id=165, lastTime=1525803331111, user=system, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=88403, charset=utf8, txIsolation=3, autocommit=true, attachment=dn1{alter table t_user add(country_id int(10) UNSIGNED not null default 0)}, respHandler=io.mycat.backend.mysql.nio.handler.MultiNodeQueryHandler@2d714a6f, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=true]
2018-05-09 02:15:31.259 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.backend.datasource.PhysicalDatasource.releaseChannel(PhysicalDatasource.java:595)) - release channel MySQLConnection [id=165, lastTime=1525803331111, user=system, schema=db1, old shema=db1, borrowed=true, fromSlaveDB=false, threadId=88403, charset=utf8, txIsolation=3, autocommit=true, attachment=null, respHandler=null, host=192.168.20.118, port=3306, statusSync=null, writeQueue=0, modifiedSQLExecuted=false]

原文地址:https://www.cnblogs.com/yhq1314/p/9981806.html