佛
每有一个新方案,就要考虑有什么影响
增删改查
可扩展性
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行或者单表超过2G
how
选择分片键
查询慢
慢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
数据库版本