> On 4/25/2013 11:55 AM, Matus UHLAR - fantomas wrote:
>
> ...
> 
> My understanding is that it's better (with respect to performance and
> atomicity) to attempt the INSERT and have it fail than to check if the
> ID/token combination already exists and UPDATE it if it does.

Please note that it would make more sense at first to attempt an UPDATE and
then, that failing, an INSERT, since the updating token is probably already
present in the average bayes db.

But this approach would be problematic in a multi-instance and/or multi-host
SA deployment: two SA instances willing to update the scores for the very
same token at (almost) the same time may both fail the UPDATE then,
attempting INSERT, one of the two would fail that too...

Besides, the safe and slower approach (a SELECT and then an UPDATE or an
INSERT) would suffer of the very same problem.

Also, note that the UPDATE is kind of:

        SET nspam (nham) = npam (nham) + 1

which works far better in a non-transacted environment: a lot of troubles
may arise otherwise (like all-1 SA instances waiting for a single one to
release a transactional lock, or even worse using serializable
transactions).

Giampaolo

Reply via email to