Re: start of transaction (was: Re: [PERFORM] Help with count(*)) - Mailing list pgsql-hackers

From Greg Stark
Subject Re: start of transaction (was: Re: [PERFORM] Help with count(*))
Date
Msg-id 87he13a5hy.fsf@stark.dyndns.tv
Whole thread Raw
In response to Re: start of transaction (was: Re: [PERFORM] Help with count(*))  (Neil Conway <neilc@samurai.com>)
Responses Re: start of transaction (was: Re: [PERFORM] Help with  (Stephan Szabo <sszabo@megazone.bigpanda.com>)
List pgsql-hackers
Neil Conway <neilc@samurai.com> writes:

> What does BEGIN actually do now, from a user's perspective? 

I think you're thinking about this all wrong. BEGIN doesn't "do" anything.
It's not a procedural statement, it's a declaration. It declares that the
block of statements form a transaction so reads should be consistent and
failures should be handled in a particular way to preserve data integrity.

Given that declaration and the guarantees it requires of the database it's
then up to the database to figure out what constraints that imposes on what
the database can do and still meet the guarantees the BEGIN declaration
requires. The more clever the database is about minimizing those restrictions
the better as it means the database can run more efficiently.

For what it's worth, this is how Oracle handles things too. On the
command-line issuing a BEGIN following a COMMIT is just noise; you're _always_
in a transaction. A COMMIT ends the previous the transaction and implicitly
starts the next transaction. But the snapshot isn't frozen until you first
read from a table.

I'm not sure what other databases do, but I think this is why clients behave
like this. They think of BEGIN as a declaration and therefore initiating a
COMMIT;BEGIN; at the end of every request is perfectly logical, and works fine
in at least Oracle, and probably other databases.

-- 
greg



pgsql-hackers by date:

Previous
From: "Marc G. Fournier"
Date:
Subject: Release now live ...
Next
From: Stephan Szabo
Date:
Subject: Re: start of transaction (was: Re: [PERFORM] Help with