In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to load external C language functions in PostgreSQL. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
Quanzl-mac:postgresql.builtin_pool quanzl$ nm lib/plpgsql.so... 0000000000007e10 T _ pg_finfo_plpgsql_call_handler000000000001c888 s _ pg_finfo_plpgsql_call_handler.my_finfo...0000000000007e20 T _ plpgsql_call_handler...
How did this come from? Look directly at the function definition (src/pl/plpgsql/src/pl_handler.c):
... PG_FUNCTION_INFO_V1 (plpgsql_call_handler); Datumplpgsql_call_handler (PG_FUNCTION_ARGS) {...
The functions in all plug-in modules are defined in this form, the return value must be Datum, and the parameters must use the preprocessor PG_FUNCTION_ARGS. Plpgsql_call_handler is the stored procedure processing entry defined in pg_language, which is called differently from the functions that can be used in SQL, so it returns the value directly using return. While general SQL functions such as geo_distance in earthdistance module
... PG_FUNCTION_INFO_V1 (geo_distance); Datumgeo_distance (PG_FUNCTION_ARGS) {... PG_RETURN_FLOAT8 (result);}
SQL definition
CREATE FUNCTION geo_distance (point, point) RETURNS float8LANGUAGE C IMMUTABLE STRICT PARALLEL SAFE AS 'MODULE_PATHNAME'
It must be returned using the PG_RETURN_xxx series preprocessor.
The use of the returned value can be understood by referring to the definition of DirectFunctionCalln (n is a number and the table is the number of parameters). If necessary, we can write another article. To make a simple mention here, we mainly talk about the preprocessor PG_FUNCTION_INFO_V1, which is defined below:
# define PG_FUNCTION_INFO_V1 (funcname)\ extern Datum funcname (PG_FUNCTION_ARGS);\ extern PGDLLEXPORT const Pg_finfo_record * CppConcat (pg_finfo_,funcname) (void);\ const Pg_finfo_record *\ CppConcat (pg_finfo_,funcname) (void)\ {\ static const Pg_finfo_record my_finfo = {1};\ return & my_finfo;\}\ extern int no_such_variable
Take a look at earthdistance.so 's symbol:
0000000000000de0 T _ geo_distance0000000000000dd0 T _ pg_finfo_geo_distance0000000000000fb0 s _ pg_finfo_geo_distance.my_finfo
CppConcat (pg_finfo_,funcname) defines a new function with the prefix pg_finfo_. This is where pg_finfo_geo_distance comes from. It simply returns the structure Pg_finfo_record with a member api_version of 1.
The powerful PG is ready for future expansion.
Check the fetch_finfo_record of the function load section (src/backend/utils/fmgr/fmgr.c):
Const Pg_finfo_record * inforec; infofuncname = psprintf ("pg_finfo_%s", funcname); / * Try to lookup the info function * / infofunc = (PGFInfoFunction) lookup_external_function (filehandle, infofuncname); Inforec = (* infofunc) (); The above is the editor for you to share how to load external C language functions in PostgreSQL, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 269
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.