技术标签: shardingsphere database 分库分表
绑定表:就是mycat的ER表。
如我们的order表进行了数据分片,那么order_item也要分片,同时要求分片的数据不会混乱,记录order_id = 1落入t_order1,那他对应的明细要落t_order_item_1。
查询时就是t_order1 join t_order_item_1,否则会出现笛卡尔积现象。
yml:
sharding:
tables:
t_order:
actualDataNodes: ds0.t_order$->{0..1}
table-strategy:
inline:
sharding-column: order_id
#根据字段值求模
algorithm-expression: t_order$->{order_id % 2}
key-generator:
column: order_id
type: SNOWFLAKE
props:
worker:
id: ${workerId}
max:
vibration:
offset: 1
t_order_item:
actualDataNodes: ds0.t_order_item$->{0..1}
table-strategy:
inline:
sharding-column: order_id
#根据字段值求模
algorithm-expression: t_order_item$->{order_id % 2}
key-generator:
column: id
type: SNOWFLAKE
props:
worker:
id: ${workerId}
max:
vibration:
offset: 1
bindingTables:
- t_order,t_order_item
broadcastTables:
- t_adress
PS:注意位置,yml格式中bindingTables和tables是同级的。
数据表(t_order在之前inline分片中已展示):
@Data
@TableName("t_order_item")
public class OrderItemPo implements Serializable {
@TableId(value = "id",type = IdType.AUTO)
private Long id;
@TableField(value = "order_id")
private Long orderId;
@TableField("goods_name")
private String goodsName;
@TableField("quantity")
private Integer quantity;
@TableField("goods_price")
private BigDecimal goodsPrice;
}
测试:
@Test
void insertOrderDemo(){
String preCode = "ack_";
for (int i = 1; i <= 10; i++) {
OrderPo orderPo = new OrderPo(preCode + i, new Random().nextInt(10) + i, BigDecimal.TEN);
orderMapper.insert(orderPo);
orderItemMapper.insert(new OrderItemPo(orderPo.getOrderId(),"日化用品",10,BigDecimal.TEN));
}
}
全局表:分库时每个库都需要使用且数据量较小的表,此时跨库查询太过影响性能,选择每个库都创建一个相同的表,如字典表。
yml:
tables:
t_adress:
actualDataNodes: ds$->{0..1}.t_adress #这里是多个库,表只有一张
keyGenerator:
column: id
type: SNOWFLAKE
props:
worker:
id: ${workerId}
max:
vibration:
offset: 1
broadcastTables: #与tables同一级别,位置不能错
- t_adress
数据表:
@Data
@TableName("t_adress")
public class AdressPo implements Serializable {
@TableId(value = "id",type = IdType.AUTO)
private Long id;
@TableField("adress")
private String adress;
@TableField("code")
private String code;
}
测试:
@Test
void insertAdressDemo(){
String preCode = "ack_";
for (int i = 1; i <= 10; i++) {
//PS:执行一次,两个数据库都会插入
adressMapper.insert(new AdressPo("一个街道",preCode+i));
}
}
文章浏览阅读1.1k次。//如果直接使用这种方法是会报错的setTimeout(this.functionName,300)//在后面加个.bind(this)setTimeout(this.functionName.bind(this),300)_js 函数定时调用自己
文章浏览阅读634次,点赞9次,收藏14次。SCI一区 | Matlab实现SSA-CNN-LSTM-Mutilhead-Attention麻雀算法优化卷积长短期记忆神经网络融合多头注意力机制多变量时间序列预测
文章浏览阅读837次。你是否有这样的疑惑?有些名词、概念自己经常听到过,但自己确搞不明白它具体是什么,如何解释它。是否经常觉得自己的认知能力、思考能力不足。你有没有这样的时候?时常感觉很痛苦,感觉不是很强烈,却很持久,也不知道为什么痛苦。你有没有这样的时候?你现在有一点闲暇时间,你想要去学习,但你不知道该学什么,在短暂的考虑后,你选择了打游戏或者刷短视频或者娱乐活动。而且这样事情时常会发生在你的身上。
文章浏览阅读4.5w次,点赞21次,收藏163次。NLP(自然语言处理)到底是做什么?NLP 的全称是 Natural Language Processing,翻译成中文称作:自然语言处理。它是计算机和人工智能的一个重要领域。顾名思义,该..._nlp
文章浏览阅读1.2k次,点赞3次,收藏8次。最近需要用到github上一个包,克隆到本地windows环境下运行有问题,想在Ubuntu下尝试,虽然用虚拟机比较方便,但是考虑到这样的话实验室的电脑和自己的电脑都需要分别配虚拟机比较麻烦,就想直接在阿里云买个服务器跑个ubuntu远程桌面。https://common-buy.aliyun.com/?commodityCode=swas®ionId=cn-hangzhou选择的乌班图版本为16.04,开通完成后预装的Ubuntu是不带桌面只有命令行的,先安装xrdp:1、安_阿里云 ubuntu 安装远程桌面
文章浏览阅读10w+次,点赞108次,收藏408次。如需转载请注明出处:https://blog.csdn.net/qq_29350001/article/details/76680646最近在搞 PM2.5 采集,需要用到 MQTT 传输协议。协议部分看了几天的,讲的七七八八。本身在 intel 上有 写好的MQTT 的源码,现在的工作其实也就是移植到单片机上或者DM368板卡上。不过,对于之前没有接触过的我来说,还是从头开始,搭建服务器及测..._mqtt服务器搭建
文章浏览阅读1.2k次。webgl平台的文件对话框,unity只提供了编辑器模式下的,导入dll打包后会报错。思路:c#可以调用js的代码通过DOM生成一个input file按钮,调用click可以弹出。但是问题:游览器安全设置,无法模拟点击file按钮,在console里面可以跳出对话框,但是代码调用没有办法执行,必须点击按钮。unity用UGUI拼的Button,点击触发事件可以加,不想点击两次..._unity webgl js 弹出文件对话框
文章浏览阅读929次。Are virtual interfaces supported on Quagga v0.98.3 (on Debian GNU/Linux 2.6.16)?_ndndbrdxx
文章浏览阅读5.9k次,点赞4次,收藏48次。一:目的1. 用C++实现链队列的基本操作2. 用C++实现循环队列的基本操作二:链队列的实现1. 定义数据结构和类,书写在Queue.h中# include using namespace std;typedef int ElemType;typedef struct QNode{ ElemType data; QNode *n_c++链对列和循环队列基本操作bool dequeue(queue& q, qelemtype& e)
文章浏览阅读526次。软件测试中使用coverage统计python代码的覆盖率1.确保电脑里面安装了python环境,安装了pip。2.使用管理员身份打开cmd,键入pip install coverage,等待安装完成。3.在命令提示符里面使用coverage执行python代码。备注:执行代码前先cd到.py执行文件路径下,然后输入:coverage run quadratic01.py,点击Ente..._pycharm coverage 教程
文章浏览阅读1.1k次。参考博客:小程序的textarea完美解决所有的坑包括穿透、样式等<view class="items"> <text class="style-text">备注:</text> <textarea v-show="showTextArea" name="remark" class="content" style="height: 50rpx;padding: 5px 10px;font-size: 30upx;" placeholder="请输入备注..."_uni-textarea 样式穿透
文章浏览阅读324次。Solution首先 manacher 求出以 i 为中心的回文串长度 FiFiF_i容易发现 Ans=∑i=LRmin(R−i+1,i−L+1,Fi)Ans=∑i=LRmin(R−i+1,i−L+1,Fi)Ans=\sum_{i=L}^{R} min(R-i+1,i-L+1,F_i)为减少限制 拆分每个询问为(L,m)(m+1,R)(L,m)(m+1,R)(L,m)(m+1,R) ..._5036: [jsoi2014]回文串