Re: How to check whether the row was modified by this transaction before? - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: How to check whether the row was modified by this transaction before?
Date
Msg-id 20121206180851.GB4299@alvh.no-ip.org
Whole thread Raw
In response to Re: How to check whether the row was modified by this transaction before?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: How to check whether the row was modified by this transaction before?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: How to check whether the row was modified by this transaction before?  (Andres Freund <andres@2ndquadrant.com>)
List pgsql-hackers
Tom Lane wrote:
> Vlad Arkhipov <arhipov@dc.baikal.ru> writes:
> > In a BEFORE UPDATE trigger I need to know whether the row was previously
> > modified by this transaction. Is it safe to use xmin and txid_current()
> > for this purpose (xmin is 32-bit txid type but txid_current() returns
> > 64-bit bigint).
>
> >    IF OLD.xmin = txid_current() THEN
>
> Comparing to txid_current() mod 2^32 would probably work,

I think we should be setting the initial epoch to something other than
zero.  That way, some quick testing would have revealed this problem
immediately.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Setting visibility map in VACUUM's second phase
Next
From: Simon Riggs
Date:
Subject: Re: Commits 8de72b and 5457a1 (COPY FREEZE)