pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vadim Mikheev <vadim@krs.ru>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Oleg Bartunov <oleg@sai.msu.su>
Cc: pgsql-hackers@postgreSQL.org
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] inserts/updates problem under stressing !
Date: Mon, 26 Jul 1999 10:43:00 +0800
Message-ID: <379BCB34.B3A0EF3E@krs.ru> (raw)
References: <1696.932833746@sss.pgh.pa.us>

(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



view thread (11+ messages)  latest in thread

Message-ID: <379BCB34.B3A0EF3E@krs.ru>
Permalink:  ../379BCB34.B3A0EF3E@krs.ru/
Also on:    postgresql.org/message-id/379BCB34.B3A0EF3E@krs.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: vadim@krs.ru, tgl@sss.pgh.pa.us, oleg@sai.msu.su, pgsql-hackers@postgreSQL.org
  Subject: Re: [SQL] inserts/updates problem under stressing !
  In-Reply-To: <379BCB34.B3A0EF3E@krs.ru>
  References: <1696.932833746@sss.pgh.pa.us> <379BCB34.B3A0EF3E@krs.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox