Re: How to get the 'ctid' from a record type?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Eric Ridge <eebbrr(at)gmail(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: How to get the 'ctid' from a record type?
Date: 2017-03-11 01:29:28
Message-ID: 9545.1489195768@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Eric Ridge <eebbrr(at)gmail(dot)com> writes:
> What I'm seeing is that the ctid returned from this function isn't always
> correct:

> # select ctid, foo(table) from table limit 10;
> ctid | foo
> -------+-----------
> (0,1) | (19195,1) -- not correct!
> (0,2) | (0,2)
> (0,3) | (0,3)

I suspect the tuple at (0,1) has been the subject of a failed update.

Your problem here is that you're mistaking the t_ctid field of a tuple
header for the tuple's address. It is not that; it's really just garbage
normally, and is only useful to link forward to the next version of the
row from an outdated tuple. I think we do initialize it to the tuple's
own address during an INSERT, but either a completed or failed UPDATE
would change it.

I do not think there is any way to get the true address of a heap tuple
out of a composite Datum manufactured from the tuple. Most of the other
system columns can't be gotten from a composite Datum either, because of
the field overlay in HeapTupleHeaderData's union t_choice.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2017-03-11 01:59:48 Re: Indirect assignment code for array slices is dead code?
Previous Message Andres Freund 2017-03-11 00:58:10 Indirect assignment code for array slices is dead code?