Re: how to read table options during smgropen()

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема Re: how to read table options during smgropen()
Дата
Msg-id afb2c34e-b2d4-471e-9bb8-445ff1d22aea@iki.fi
обсуждение исходный текст
Ответ на how to read table options during smgropen()  ("Dima Rybakov (Tlt)" <dim001r@gmail.com>)
Список 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)




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Heikki Linnakangas
Дата:
Сообщение: Re: make BuiltinTrancheNames less ugly
Следующее
От: "Zhijie Hou (Fujitsu)"
Дата:
Сообщение: RE: Synchronizing slots from primary to standby