Re: Comparing txid_current() to xmin

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Marko Kreen <markokr(at)gmail(dot)com>
Cc: Mike Lewis <mikelikespie(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Comparing txid_current() to xmin
Date: 2012-11-08 10:21:07
Message-ID: 20121108102107.GA6574@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Nov 08, 2012 at 11:47:37AM +0200, Marko Kreen wrote:
> On Wed, Nov 7, 2012 at 10:21 AM, Andres Freund <andres(at)anarazel(dot)de> wrote:
> > On Tue, Nov 06, 2012 at 02:55:40PM -0800, Mike Lewis wrote:
> >> I am trying to make a trigger that updates a row once and only once per
> >> transaction (even if this trigger gets fired multiple times). The general
> >> idea is that for a user we have a version number. When we modify the
> >> user's data, the version number is incremented then set on the object. We
> >> only need to increment the version number once.
> >>
> >> I am thinking about doing something like:
> >>
> >> update user
> >> set version=version+1
> >> where txid_current() != xmin and user_id = 352395;
> >>
> >>
> >> So I guess my questions are:
> >>
> >> How dirty is this?
> >> Will I run into issues?
> >
> > It won't work in the presenence of subtransactions and is a bit more
> > complicated if you inserted the row in the same transaction.
>
> This can be solved by storing txid_current() into row
> and using that in comparision instead xmin/xmax.

If there is sufficient demand for this it should be easy enough to add a
function that checks for stuff like this using the information already
available in the backends memory.
The hardest part seems to be to find a good name...

It would basically only need to wrap
TransactionIdIsCurrentTransactionId.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2012-11-08 12:50:00 Re: Running out of memory while making a join
Previous Message Carlos Henrique Reimer 2012-11-08 10:20:59 Running out of memory while making a join