Re: Recommendation about the implementation of a voting process - Mailing list pgsql-novice

From amul sul
Subject Re: Recommendation about the implementation of a voting process
Date
Msg-id 1950492957.13137293.1471278889852.JavaMail.yahoo@mail.yahoo.com
Whole thread Raw
In response to Recommendation about the implementation of a voting process  (JORGE MALDONADO <jorgemal1960@gmail.com>)
List pgsql-novice
SELECT COUNT... GROUP BY will definitely much slower than the counter logic. And I don't see any issue with counter logic as long as bumping it is an atomic transaction.  

Regards,  
Amul Sul
---------------------------------------------------------------------------------------------------- Sent from a mobile device. Please excuse brevity and tpyos.

On Mon, 15 Aug, 2016 at 9:48 pm, JORGE MALDONADO
<jorgemal1960@gmail.com> wrote:
Hi,

We have an information system for the World Wide Web already running and we need to include a new functionality which should allow users to vote for certain events. This means that users will be able to (for example) click a button to vote. 

This might imply 2 things:
(1) The insertion of a record to a DB table containing data like the event ID the user is voting, the username and timestamp.
(2) Update a counter for the event the user is voting each time a user votes (each event would have its own counter).

Our main concern is how to implement the process of showing the events information in real time. We need to display the events in descending order, showing those with more votes first.

We see at least 2 options to achieve this goal: 
(a) To use a SELECT statement with COUNT and GROUP BY.
(b) To display the counter that I mentioned in point (2) above.

How reliable it is to use a counter? Is there any risk that the PostgreSQL DB does not update such a counter?

I know that using option (a) will provide the correct results without any doubt, but it also means more process for the DB.

What do you recommend?

Respectfully,
Jorge Maldonado

pgsql-novice by date:

Previous
From: JORGE MALDONADO
Date:
Subject: Recommendation about the implementation of a voting process
Next
From: JORGE MALDONADO
Date:
Subject: TImestamp with milliseconds or ten thousandths of a second