Re: ctid access is slow - Mailing list pgsql-general

From Jim C. Nasby
Subject Re: ctid access is slow
Date
Msg-id 20050824043631.GI96732@pervasive.com
Whole thread Raw
In response to Re: ctid access is slow  (Jeff Eckermann <jeff_eckermann@yahoo.com>)
Responses Re: ctid access is slow  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Re: ctid access is slow  (Ron Mayer <rm_pg@cheapcomplexdevices.com>)
List pgsql-general
On Tue, Aug 23, 2005 at 06:42:33PM -0700, Jeff Eckermann wrote:
> > I believe that's not necessarily true. If you select
> > a tuple and it's
> > ctid and it's updated more than once with a vacuum
> > in-between I believe
> > it could end up back in the same position, which
> > would mean the same
> > ctid.
>
> True.  But the probability of that happening would
> generally be low enough not to bother the designers of
> most applications.

Designers that don't care about their data, maybe. Here's the use case
that was implied:

Application selects a bunch of data to present to the user to be edited
User edits data even though it's not locked in the database
Application gets data and checks to see if it's changed. If it not,
*BLAM*, new changes are put into the database

Now, if that check for changed data fails with a false negative, you
just nuked data.

A better solution is to use a combination of a timestamp and a sequence.
Why both? Because it's possible for the clock to be set back (though
this is something best avoided), and a sequence will eventually roll
over. It's impossible to have a collision in this scenario unless you
roll the clock way back AND reset the sequence (assuming you're using an
integer sequence).
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software        http://pervasive.com        512-569-9461

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: plpgsql: returning multiple named columns from function
Next
From: wolverine my
Date:
Subject: Re: ERROR: database is being accessed by other users