Ask a database design question!

Source: Internet
Author: User
Ask a database design question! Ask a database design question!

Assume an application. For example, forum
We send a post, and we create a post table topic.
Then, it allows visitors to reply and prepare a reply table reply.

My problem is:
Suppose we want to know the number of replies in each post. how should we make statistics better?
1. prepare a field reply count (reply_count) in the topic table of the post. we can select this field to obtain the reply count.
2. join tables, and then select count (reply) to get the number of replies.

I think like this:
Method 1: it is feasible to follow the normal business logic. In addition, it is dominant in efficiency. However, data inconsistency may occur. I mean, the database does not reject 10 replies recorded, but in fact the reply table is 13 records.
Method 2: The data structure is rigorous, but the search efficiency is sacrificed.
I don't know if there are any other good practices, or which of the two methods is more feasible?


Reply to discussion (solution)

In method 1, after the insert and delete operations on reply are successful, you must update topic. reply_count.

In fact, it depends on your usage frequency of "know the number of replies in each post.
1. if you only collect statistics once a month in the background, you can obviously use the second one.
2. if The Post needs to be displayed, it must be the first one.

We recommend that you analyze specific issues, reply_count, and set up fields.

We recommend that you analyze specific issues, reply_count, and set up fields.

Check the actual use of redundancy design.

I started to look at the database, but this problem seems very simple, that is, both tables must be updated and associated.
I sent a resume on the market, and I only needed 2000 yuan. no one answered me, but I didn't have a phone call. is my resume not good? can you help me?
Name: Qingting
URL: http://bj.ganji.com/jianli/564717047x.htm? _ Rtm = 1

Do not lose efficiency to save a field.
Let's look at the design of DISCUZ tables. The number of cached replies is required.

I started to look at the database, but this problem seems very simple, that is, both tables must be updated and associated.
I sent a resume on the market, and I only needed 2000 yuan. no one answered me, but I didn't have a phone call. is my resume not good? can you help me?
Name: Qingting
URL: http://bj.ganji.com/jianli/564717047x.htm? _ Rtm = 1

Don't try to reduce your salary to "begging" a job. this is a kind of unconfident and irresponsible attitude towards yourself.
Friend, I read your resume.
No real name. what do employers call you?
There is no direct contact number. you can add it to the remarks.
There is no positive self-description. how does one get to know you?
And you are 27 years old, brother. Only 23-24 students who have just graduated from college may blame their university for being bad. Have you been out of society for a while? If you continue to complain about your college, your youth will only be used to complain.
If you want someone to take it with you, why don't you choose another freshman who just graduated from college? What are your advantages?
I hope you have prepared well. Good luck!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.