当前位置:网站首页>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
边栏推荐
- Understand the new economic model of platofarm and its ecological progress
- Example of pop-up task progress bar function based on pyqt5
- Introduction to data analysis 𞓜 kaggle Titanic mission (III) - > explore data analysis
- Image processing - Noise notes
- Notes on concurrent programming of vegetables (IX) asynchronous IO to realize concurrent crawler acceleration
- Read LSTM (long short term memory)
- 最强日期正则表达式
- What are the system events of Jerry's [chapter]
- Shell script interaction free
- Reading integrity monitoring techniques for vision navigation systems - 3 background
猜你喜欢

高价买来的课程,公开了!phper资料分享

101. Symmetric Tree

/Can etc / shadow be cracked?

Jinglianwen technology - professional data annotation company and intelligent data annotation platform

Idea - indexing or scanning files to index every time you start

Charles function introduction and use tutorial

Shell script interaction free

Reading integrity monitoring techniques for vision navigation systems - 5 Results

【leetcode】199. Right view of binary tree

How to quickly download vscode
随机推荐
LeetCode-608. Tree node
997. Square of ordered array (array)
最强日期正则表达式
RESTful和SOAP的区别
【leetcode】107. Sequence traversal of binary tree II
19. Delete the penultimate node of the linked list (linked list)
209、长度最小的子数组(数组)
CentOS/Linux安装MySQL
主流手机分辨率与尺寸
Understand the new economic model of platofarm and its ecological progress
Embedded related surface (I)
IDEA——》每次启动都会Indexing或 scanning files to index
Configuration of LNMP
Learning note 5 - gradient explosion and gradient disappearance (k-fold cross verification)
209. Subarray with the smallest length (array)
使用zerotier让异地设备组局域网
454. Sum of four numbers (hash table)
Charles function introduction and use tutorial
Arm debugging (1): two methods to redirect printf to serial port in keil
Jerry sometimes finds that the memory has been tampered with, but there is no exception. How should he find it? [chapter]