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)



Reply via email to