Re: how to read table options during smgropen()

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: "Dima Rybakov (Tlt)" <dim001r(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: how to read table options during smgropen()
Date: 2024-02-23 09:40:35
Message-ID: afb2c34e-b2d4-471e-9bb8-445ff1d22aea@iki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 22/02/2024 20:22, Dima Rybakov (Tlt) wrote:
> Dear pgsql hackers,
>
> I am developing custom storage for pgsql tables. I am using md*
> functions and smgrsw[] structure to switch between different magnetic
> disk access methods.
>
> I want to add some custom options while table created
> psql# create table t(...) with (my_option='value');
>
> And thus I want to set "reln->smgr_which" conditionally during
> smgropen(). If myoption='value' i would use another smgr_which
>
> I am really stuck at this point.
>
> smgr.c:
> SMgrRelation
> smgropen(RelFileNode rnode, BackendId backend){
> ...
>   if ( HasOption(rnode, "my_option","value")){ //<< how to implement
> this check ?
>     reln->smgr_which = 1; //new access method
>   }else{
>     reln->smgr_which = 0; //old access method
>   }
> ...
> }
>
>
> The question is --- can I read table options while the table is
> identified by  "RelFileNode rnode" ??

The short answer is that you can not. smgropen() operates at a lower
level, and doesn't have access to the catalogs. smgropen() can be called
by different backends connected to different databases, and even WAL
recovery when the system is not in a consistent state yet.

Take a look at the table AM interface. It sounds like it might be a
better fit for what you're doing.

There have been a few threads here on pgsql-hackers on making the smgr
interface extensible, see
https://www.postgresql.org/message-id/CAEze2WgMySu2suO_TLvFyGY3URa4mAx22WeoEicnK%3DPCNWEMrA%40mail.gmail.com
one recent patch. That thread concluded that it's difficult to make it a
per-tablespace option, let alone per-table.

--
Heikki Linnakangas
Neon (https://neon.tech)

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhijie Hou (Fujitsu) 2024-02-23 09:46:00 RE: Synchronizing slots from primary to standby
Previous Message Heikki Linnakangas 2024-02-23 09:31:12 Re: make BuiltinTrancheNames less ugly