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

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

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

数据库版本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

看个人简介有交流群(付费)

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

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

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

打赏作者

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

抵扣说明:

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

余额充值