Replies: 2 comments 10 replies
-
To track some of the sketching: pgedc/postgres#2 |
Beta Was this translation helpful? Give feedback.
-
I think this issue is connected to another one - code versioning. |
Beta Was this translation helpful? Give feedback.
-
Hey @pgedc/members,
PG_FUNCTION_INFO_V1 did quite well for Postgres over the years. However, I keep thinking about cases where it may be insufficient and wanted to run some ideas by you to spark a conversation about it – and what kind of proposal we can make to the core.
Some of the issues
I tried to note the concerns I had most often below.
Unsafe type signatures
The safety of our extensions often relies on being defensive about the types of arguments the functions receive. A Postgres user with sufficient privileges can create a function with any parameters/return signature calling our native function. Unless that function inspects FunctionCallInfo deeply (which comes at a non-zero cost), all bets are off in this case, and a crash or other malfunction can occur.
Load-time symbol resolution
Sometimes, it would be meaningful to select a different function implementation based on some load-time parameters – either based on the host system or on something coming from the database. In the case of more optimal generated code specific to CPUs, function multiversioning can alleviate this (subject to limitations of multiversioning, but for all other cases, there's no straightforward way to pick the right function when we load it.
Symbol concatenation
PG_FUNCTION_INFO_V2
definespg_finfo_FUNCTION_NAME
symbol. Some languages make it much harder to construct names like this. This also makes it much harder to list all exported names (we need to find symbols!)This is less critical than the ones above, but it is still a concern.
Sketch of the proposal
What if we had a single function that would return a "list" of available functions?
(Please ignore arbitrary naming and imperfect data structure – the point to make here is conceptual)
The most difficult part design-wise here would be identifying the types involved. This would imply that the
__pg_function_info
would have to resolve the types by name when using non-standard types. There is a non-zero risk that those types can change OIDs during the lifecycle, but we can address this. [1]With the above, we can solve all three concerns I noted before. It should also work well with the _V1 approach. Postgres would have to try to load
__pg_function_info
first; if not available, fall back toPG_FUNCTION_INFO_V1
.What do you think?
[1] We can perhaps mandate that such types should be declared in a different part of
Pg_FunctionInfoList
(or however it would be called) as exports (or even imports from other extensions?), and then the extension should receive a callback upon such a change. Definitely a more involved change but not infeasible.Beta Was this translation helpful? Give feedback.
All reactions