Re: MaxOffsetNumber for Table AMs

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: MaxOffsetNumber for Table AMs
Date: 2021-04-30 16:50:25
Message-ID: df41a0bbab20b2346733b2c36ff0fa7ef8f7e100.camel@j-davis.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 2021-04-30 at 12:04 +0200, Matthias van de Meent wrote:
> Other than that, I believe you've also missed the special offset
> numbers specified in itemptr.h (SpecTokenOffsetNumber and
> MovedPartitionsOffsetNumber). I am not well enough aware of the usage
> of these OffsetNumber values, but those might also be limiting the
> values any tableAM can use for their TIDs.

Yes, thank you. If it is treated specially in a heap tuple, it can't be
a regular TID.

> > It just seems like it's used when scanning heap or index pages for
> > stack-allocated arrays. For a table AM it appears to waste 5 bits.
>
> MaxOffsetNumber is used for postgres' Page layout, of which the
> MaxOffsetNumber is defined as how many item pointers could exist on a
> page, and AFAIK should be used for postgres' Page layout only. No
> thing can or should change that. If any code asserts limitations to
> the ip_posid of table tuples that could also not be tableam tuples,
> then I believe that is probably a mistake in postgres, and that
> should be fixed.

A name that would better fit your definition would be something like
"MaxItemsPerPage".

The name "MaxOffsetNumber" implies that any number past that must be
either invalid or special. But it seems like you are saying that if I
use an offset number of 5000 in my table AM, then that's fine and
should be treated like a normal TID.

> No. The documentation for that function explicitly mentions that
> these item pointers are optimized for storage when using the heap
> tableam, and that that code will be changed once there exist tableAMs
> with different TID / ip_posid constraints (see the comment on lines
> 32 and 33 of that file).

Thank you.

I'm a table AM author, and I'd like to use whatever the real range of
TIDs is. Does that mean it's time to change that code in
ginpostinglist.c now?

> > 1. Keep MaxOffsetNumber as 2048 and fix itemptr_to_uint64().
>
> I believe that this is the right way when there exist tableAMs that
> use those upper 5 bits.

Does that mean we should declare the valid range of offsets to be
between 1 and 0xfffc (inclusive)?

I'm trying to use some mapping now that's somewhat stable so that I
don't have to worry that something will break later, and then require
reindexing all tables with my table AM.

Regards,
Jeff Davis

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2021-04-30 16:51:14 Re: MaxOffsetNumber for Table AMs
Previous Message Robert Haas 2021-04-30 16:39:23 Re: pg_amcheck contrib application