Custom reloptions in TableAM
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:
v1-0001-tableam-relopts.patchapplication/octet-stream; name=v1-0001-tableam-relopts.patchDownload+53-11
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/
Hi!
Thank you very much, I'll check it out.
--
Regards,
Nikita Malakhov
Postgres Professional
The Russian Postgres Company
https://postgrespro.ru/
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