Storing actively updated fields in the database

I have a database with one of the tables storing articles. For each article I need to save the number of views. Now I want to save this value in the database and update it every time someone visits the page with this article, and now I am considering two alternatives:

  • Create a column viewsin the table articlesand update it.
  • Create a separate table view_countwith the FK pointer to the article and the numbers for this article.

My question is: is there a difference between the two approaches in terms of speed and why? Are there any better alternatives?

I am using a PostgreSQL database.

Note that I do not consider different ways of accumulating these values ​​in separate files, outside the database and subsequent insertion, because i) we do not receive so many hits ii) the function is in the minor ones and if this requires such a hassle, we would prefer to refuse it and use some other service for this.

+3
source share
3 answers

The differences in the two sentences are pretty subtle, this is how I see them:

Same table

  • saving it in one table will allow you to get it at a lower cost
  • updates can be blocking parts of the database so that other requests in the queue need to be slowed down.
  • - ( - , - , , 2 - n x - / , , / - , , , )

  • , - ( , , , -)
  • , I/O
  • - , , , -, .

:
, : , , . - .

+4

articles , , - .

/ , . , .

, .

0

, . , - , , script .

0

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


All Articles