Ask for a database design problem!
I'm assuming an application. such as the Forum
We send a post we build a post table topic
Then support the visitors to prepare a reply form reply
My question is:
Suppose we want to know the number of replies for each post. How should we go about statistics better?
1. Prepare a field reply number in the Post topic table (reply_count) We direct Select this field to get back the plural
2. Associate with a table, and then go to select count (Reply) to get the number of replies
That's what I was thinking:
Method 1: It is possible to follow normal business logic. And in the efficiency of the dominant. But there may be inconsistencies in the data. I mean, the database doesn't repel me. The record is 10 replies, but actually the reply reply table is 13 records.
Method 2: The data structure feels more rigorous, but the search efficiency is sacrificed.
Don't know if there are any good practices, or which of these two methods is more feasible?
Reply to discussion (solution)
In Method 1, when the insert and delete operations for reply are successful, the Topic.reply_count is required to update
In fact, you have to read: "To know the number of replies per post," the frequency of use.
1, if only in the background one months after the statistics, it is obvious that the second kind can be used.
2, if it is necessary to display the view of the post, it must be the first kind.
Suggest specific problem specific analysis, reply_count, field to establish
Suggest specific problem specific analysis, reply_count, field to establish
The actual use of the redundancy design to see the situation.
Database I started to see, but the problem seems to be very simple, that is, two tables to update, to do the correlation.
I sent a resume in go, only to 2000, incredibly no one to talk to me, a phone is not, is my resume written bad, help to see it
Name: Fly WAN Play chatter
Website: http://bj.ganji.com/jianli/564717047x.htm?_rtm=1
Don't lose efficiency in order to save a field.
Look at the design of the Discuz table. The number of cached replies is required.
Database I started to see, but the problem seems to be very simple, that is, two tables to update, to do the correlation.
I sent a resume in go, only to 2000, incredibly no one to talk to me, a phone is not, is my resume written bad, help to see it
Name: Fly WAN Play chatter
Website: http://bj.ganji.com/jianli/564717047x.htm?_rtm=1
Do not try to lower your salary to "beg" a job, this is a self-distrust, irresponsible attitude.
Friend, I read your resume.
What do employers call you without a real name?
There is no direct contact number, you can add in the notes.
Without a more positive self-description, how does the other person get to know you?
And, brother, you are 27 years old. Only 23 24 of friends who have just graduated from college can really blame their college for being bad. You've been out of society for a while, haven't you? Continue complaining about your college, and your youth will only be used to complain.
You say you want to have someone to bring, then why don't others choose just graduated from college-spirited fresh students, and to choose you? Where is your advantage?
I hope you're well prepared. Good luck!