Re: Using HeapTuple.t_len to verify size of tuple - Mailing list pgsql-hackers

From Vignesh Raghunathan
Subject Re: Using HeapTuple.t_len to verify size of tuple
Date
Msg-id CAD_AmVgr5Y7uGh9q8iQOr5D+X19nELeNG0++0sMd8sg9N=v5tQ@mail.gmail.com
Whole thread Raw
In response to Re: Using HeapTuple.t_len to verify size of tuple  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Using HeapTuple.t_len to verify size of tuple  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers


On Tue, Aug 25, 2015 at 2:56 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Vignesh Raghunathan <vignesh.pgsql@gmail.com> writes:
> Can the t_len field in HeapTuple structure be used to verify the length of
> the tuple?

> That is, if I calculate the length from the contents of the tuple using
> data from pg_attribute for fixed length fields and the data from the header
> for varlena fields, should it always match the value stored in t_len?

If t_len were *less* than that, it would be a bug.  But I think it's
fairly common for t_len to be rounded up to the next maxalign boundary.

                        regards, tom lane

I have modified heap_deform_tuple code to check whether the 'off' variable matches the tuple's t_len field for a project. In the code, off is not updated in case of null fields. However, when I run it for pg_class table, the code throws an error saying that the value of off does not match t_len. It turns out that for all tuples even if the attribute attacl is null, t_len field is set to be the sizeof(FormData_pg_class). Is this normal behavior?

pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Function accepting array of complex type
Next
From: Tom Lane
Date:
Subject: Re: Using HeapTuple.t_len to verify size of tuple