配置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)
總結(jié)如下:
最開始的id=current_value+increment,繼續(xù)插入時(shí)如果id一直<第二次的current_value+increment,current_value不會(huì)變,直到自增id 超過,然后current_value變?yōu)閏urrent_value+increment,以此類推
參考:
http://www.cnblogs.com/raphael5200/p/5900007.html
https://github.com/yujiahui/Mycat-doc/blob/master/MyCAT自增字段和返回生成的主鍵ID的經(jīng)驗(yàn)分享
<table name="employee" primarykey="ID" datanode="dn1,dn2"