Custom reloptions in TableAM

Started by Nikita Malakhovover 1 year ago4 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

needs rebasesuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t51774
psql -h localhost -U postgres

Built from patchset v1 (message #1), August 24, 2026 at 03:07 AM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t51774_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t51774_1 && git checkout t51774_1

Patchset v1 (message #1) is on t51774_1

Jump to latest
#1Nikita Malakhov
hukutoc@gmail.com

Hi hackers!

While developing an alternative Table AM I've stumbled
upon the impossibility to set custom reloptions to the table
created by Table AM, like it could be done for Index AM.

I haven't found any comments on this and implemented
a mechanism of setting custom reloptions for a relation
created with Table AM, if needed. These options are stored
in Relcache and are accessed through the rd_options field.

The main scenario for custom reloptions is something like:
CREATE TABLE t (...) USING myTableAM WITH (custom_opt1=..., ...);

and myTableAM should implement custom options function,
like Index AM, and assign in to an amoptions field:

bytea *myamoptions(Datum reloptions, bool validate)
{
myAMOptions *rdopts;
static const relopt_parse_elt tab[] = {
{"custom_opt1", RELOPT_TYPE_INT, offsetof(myAMOptions, customOpt1)},
...
};

/* Parse the user-given reloptions */
rdopts = (myAMOptions *) build_reloptions(reloptions, validate,
my_relopt_kind,
sizeof(myAMOptions),
tab,
lengthof(tab));

return (bytea *) rdopts;
}

Hope you'll find it useful.
Advice and objections are welcome.
POC patch in attachment.

--
Regards,
Nikita Malakhov
Postgres Professional
The Russian Postgres Company
https://postgrespro.ru/

Attachments:

t51774_1
v1-0001-tableam-relopts.patchapplication/octet-stream; name=v1-0001-tableam-relopts.patchDownload+53-11
#2Srinath Reddy Sadipiralla
srinath2133@gmail.com
In reply to: Nikita Malakhov (#1)
Re: Custom reloptions in TableAM

On Sat, Jun 21, 2025 at 1:39 AM Nikita Malakhov <hukutoc@gmail.com> wrote:

Hi hackers!

While developing an alternative Table AM I've stumbled
upon the impossibility to set custom reloptions to the table
created by Table AM, like it could be done for Index AM.

I haven't found any comments on this and implemented
a mechanism of setting custom reloptions for a relation
created with Table AM, if needed. These options are stored
in Relcache and are accessed through the rd_options field.

The main scenario for custom reloptions is something like:
CREATE TABLE t (...) USING myTableAM WITH (custom_opt1=..., ...);

I think there are some similar efforts going on ,you can check in this
thread [0]/messages/by-id/20250302085641.hmjom5ru3w554t2n@poseidon.home.virt.

[0]: /messages/by-id/20250302085641.hmjom5ru3w554t2n@poseidon.home.virt
/messages/by-id/20250302085641.hmjom5ru3w554t2n@poseidon.home.virt

--
Thanks,
Srinath Reddy Sadipiralla
EDB: https://www.enterprisedb.com/

#3Nikita Malakhov
hukutoc@gmail.com
In reply to: Srinath Reddy Sadipiralla (#2)
Re: Custom reloptions in TableAM

Hi!

Thank you very much, I'll check it out.

--
Regards,
Nikita Malakhov
Postgres Professional
The Russian Postgres Company
https://postgrespro.ru/

#4Michael Paquier
michael@paquier.xyz
In reply to: Nikita Malakhov (#1)
Re: Custom reloptions in TableAM

On Fri, Jun 20, 2025 at 11:09:01PM +0300, Nikita Malakhov wrote:

I haven't found any comments on this and implemented
a mechanism of setting custom reloptions for a relation
created with Table AM, if needed. These options are stored
in Relcache and are accessed through the rd_options field.

Your patch touches the backend, but there is no real way to check
whether it is correct. I would suggest revisiting an idea of dummy
table AM module added to src/test/modules/. This has been proposed
one year ago if I recall correctly on pgsql-hackers, and I did argue
that there was little value in having it as long as it does not
provide specific test coverage. The additions you are suggesting to
would be a reason enough for having such a module, IMO, validating the
correctness of what you are proposing.
--
Michael