Custom reloptions in TableAM

Nikita Malakhov <hukutoc@gmail.com>

From: Nikita Malakhov <hukutoc@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-06-20T20:09:01Z
Lists: pgsql-hackers

Attachments

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/