Denormalize for Simplicity: the idea of ​​Ungood?

After reading this question , I found out that denormalization is not a solution for simplicity. How about this case?

I have news articles in which there is a list of article sites to be published. The latter can be expressed in a normalized way, either by the table or by the many-to-many principle (in my opinion, through the cross-table). But a simple solution is to simply insert a bunch of logical objects for article sites that will be published-publish (publish_to_site_1, publish_to_site_2, etc.). Assuming sites:

  • small number
  • will not change over time
  • have no fields except the name

Is this a terrible idea? Many-to-many relationships seem a little cumbersome, but I've done this before in such cases (and it seemed cumbersome).

Note: I do this in Rails, where it doesn’t hurt so much. Metaprogramming, on the other hand, does things like trivial

(1..5).each { |site| do_something(article["publish_to_site_#{site}".to_symbol]) } 
+4
source share
4 answers

If these conditions are really met, then no, this is not a terrible idea.

In fact, this is not even denormalization: denormalization usually means that you save some information redundantly for the sake of performance. In your example, since sites do not have fields on their own, you do not save things redundantly. You simply lose the opportunity to leave additional fields for sites in the future (without violating the normalization or redesigning of your database).

So this is normal (normalized):

 article show_on_stackoverflow show_on_my_blog ----------------------------------------------------------------------- Denormalize for Simplicity YES NO More simplicity YES YES ... 

But this is not normal (redundancy):

 article show_on_stackoverflow stackoverflow_mainpage_url show_on_my_blog my_blog_mainpage_url ------------------------------------------------------------------------------------------------------------------------------ Denormalize for Simplicity YES http://stackoverflow.com NO http://my.blog.url More simplicity YES http://stackoverflow.com YES http://my.blog.url ... 
+3
source

Assumption two is unrealistic.

Therefore, in full accordance with "If these conditions are really met, then no, this is not a terrible idea.": Yes, this is a terrible idea.

+2
source

If you think of boolean "article-sites-will-be-published-as" as attributes of the primary database, such as "isGreen", "hasHair", "isBipedal", then one table is normalized to the point that it would be vicious to have an external key to the Green{<true>, <false>} table Green{<true>, <false>} .

Obviously, if your 3 conditions do not remain true, the next guy will have a non-trivial job, but “as simple as possible but not easier” has its usefulness.

0
source

Personally, I think I'm not denormalizing. In my opinion, the only n: n relation is not so cumbersome to combine if you are familiar with SQL. What can be cumbersome is the use of a denormalized structure for different queries. For example, are you sure that you will never need a list of all the sites published in an article ...?

Not that I ever called your approach terrible, but I usually prefer normalized data, happily making another connection :)

Cheers Matthias

0
source

Source: https://habr.com/ru/post/1310375/


All Articles