Re: MaxOffsetNumber for Table AMs

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Jeff Davis <pgsql(at)j-davis(dot)com>
Cc: Peter Geoghegan <pg(at)bowt(dot)ie>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: MaxOffsetNumber for Table AMs
Date: 2021-05-04 16:56:37
Message-ID: CA+TgmobeUX_xw_4o1obbdLUDbDDGUijrsHke8HnUWs6HL8T7yg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, May 3, 2021 at 2:13 PM Jeff Davis <pgsql(at)j-davis(dot)com> wrote:
> That's not clear to me at all, and is the whole reason I began this
> thread.
>
> a. You say "smaller than MaxOffsetNumber", but that's a little weird.
> If an offset can't be MaxOffsetNumber, it's not really the maximum, is
> it?

I wasn't trying to be that precise. I see that OffsetNumberIsValid()
returns true if the offset is <= MaxOffsetNumber, so therefore I agree
that using exactly MaxOffsetNumber ought to work.

> b. If you actually meant "less than or equal to MaxOffsetNumber",
> that will fail with the GIN posting list issue raised in my first
> email. Do you agree that's a bug?

Given the above, yes.

> c. Why can't we go all the way up to MovedPartitionsOffsetNumber - 1?
> Right now, MaxOffsetNumber is poorly named, because it actually
> represents the a number slightly higher than the maximum number of
> items that can fit on a page. That essentially wastes 5 bits of address
> space for no obvious reason.

Because of stuff like this:

[rhaas EDBAS]$ git grep -F '[MaxOffsetNumber'
src/backend/access/gist/gistvacuum.c: OffsetNumber
todelete[MaxOffsetNumber];
src/backend/access/gist/gistvacuum.c: OffsetNumber
todelete[MaxOffsetNumber];
src/backend/access/gist/gistvacuum.c: BlockNumber
leafs_to_delete[MaxOffsetNumber];
src/backend/access/hash/hash.c: OffsetNumber deletable[MaxOffsetNumber];
src/backend/access/hash/hashinsert.c: OffsetNumber
deletable[MaxOffsetNumber];
src/backend/access/hash/hashovfl.c: OffsetNumber
deletable[MaxOffsetNumber];

Maybe changing those places to use dynamic allocation wouldn't hurt
anything in terms of performance, but I'm not sure. Making them 32
times larger categorically does not seem like a good idea.

There might be other dependencies on this value in other parts of the
code; I'm not sure.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2021-05-04 17:13:37 Re: Incorrect snapshots while promoting hot standby node when 2PC is used
Previous Message Justin Pryzby 2021-05-04 16:43:47 Re: Extending amcheck to check toast size and compression