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?