Re: Is a syscache tuple more like an on-disk tuple or a freshly made one? - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Is a syscache tuple more like an on-disk tuple or a freshly made one?
Date
Msg-id 20160415220301.GA469536@alvherre.pgsql
Whole thread Raw
In response to Is a syscache tuple more like an on-disk tuple or a freshly made one?  (Chapman Flack <chap@anastigmatix.net>)
Responses Re: Is a syscache tuple more like an on-disk tuple or a freshly made one?  (Chapman Flack <chap@anastigmatix.net>)
List pgsql-hackers
Chapman Flack wrote:

> I am tempted to apply HeapTupleGetDatum to a tuple retrieved from
> the syscache (as I already have code for processing a tuple presented
> as a Datum).
> 
> But I see a comment on HeapTupleHeaderGetDatum: "This must *not* get
> applied to an on-disk tuple; the tuple should be freshly made by
> heap_form_tuple or some wrapper ..."

I suppose you could create a copy of the tuple (SysCacheSearchCopy) and
use that for HeapTupleGetDatum.  The problem with the syscache tuple is
that it can go away as soon as you do the ReleaseSysCache -- it lives in
shared_buffers memory, so when it's released the buffer might get
evicted.

heap_form_tuple returns a newly palloc'd tuple, which is what you want.

> ... and here I confess I'm unsure whether a tuple retrieved from
> the syscache is more like an on-disk one, or a freshly-made one,
> for purposes of the warning in that comment.

A "syscache tuple" is definitely an on-disk tuple.

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



pgsql-hackers by date:

Previous
From: Chapman Flack
Date:
Subject: Is a syscache tuple more like an on-disk tuple or a freshly made one?
Next
From: Tom Lane
Date:
Subject: Re: Is a syscache tuple more like an on-disk tuple or a freshly made one?