Postgresql 中文操作指南

32.4. Extensibility #

32.4.1. Inlining Support for Extensions #

PostgreSQL 的 JIT 实现可以内联类型为 Cinternal 的函数主体,以及基于此类函数的运算符。要对扩展中的函数执行此操作,需要提供这些函数的定义。当使用 PGXS 对已使用 LLVM JIT 支持编译的服务器构建扩展时,将自动构建和安装相关文件。

PostgreSQL’s JIT implementation can inline the bodies of functions of types C and internal, as well as operators based on such functions. To do so for functions in extensions, the definitions of those functions need to be made available. When using PGXS to build an extension against a server that has been compiled with LLVM JIT support, the relevant files will be built and installed automatically.

相关文件必须安装到 $pkglibdir/bitcode/$extension/,并将其摘要安装到 $pkglibdir/bitcode/$extension.index.bc,其中 $pkglibdir 是由 pg_config --pkglibdir 返回的目录,而 $extension 是扩展的共享库的基本名称。

The relevant files have to be installed into $pkglibdir/bitcode/$extension/ and a summary of them into $pkglibdir/bitcode/$extension.index.bc, where $pkglibdir is the directory returned by pg_config --pkglibdir and $extension is the base name of the extension’s shared library.

Note

对于内置于 PostgreSQL 自身的函数,将字节码安装到 $pkglibdir/bitcode/postgres

For functions built into PostgreSQL itself, the bitcode is installed into $pkglibdir/bitcode/postgres.

32.4.2. Pluggable JIT Providers #

PostgreSQL 提供了基于 LLVM 的 JIT 实现。与 JIT 提供程序的接口是可以插入的,并且可以更改提供程序而不重新编译(不过目前构建过程仅针对 LLVM 提供内联支持数据)。通过设置 jit_provider 来选择活动提供程序。

PostgreSQL provides a JIT implementation based on LLVM. The interface to the JIT provider is pluggable and the provider can be changed without recompiling (although currently, the build process only provides inlining support data for LLVM). The active provider is chosen via the setting jit_provider.

32.4.2.1. JIT Provider Interface #

可以通过动态加载命名的共享库来加载 JIT 提供程序。使用常规库搜索路径定位库。为了提供所需的 JIT 提供程序回调并指示库实际上是 JIT 提供程序,它需要提供名为 _PG_jit_provider_init 的 C 函数。此函数传递一个结构,需要用单个动作的回调函数指针来填充它:

A JIT provider is loaded by dynamically loading the named shared library. The normal library search path is used to locate the library. To provide the required JIT provider callbacks and to indicate that the library is actually a JIT provider, it needs to provide a C function named _PG_jit_provider_init. This function is passed a struct that needs to be filled with the callback function pointers for individual actions:

struct JitProviderCallbacks
{
    JitProviderResetAfterErrorCB reset_after_error;
    JitProviderReleaseContextCB release_context;
    JitProviderCompileExprCB compile_expr;
};

extern void _PG_jit_provider_init(JitProviderCallbacks *cb);