unserializable transaction?

From: s post <sbmpost(at)science(dot)uva(dot)nl>
To: pgsql-general(at)postgresql(dot)org
Subject: unserializable transaction?
Date: 2004-08-16 12:15:35
Message-ID: Pine.GSO.4.58.0408161303240.13455@sremote.science.uva.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Recently I posted "notes on SERIALIZABLE transactions". In these notes I
state that one should use SELECT FOR UPDATE on all accessed data items to
execute SERIALIZABLE transactions. I now seem to have found a schedule
that cannot be serialized in this way. The schedule is like this:

BEGIN BEGIN
SELECT A FOR UPDATE SELECT B FOR UPDATE
if(record A not present) if(record B not present)
INSERT B <- does not block INSERT A <- does not block
COMMIT COMMIT

The select statements operate on a table that initially does not contain
records A and B. The if condition is part of the code that executes the
transaction. This should be no problem since PostgreSQL cannot assume
anything about the internal operation a transaction.

The problem of the above schedule is that both records A and B are
inserted, whereas any serial execution of both transactions would result
in just one record to be inserted (either A or B). Both transactions do
not see each others inserts because phantom reads are prevented by
accessing the database snapshot that was obtained at the moment of the
first select. This does not mean however that a transaction can safely
ignore the effect of another transaction inserting a record. This seems to
be the cause of the problem because the first transaction is allowed to
INSERT record B, while the search criteria of the SELECT in the second
transaction would have included it. So I wonder, Is the above schedule
indeed unserializable? If so, then I suppose this is a bug?

s.post, mail: wortelsapje AT hotmail.com

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vinay Jain 2004-08-16 12:24:15 could not find block containing chunk 0x8483530
Previous Message Frank van Vugt 2004-08-16 12:07:45 Does a 'stable' deferred trigger execution order exist? Is housekeeping for deferred trigger fire events done in one of the system catalogues?