Re: Nested transactions and tuple header info

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>, Manfred Koizar <mkoi-pg(at)aon(dot)at>, David Blasby <dblasby(at)refractions(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Nested transactions and tuple header info
Date: 2004-06-02 14:44:07
Message-ID: 200406021444.i52Ei7v10370@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > Tom Lane wrote:
> >> This is exactly the same argument as not being able to overwrite cmin.
>
> > Basically the phantom xid's are a shorthand for saying the tuple was
> > created by xid1 and deleted by xid2, both part of the same main
> > transaction.
>
> > A cursor looking at the rows has to recognize the xid is a phantom (via
> > pg_subtrans) and look up the creation xid.
>
> You still don't see the point. Consider
>
> BEGIN;
> DECLARE CURSOR c1 FOR SELECT * FROM a ...;
> INSERT INTO a VALUES(...); -- call this row x
> DECLARE CURSOR c2 FOR SELECT * FROM a ...;
> BEGIN;
> DELETE FROM a WHERE ...; -- assume this deletes row x
> ROLLBACK;
> FETCH FROM c1; -- must NOT see row x
> FETCH FROM c2; -- must see row x
>
> AFAICS your proposal does not support this. The two cursors' snapshots
> will differ only in the recorded current-cid for the outer transaction.
> If the subtrans has overwritten xmin/cmin, there is no way to make that
> decision correctly.

I do not overwrite cmin or cmax. If xid=1 creates a row:

xmin=1
cmin=1

and xid=2 goes to expire it, we get:

xmin=3 (phantom for xmin=1, xmax=2)
cmin=1
cmax=1

and we set a phantom bit on the tuple. When we see it later and need to
know the xmin or xmax, we look it up in local memory. (Maybe we don't
even need a hash, just a List because I can't imagine more than a few of
these phantoms being used.) Other backends see the tuple with a xmin as
"in progress" so they don't need to look any further.

Then, on commit, we decide if a tuple created by xid=1 and expired by
xid=2 should appear created or not, and mark the phantom commit status
accordingly.

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-06-02 14:46:02 Re: Converting postgresql.conf parameters to kilobytes
Previous Message Tom Lane 2004-06-02 14:37:31 Re: ACLs versus ALTER OWNER