Re: serialization errors

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
Cc: Greg Copeland <greg(at)CopelandConsulting(dot)Net>, Ryan VanderBijl <rvbijl-pgsql(at)vanderbijlfamily(dot)com>, PostgresSQL General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Re: serialization errors
Date: 2003-01-31 15:55:07
Message-ID: 8933.1044028507@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> writes:
> I think his argument is that since the two transactions (as a whole)
> should be serialized, he shouldn't get the same max(node_order) in both
> since in either order of serialization of the two transactions you can't
> get 5 from both selects (one should return 6).

Right, that's a fair point.

> The problem with this is that it's probably pretty unimplementable,

Yeah. This shows the difference between what we do and true
serialization. An academic would tell you that true serialization
requires predicate locking --- that is, as soon as transaction T1 has
done a "SELECT ... WHERE foo", then concurrent transaction T2 must wait
for T1 if it tries to insert *or remove* a row that would satisfy foo.

Unfortunately this cure is much worse than the disease. Aside from the
sheer overhead of enforcing it, it leads to deadlocks. For example,

T1 T2

SELECT max(node_order)+1...
SELECT max(node_order)+1...
INSERT ...

at this point T1's insert blocks, because it would violate the predicate
of T2's already-performed SELECT.

INSERT...

And now T2 is blocked by T1 --- deadlock. So now you know why predicate
locking is an academic solution and not used by real databases :-(

But probably the shortest answer to Ryan is that what the database sees
is a unique-index violation, so that's what it reports. Deducing that
this condition can only have arisen because of concurrent behavior would
take an impractical amount of knowledge, both of what your own
transaction is doing and of what other transactions are doing.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Arjen van der Meijden 2003-01-31 16:13:49 Re: Weird query plans for my queries,
Previous Message Tom Lane 2003-01-31 15:30:32 Re: Weird query plans for my queries, causing terrible performance.