Re: Reading deleted records - PageHeader v3

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jonathan Bond-Caron" <jbondc(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Reading deleted records - PageHeader v3
Date: 2010-02-06 06:20:53
Message-ID: 14890.1265437253@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Jonathan Bond-Caron" <jbondc(at)gmail(dot)com> writes:
> I think part of my problem is I haven't really understood what 'Then make
> sure you have the right alignment' means.

> My approach currently is:

> After reading HeapTupleHeaderData (23 bytes), I advance another 4 bytes
> (hoff) and try to read a 32 bit integer (first attribute).

No. First you start at the tuple beginning plus the number of bytes
indicated by hoff (which should be at least 24). The first field
will always be right there, because this position is always maximally
aligned. For subsequent fields you have to advance to a multiple of
the alignment requirement of the datatype. For example, assume the
table's first column is of type bool (1 byte) and the second column
is of type integer. The bool will be at offset hoff, but the integer
will be at offset hoff + 4 ... it can't immediately follow the bool,
at offset hoff + 1, because that position isn't correctly aligned.
It has to start at the next offset that's a multiple of 4.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2010-02-06 06:21:29 Re: [CFReview] Red-Black Tree
Previous Message Greg Smith 2010-02-06 05:03:30 Re: [HACKERS] Re: Faster CREATE DATABASE by delaying fsync (was 8.4.1 ubuntu karmic slow createdb)