Re: Recommendation about the implementation of a voting process

From: amul sul <sul_amul(at)yahoo(dot)co(dot)in>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>, "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Recommendation about the implementation of a voting process
Date: 2016-08-15 16:34:49
Message-ID: 1950492957.13137293.1471278889852.JavaMail.yahoo@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message JORGE MALDONADO 2016-09-01 22:36:05 TImestamp with milliseconds or ten thousandths of a second
Previous Message JORGE MALDONADO 2016-08-15 16:18:34 Recommendation about the implementation of a voting process