配置Server.xml
mysql> insert into employee(id,name,sharding_id) values (91,'123',10010);
Query OK, 1 row affected (0.12 sec)
mysql> select * from employee;
+----+------+-------------+
| id | name | sharding_id |
+----+------+-------------+
| 91 | 123 | 10000 |
| 92 | 123 | 10000 |
| 93 | 123 | 10010 |
| 94 | 123 | 10010 |
| 91 | 123 | 10010 |
+----+------+-------------+
4 rows in set (0.01 sec)
总结如下:
最开始的id=current_value+increment,继续插入时如果id一直<第二次的current_value+increment,current_value不会变,直到自增id 超过,然后current_value变为current_value+increment,以此类推
参考:
http://www.cnblogs.com/raphael5200/p/5900007.html
https://github.com/yujiahui/Mycat-doc/blob/master/MyCAT自增字段和返回生成的主键ID的经验分享
<table name="employee" primarykey="ID" datanode="dn1,dn2"