Facilitating page type detection - Mailing list pgsql-odbc

From Michael Paquier
Subject Facilitating page type detection
Date
Msg-id CAB7nPqSu01Bg_4RSSHh9RTPHhxm1O9=BOyEa9qY4tZtGUbDH5g@mail.gmail.com
Whole thread Raw
Responses Re: Facilitating page type detection  (Michael Paquier <michael.paquier@gmail.com>)
List pgsql-odbc
Hi all,

As raised by Horiguchi-san when discussing the WAL replay patch here,
it is now a little bit difficult to identify what is the type of a
given page:
http://www.postgresql.org/message-id/20140702.173242.27816044.horiguchi.kyotaro@lab.ntt.co.jp

It is of course doable, but it is not that straight-forward:
- Relation page: special area size of 0
- gist page: special area size of MAXALIGN(sizeof(GISTPageOpaqueData))
and check if last 2 bytes match GIST_PAGE_ID
- btree page: special area size of MAXALIGN(sizeof(BTPageOpaqueData))
and check if last 2 bytes match MAX_BT_CYCLE_ID
- spgist page: special area size of
MAXALIGN(sizeof(SpGistPageOpaqueData)) and check if last 2 bytes match
SPGIST_PAGE_ID
- sequence page: special area size of MAXALIGN(sizeof(sequence_magic))
and then check if SEQ_MAGIC is set (4 first bytes of the special area)
- gin page: Special area size of MAXALIGN(sizeof(GinPageOpaqueData)),
and no magic identifier of the other types found.

The identification is uniform for most of the pages: check the last
two bytes and be done luckily thanks to their default sizes (gist,
btree have a special area size of 16 bytes after alignment. Sequence,
spgist and gin have a special area of 8 bytes). By looking at the
comments of gin_private.h, it is written that we can use the size of
the special area to identify that it is a gin page. But that's not
really cool, especially if we add in the future new page types that
have similar characteristics like same special area size, without a
magic identifier.

For relations, I guess that using the special area size is enough, but
I think that we could do better for sequences and gin indexes, by for
example adding an identifier at the end of the page...
In order to do that, the cleanest solution would be to add a dedicated
identifier area at the end of the page for non-relation pages, but
this induces a on-disk format change. Something usually rejected
AFAIK.

Regards,
--
Michael


pgsql-odbc by date:

Previous
From: Craig Ringer
Date:
Subject: [PATCHSET] Docs, old build files changes
Next
From: Michael Paquier
Date:
Subject: Re: Facilitating page type detection