Question about the anti-three paradigm of a data table?

Source: Internet
Author: User
A simple problem: the document classification table: article_type (id, name, pid, num) indicates the number of articles under the classification. I have always been like this, when an article is added or deleted, the num field of the corresponding category is updated. But now I think this seems unnecessary,... a simple question:

Document category table:

article_type(id, name, pid, num)

ThisnumIs the number of articles under this category. I have always been like this. When I add or delete an article, the corresponding category will be updated.numField.

But now I think this seems unnecessary, because the number of articles under each document category can be easily indicated by the document table.count()So I think thisnumIt is redundant and must be updated during document editing.article_typeTablenumI feel a little bored.

I want to cancel this field, but it is very tangled, because, in this caseselectThe number of statements increases.numThis is all you need.count()How many categories are required?count()A few times, does it seem unreasonable to have performance problems compared with the previous ones?

It seems that such a simple problem has already involved program coupling, table paradigm design, and other considerations.

Tangle, hope you can give me some advice. Thank you!

Reply content:

A simple question:

Document category table:

article_type(id, name, pid, num)

ThisnumIs the number of articles under this category. I have always been like this. When I add or delete an article, the corresponding category will be updated.numField.

But now I think this seems unnecessary, because the number of articles under each document category can be easily indicated by the document table.count()So I think thisnumIt is redundant and must be updated during document editing.article_typeTablenumI feel a little bored.

I want to cancel this field, but it is very tangled, because, in this caseselectThe number of statements increases.numThis is all you need.count()How many categories are required?count()A few times, does it seem unreasonable to have performance problems compared with the previous ones?

It seems that such a simple problem has already involved program coupling, table paradigm design, and other considerations.

Tangle, hope you can give me some advice. Thank you!

First, design follows the paradigm, which indicates that the original intention of designing a table is to have as few redundancy as possible.
Second, the appropriate anti-paradigm, the strict paradigm under a specific situation leads to a severe performance impact, which means you need to weigh between "Elegant Design" and "pragmatism, depending on your business, never pursue perfection.

Now let's take a look at your scenario. Your article_type increases num redundancy. In this scenario, what can be better is that when there are many articles, however, your requirements for the real-time performance of each type of num are not that high, but you need to frequently display it in multiple places. You may even update it every day or every hour, at this time, num redundancy is reasonable, and you may reduce the process that requires select count. however, if you only need this num in a few places, count can fully meet your requirements and will not cause visible performance loss. In this case, you should follow the paradigm.

Considering giving up using num can bring you a lot of trouble. How much code does it need to be restructured? Will it affect the core logic? Can I cache num?

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.