当前位置: 首页 > news >正文

数据库-数据库设计-社交关系

每有一个新方案,就要考虑有什么影响增删改查可扩展性

MySQL

根据ER图设计表

create table follow(`id` bigint unsigned not null auto_increment comment '主键',`gmt_create` datetime null default current_timestamp,`gmt_modified` null default current_timestamp on update current_timestamp,`from_user_id` bigint unsigned not null comment '',`to_user_id` bigint unsigned not null comment '',primary key(`id`)
)

根据涉及的查询场景设置索引 

--查询关注列表
--同一个连接同一个数据库
select to_user_id,nick_name,avator,introduction
from follow join user on follow.to_user_id = user.id
where from_user_id=?--查询关注列表
--同一个连接不同数据库
select to_user_id,nick_name,avator,introduction
from a.follow join b.user on follow.to_user_id = user.id
where from_user_id=?--查询关注列表
--表字段冗余
select to_user_id,nick_name,avator,introduction
from follow
where from_user_id=?--查询粉丝列表
select from_user id
from follow
where to_user_id=?index idx_from_to(`from_user_id`,`to_user_id`)

 海量数据

分库分表when阿里规范单表超过500W行或者单表超过2Ghow选择分片键

查询慢

慢sql
读写分离

参考资料

规范

阿里巴巴 Java 开发手册之MySQL 规约(三)-------我的经验-阿里云开发者社区 (aliyun.com)

bigint 

mysql bigint 设置长度_mob64ca12dd8bce的技术博客_51CTO博客

其他

mybatis_plus各类用法,version(乐观锁)、deleted(逻辑删除)、gmt_create(创建时间)、gmt_modified(修改时间)-CSDN博客

表必备三字段:id, gmt_create, gmt_modified-CSDN博客

bug

数据库版本

http://www.lryc.cn/news/306490.html

相关文章:

  • YOLO算法改进Backbone系列之:EfficientViT
  • JANGOW: 1.0.1
  • Elasticsearch 创建index库 timeout
  • 2024最新可用免费天气预报API接口
  • 【AIGC】开源声音克隆GPT-SoVITS
  • YOLOv9图像标注和格式转换
  • 车载系统相关
  • AWS对文本进行语言识别
  • HTTP 与HTTPS笔记
  • 【k8s配置与存储--配置管理】
  • 如何在C++中嵌入SQL语句?解释一下什么是ODBC、JDBC以及它们在C++数据库编程中的作用。
  • 【Simulink系列】——动态系统仿真 之 混合系统
  • PHP中的飞碟运算符、取反运算符、对比非ASCII字符串、对比浮点数操作
  • unity-unity2d基础操作笔记(二)0.5.0
  • Feign远程调用(学习笔记)
  • pytorch建模的三种方式
  • GO-ICP的使用(一)
  • FPS游戏漫谈System.GC.Collect()强制进行垃圾回收
  • 第3集《灵峰宗论导读》
  • java面试设计模式篇
  • 桥接模式:解耦抽象与实现,实现灵活多变的扩展结构
  • HUAWEI Programming Contest 2024(AtCoder Beginner Contest 342)
  • Heap sorting
  • 开源模型应用落地-qwen2模型小试-入门篇(六)
  • c#程序,oracle使用Devart驱动解决第第三方库是us7ascii,数据乱码的问题
  • 代码随想录算法训练营第四一天 | 背包问题
  • AIDL的工作原理与使用示例 跨进程通信 远程方法调用RPC
  • K8S部署Java项目 pod报错 logs日志内容:no main manifest attribute, in app.jar
  • SQL实现模糊查询的四种方法总结
  • 爬虫基本库的使用(urllib库的详细解析)