当前位置:网站首页>Simple thoughts on the design of a microblog database
Simple thoughts on the design of a microblog database
2022-04-23 10:46:00 【Glacier Technology】
In the microblog system , The current user 、 Concern ( That is, fans )、 Followers ( The object of worship ) These three roles are indispensable . The seemingly simple relationship between them , But how will the database tables be designed , But it's hard for me to figure out , In the following solutions , Which one would you choose ? Why choose this ? Is there a better solution ?
Solution 1 :
Table name |
User information sheet |
||||
Field name |
Field code |
Field type |
describe |
||
user name |
User_id |
Varchar(20) |
Primary key |
||
password |
Password |
Varchar(20) |
|||
…… |
…… |
…… |
|||
Table name |
List of followers and followers |
||||
Field name |
Field code |
Field type |
describe |
||
user name |
User_id |
Varchar(20) |
Primary key |
||
Concern |
Funs |
Text |
|
||
Followers |
Wasfuns |
Text |
This is the first design I thought of , here “ Concern ” and “ Followers ” They are stored by splicing some special characters , such as A Users have only followers B、C、D、E, Then the data stored in the follower field of the database will be B;C;D;E( For the time being, the split character is ;).
Based on the above scheme , Let me ask you a question : When this user's “ Concern ” or “ Followers ” In large numbers ( such as 10 Million followers ) What kind of string of characters will it be ? And when we need to query “ Concern ” perhaps “ Followers ” Recent blog information , Will face some time sorting queries with the blog information table , Processing difficulty is a waste of performance .
Solution 2 :
Based on the above problems , Someone offered me an extensible solution , At the same time, it also solves the problem of massive data in a field . Decompose the list of concerns and followers in scheme 1 into two tables , as follows :
Table name |
Followers table |
||
Field name |
Field code |
Field type |
describe |
Number |
Id |
Number |
Primary key |
user name |
User_id |
Varchar(20) |
|
Follower number |
Funs_id |
Varchar(20) |
|
Table name |
List of followers |
||
Field name |
Field code |
Field type |
describe |
Number |
Id |
Number |
Primary key |
user name |
User_id |
Varchar(20) |
|
Number of followers |
Wasfuns_id |
Varchar(20) |
|
I was surprised to see such a design , Just imagine , If I have a user corresponding to 1W Followers , Then the user will have 10000 records in the followers table , Isn't this serious data redundancy ? This doesn't even conform to the database design specification . But it turns out , This design is very good for the expansion of large amount of data , In that case , If the relationship between users is not limited to the relationship between attention and attention , Is it necessary to add a new table ?
Solution three :
Words “ A long time must be divided. , Long period of division ”, Further modification of the above design , So the two tables of scheme 2 are combined into one , as follows :
Table name |
List of followers and followers |
||
Field name |
Field code |
Field type |
describe |
Number |
Id |
Int |
Primary key |
user name |
User_id |
Varchar(20) |
|
Target audience |
Operate_object |
Varchar(20) |
|
state |
Status |
Number |
When the target object is a follower , Marked as 1; When the target object is the follower , Marked as 2; When both sides pay attention to each other , Marked as 3; When the target object is OO, Marked as XX. |
OK, This design not only solves a considerable part of data redundancy , It can also represent a variety of relationships between users , Facilitate the future expansion of the system . But the problem comes out again , Obviously, this design also has doubts about the maintenance of state , Replace multiple tables with one table , The data must have doubled , Is it not in line with the current common saying “ Dismantle the library and the table ” Our strategic approach ( It seems that such a state is generally used for “ Mark men and women ” perhaps “ Have you deleted ” And so on. , It seems that it is rarely used in this kind of occasion ).
In the solution of the above user relationship , It can be simply summed up as one to many , For one more , Many to many relationship , So how to design , Which is better , I hope you can analyze it together !
版权声明
本文为[Glacier Technology]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230922150969.html
边栏推荐
- 142. Circular linked list||
- Restful、SOAP、RPC、SOA、微服务之间的区别
- JVM——》常用命令
- Read integrity monitoring techniques for vision navigation systems
- JVM - common parameters
- CSP certification 202203-2 travel plan (multiple solutions)
- 解决方案架构师的小锦囊 - 架构图的 5 种类型
- SQL Server recursive query of superior and subordinate
- [Niuke challenge 47] C. conditions (BitSet acceleration Floyd)
- 349、两个数组的交集
猜你喜欢
Wonderful review | deepnova x iceberg meetup online "building a real-time data Lake based on iceberg"
景联文科技—专业数据标注公司和智能数据标注平台
中职网络安全2022国赛之CVE-2019-0708漏洞利用
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
JUC concurrent programming 09 -- source code analysis of condition implementation
JVM——》常用命令
Notes on concurrent programming of vegetables (V) thread safety and lock solution
How can swagger2 custom parameter annotations not be displayed
【leetcode】107. Sequence traversal of binary tree II
Reading integrity monitoring techniques for vision navigation systems - 3 background
随机推荐
[provincial election joint examination 2022 d2t1] card (state compression DP, FWT convolution)
Windows installs redis and sets the redis service to start automatically
SQLServer 查询数据库死锁
349. Intersection of two arrays
Go language practice mode - functional options pattern
A diary of dishes | 238 Product of arrays other than itself
解决方案架构师的小锦囊 - 架构图的 5 种类型
Jerry's more accurate determination of abnormal address [chapter]
454、四数之和(哈希表)
JVM - common parameters
142. Circular linked list||
59. Spiral matrix (array)
Ansible cloud computing automation command line compact version
19. Delete the penultimate node of the linked list (linked list)
Diary of dishes | Blue Bridge Cup - hexadecimal to octal (hand torn version) with hexadecimal conversion notes
net start mysql MySQL 服务正在启动 . MySQL 服务无法启动。 服务没有报告任何错误。
206. Reverse linked list (linked list)
Question bank and answers of Shanghai safety officer C certificate examination in 2022
Reading integrity monitoring techniques for vision navigation systems - 3 background
How does the swagger2 interface import postman