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.
source
share