Re: WAL, xl_heap_insert and tuple oid mystry

From: jagan <jaganrvce(at)yahoo(dot)com>
To: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: WAL, xl_heap_insert and tuple oid mystry
Date: 2011-04-14 20:30:17
Message-ID: 343821.32394.qm@web32103.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

>
> > Where is the OID of tuple stored in a WAL record of a
> tuple? If not with xl_heap_header, where is it stored? Is it
> stored at all?
>
> It's stored in the "tuple data" portion.

I see it now. I was having alignment issues, which I resolved. Thanks for your help. I am still not sure if I understand how attributes are packed in to a buffer. In particular, according to the inline comments in code, this is how a xl_heap_insert stores data:

Oid + [padding bits] + [data]

Now, to unpack the data, we would have to know what type of data is stored, which is obtained from pg_type. Different types require either a "no (char) align", "short align", "int aligned" or "double align". I went over the varattrib code and I am also able to unpack varchar, text and other variable length types.

The code I wrote works fine but runs into alignment issues with some of the records. So, I am still missing something even though I have spent weeks reading postgres code.

I notice the following:

1. Oid starts at MAXALIGNed, which is fine.

2. The subsequent attribute starts right away. There never seems to be padding even if the subsequent tuple needs to be double aligned. Hence, I skip aligning the first attribute by default, which is bizarre but works.

3. When unpacking goes out of alignment, I print the buffer see if this is because they are externally stored. That is not the case as I can see text fields are actually stored in the buffer.

4. The alignment goes out of whack even for entries with no varattrib for certain tuples.

In general, what is the best way to unpack buffers containing tuples? I came across "heap_form_tuple" but not sure if that is most optimal way to go about. Is there some documentation on how tuples are internally stored?

Thanks in advance for any pointers.
Jagan

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2011-04-14 20:30:25 Re: Single client performance on trivial SELECTs
Previous Message Greg Smith 2011-04-14 20:22:26 Re: Single client performance on trivial SELECTs