Chapter 14. サーバプログラム開発用インタフェース

Table of Contents
インタフェース関数
サポート関数のインタフェース
メモリ管理
データ変更の可視性

The Server Programming Interface (SPI) gives users the ability to run SQL queries inside user-defined C functions. The available Procedural Languages (PL) give an alternate means to access these capabilities.

Server Programming InterfaceSPI )はユーザ定義の C 関 数から SQL 問い合わせを実行する機能をユーザに提 供します。使用可能な手続き言語( PL )はこの機能 にアクセスする別の方法を提供しています。

In fact, SPI is just a set of native interface functions to simplify access to the Parser, Planner, Optimizer and Executor. SPI also does some memory management.

実際には、SPI は、パーサ、プランナ、オブティマイ ザ、エグゼキュータへのアクセスを単純化にするための一連の組み込み関数 群に過ぎません。また、SPI はメモリ管理も行ないます。

To avoid misunderstanding we'll use function to mean SPI interface functions and procedure for user-defined C-functions using SPI.

誤解を防ぐために、これ以降、関数SPI インタフェース関数の意味で、 プロシージャSPI を呼び出 すユーザ定義の C 関数の意味で使うことにします。

SPI procedures are always called by some (upper) Executor and the SPI manager uses the Executor to run your queries. Other procedures may be called by the Executor running queries from your procedure.

SPI プロシージャは常に(上位の)エグゼキュータ から呼び出され、SPI マネージャはエグゼキュータ を使用してユーザの問い合わせを実行します。他のプロシージャの場合、 そのプロシージャからの問い合わせを実行しているエグゼキュータから呼 び出されることもあります。

Note, that if during execution of a query from a procedure the transaction is aborted then control will not be returned to your procedure. Rather, all work will be rolled back and the server will wait for the next command from the client. This will be changed in future versions.

プロシージャの中で問い合わせを実行している最中にトランザクションが 中断すると、そのプロシージャに制御が戻らないということに注意して下 さい。 それどころか、全ての実行結果がロールバックされてサーバはクラ イアントからの次のコマンドを待つ状態になります。この仕様は将来の版で 変更される予定です。

Other restrictions are the inability to execute BEGIN, END and ABORT (transaction control statements) and cursor operations. This will also be changed in the future.

この他の制約として、(トランザクションの制御文である)BEGIN、END、 ABORT とカーソル操作ができないという点があります。これも将来変更され る予定です。

If successful, SPI functions return a non-negative result (either via a returned integer value or in SPI_result global variable, as described below). On error, a negative or NULL result will be returned.

SPI 関数は、成功すると非負の結果を(後述のように、 整数値または SPI_result 大域変数のどちらかを通して)返します。失敗した 場合は、負または NULL という結果を返します。

インタフェース関数