Is it always useful to store an array as a field value or store array values ​​as records?

In my application, I have β€œarticles” (similar to posts / tweets / articles) that are tagged with descriptive predefined tags: i.e. "difficult", "simple", "red", "blue", "business", etc.

These available tags are stored in a table, called "tags", which contain all the available tags.

In each article, you can mark several tags that can be edited through the user interface.

It may be tempting to simply associate tags for each object with a strict array of identifiers for each tag and save it along with the article entry in my "articles" table:

id | title | author | tags
---+-------+--------+-------------
1  | title | TG     | "[1,4,7,12]"

although I'm sure this is a bad idea for a number of reasons, is there a reasonable reason to do the above?

+4
source share
3 answers

I think you should read about Database Normalization and decide for yourself. In short, there are a number of problems with your proposal, but you can decide whether you can live with them.

The most obvious are:

  • What should I do if an additional tag is added to line (1)? You must first parse, check if it is already present, and then update the line to tags.append(newTag).
  • Worse still deletes a tag? Search tags are present, re-create tags.
  • What if the tag should change the name - some kind of moderation process, maybe?
  • , dfferent , - - .
  • , ? , .
  • : , . ? .

, . . , , , IMO, , , - , . , ( , ).

+6

, , , ( "" ),

, , , , / , , .

, , , , .

+2

, . .

. , , , API Azure , SQL. ( API Azure , , .)

SQL ( ) , , , , .

- , , , . NoSQL, .

. CRUD . , , SQL, , .

As soon as your user base gets to large volumes, and you need to support several simultaneous requests without affecting the performance of the update, you will find that external indexing is a huge investment in your time to save your time and resources later.

0
source

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


All Articles