sql - how to add a reaction to a post (social website)
问题描述
I'm rather new to sql and i was wondering what would be the best way to add reactions to posts as we can see for exemple in twitter where you answer a tweet, so far i've worked out these 2 ways but i don't know which one should be done:
- add a reaction table which will have for pk id_react and id_post, with id_react in auto_increment with each reaction made by any user on any page of the site
- create a new table reaction for every post that is created
this one would "erase" the problem of the DB size although it would mean to moderate as many reaction tables as there is of id_post; so here I am not knowing which solution would be theoretically the best for this kind of problem
解决方案
A new table per post does not look great to me. You may end up with millions of tables, most of them empty, for no performance benefit, and a lot of maintenance burden.
I would go with just one more table that stores all the reactions, and has post_id
as a foreign key.
But your intuition about having more separate tables is not wrong: a similar feature is known as partitioning, and is available in all major relational databases.
推荐阅读
- php - 托管后访问laravel 8中的图像不起作用
- android - 如何在 Kotlin 中等待并继续执行
- npm - 无法启动 Angular 项目
- curl - AppleScript 不会超越顶层
- python - 如何将开发中的数据库中的数据带到生产中?使用 django、postgres 和 heroku?
- performance - 如何提高具有多个孩子的 Wrap Widget 的性能?
- javascript - 反应生命周期方法中的横切概念
- flutter - 迁移到空安全:参数类型“对象?” 不能分配给参数类型“列表”
' - python - 用于循环打印数组的行数,然后根据数组的长度重复数据,如何在 Python 中只打印 1 行数据?
- javascript - 使用大于 ( > ) 比较 date.toUTCString() 总是返回 false,无论其他日期是否更早或更早