Re: [SQL] inserts/updates problem under stressing !

From: Vadim Mikheev <vadim(at)krs(dot)ru>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Oleg Bartunov <oleg(at)sai(dot)msu(dot)su>, pgsql-hackers(at)postgreSQL(dot)org, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] inserts/updates problem under stressing !
Date: 1999-07-26 02:43:00
Message-ID: 379BCB34.B3A0EF3E@krs.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-sql

(Sorry for incomplete prev message).

Tom Lane wrote:
>
> I wonder whether this doesn't have a problem with concurrent access:
>
> 1. Transaction A does 'Select count into cnt', gets (say) 200.
> 2. Transaction B does 'Select count into cnt', gets 200.
> 3. Transaction A writes 201 into hits record.
> 4. Transaction B writes 201 into hits record.
>
> and variants thereof. (Even if A has already written 201, I don't think
> B will see it until A has committed...)

You're right, Tom.

> I am not too clear on MVCC yet, but I think you need "SELECT FOR UPDATE"
> or possibly an explicit lock on the hits table in order to avoid this
> problem. Vadim, any comments?

SELECT FOR UPDATE will not help: if there was no record for
particular key then nothing will be locked and two records with
the same key will be inserted.

Oleg, use LOCK IN SHARE ROW EXCLUSIVE MODE.

Vadim

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message D'Arcy J.M. Cain 1999-07-26 02:43:20 Re: [HACKERS] Problem with dlopen and PostgreSQL - load of file failed
Previous Message D'Arcy J.M. Cain 1999-07-26 02:39:47 Re: [HACKERS] Problem with dlopen and PostgreSQL - load of file failed

Browse pgsql-sql by date

  From Date Subject
Next Message Vadim Mikheev 1999-07-26 02:50:28 Re: [HACKERS] Re: [SQL] inserts/updates problem understressing !
Previous Message Vadim Mikheev 1999-07-26 02:39:14 Re: [SQL] inserts/updates problem under stressing !