Csaba Nagy <nagy@ecircle-ag.com> writes:
>> Can you explain why sorting by ID would make a difference as I don't
>> understand why what you are suggesting should make a difference?
>
> Because I guess id is your primary key, and that would make your
> transactions always update the same rows in the same order.
If the deadlocks occur because different transactions actually try to
update the same rows concurrently, then this is an appropriate solution.
However I wonder if Gavin is getting bitten by foreign key deadlocks.
Is there any foreign key reference from the stats table to other tables?
regards, tom lane