pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Stark <gsstark@mit.edu>
To: pgsql-hackers@postgresql.org
Subject: Re: start of transaction (was: Re: [PERFORM] Help with count(*))
Date: 17 Nov 2003 01:11:53 -0500
Message-ID: <87he13a5hy.fsf@stark.dyndns.tv> (raw)
In-Reply-To: <873ccnc49e.fsf@mailbox.samurai.com>
References: <200311141251.38786.mallah@trade-india.com>
	<m3ad6zkpgj.fsf@wolfe.cbbrowne.com>
	<1068831807.2540.44.camel@fuji.krosing.net>
	<3FB52FA7.8060508@lashell.net>
	<4987.1068842326@sss.pgh.pa.us>
	<87isllbcys.fsf@mailbox.samurai.com>
	<1068983887.17671.10.camel@fuji.krosing.net>
	<873ccnc49e.fsf@mailbox.samurai.com>


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




view thread (13+ messages)  latest in thread

Message-ID: <87he13a5hy.fsf@stark.dyndns.tv>
Permalink:  ../87he13a5hy.fsf@stark.dyndns.tv/
Also on:    postgresql.org/message-id/87he13a5hy.fsf@stark.dyndns.tv

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: gsstark@mit.edu, pgsql-hackers@postgresql.org
  Subject: Re: start of transaction (was: Re: [PERFORM] Help with count(*))
  In-Reply-To: <87he13a5hy.fsf@stark.dyndns.tv>

* 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