Atlas分表

A tlas在库内完成分表,使用参数tables指定
tables = test.tb1.id.3
首先创建三张结构完成相同的子表tb1_0、tb1_1、tb1_2
CREATE TABLE `tb1_0` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `age` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
然后使用tb1插入
insert into tb1 values (9,'a',20);
insert into tb1 values (10,'a',20);
insert into tb1 values (11,'a',20);
查询子表,数据已按id列取模分表存储
MySQL [test]> select * from tb1_0;
+----+------+------+
| id | name | age  |
+----+------+------+
|  9 | a    |   20 |
+----+------+------+

MySQL [test]> select * from tb1_1;
+----+------+------+
| id | name | age  |
+----+------+------+
| 10 | a    |   20 |
+----+------+------+

MySQL [test]> select * from tb1_2;
+----+------+------+
| id | name | age  |
+----+------+------+
| 11 | a    |   20 |
+----+------+------+
主表查询
MySQL [test]> select * from tb1 where id =11;
+----+------+------+
| id | name | age  |
+----+------+------+
| 11 | a    |   20 |

限制

1、多行插入不分表

MySQL [test]> insert into tb1 values (1,'a',20),(2,'b',21),(3,'c',21),(4,'d',22),(5,'e',20),(6,'f',21),(7,'g',20),(8,'h',22);
MySQL [test]> select * from tb1_1;
+----+------+------+
| id | name | age  |
+----+------+------+
|  1 | a    |   20 |
|  2 | b    |   21 |
|  3 | c    |   21 |
|  4 | d    |   22 |
|  5 | e    |   20 |
|  6 | f    |   21 |
|  7 | g    |   20 |
|  8 | h    |   22 |
| 10 | a    |   20 |
+----+------+------+
2、不支持不加分表字段的语句

MySQL [test]> select * from tb1;
ERROR 1146 (42S02): Table 'test.tb1' doesn't exist
select * from tb1 where name = 'a';
ERROR 1146 (42S02): Table 'test.tb1' doesn't exist
MySQL [test]> select * from tb1 where age = 20;
ERROR 1146 (42S02): Table 'test.tb1' doesn't exist
MySQL [test]> update tb1 set age=30 where age =20;
ERROR 1146 (42S02): Table 'test.tb1' doesn't exist
MySQL [test]<span id="transmark"></span>> delete from tb1 where age=20;
ERROR 1146 (42S02): Table 'test.tb1' doesn't exist
MySQL [test]> update tb1 set age=30 ;
ERROR 1105 (07000): Proxy Warning - Syntax Forbidden
3、更新后,数据不会移动,仍在原子表中

MySQL [test]> update tb1 set id=12 where id =11;
MySQL [test]> select * from tb1_2;
+----+------+------+
| id | name | age  |
+----+------+------+
| 12 | a    |   20 |
+----+------+------+

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

上海阿丽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值