バージョンごとのドキュメント一覧

61.3. カスタムスキャンの実行 #

<title>Executing Custom Scans</title>

When a <structfield>CustomScan</structfield> is executed, its execution state is represented by a <structfield>CustomScanState</structfield>, which is declared as follows: CustomScanが実行されるとき、その実行状態はCustomScanStateで表現されます。 これは次のように宣言されています。

typedef struct CustomScanState
{
    ScanState ss;
    uint32    flags;
    const CustomExecMethods *methods;
} CustomScanState;

<structfield>ss</structfield> is initialized as for any other scan state, except that if the scan is for a join rather than a base relation, <literal>ss.ss_currentRelation</literal> is left NULL. <structfield>flags</structfield> is a bit mask with the same meaning as in <structname>CustomPath</structname> and <structname>CustomScan</structname>. <structfield>methods</structfield> must point to a (usually statically allocated) object implementing the required custom scan state methods, which are further detailed below. Typically, a <structname>CustomScanState</structname>, which need not support <function>copyObject</function>, will actually be a larger structure embedding the above as its first member. ssは他のすべてのスキャン状態と同じく初期化されますが、スキャンがベースリレーションではなく結合を対象にしているときは例外で、ss.ss_currentRelationはNULLのままになります。 flagsCustomPathおよびCustomScanと同じ意味のビットマスクです。 methodsは必要なカスタムスキャン状態のメソッドを実装するオブジェクト(通常は静的に割り当てられる)を指していなければなりません。 これについては以下で詳しく説明します。 CustomScanStatecopyObjectをサポートしなくてもよく、典型的には上記を先頭のメンバーとして組み込んだより大きな構造体になっています。

61.3.1. カスタムスキャン実行のコールバック #

<title>Custom Scan Execution Callbacks</title>

void (*BeginCustomScan) (CustomScanState *node,
                         EState *estate,
                         int eflags);

Complete initialization of the supplied <structname>CustomScanState</structname>. Standard fields have been initialized by <function>ExecInitCustomScan</function>, but any private fields should be initialized here. 提供されたCustomScanStateの初期化を完了します。 標準的なフィールドはExecInitCustomScanで初期化が済んでいますが、プライベートフィールドはここで初期化されます。

TupleTableSlot *(*ExecCustomScan) (CustomScanState *node);

Fetch the next scan tuple. If any tuples remain, it should fill <literal>ps_ResultTupleSlot</literal> with the next tuple in the current scan direction, and then return the tuple slot. If not, <literal>NULL</literal> or an empty slot should be returned. 次のスキャンタプルをフェッチします。 タプルが残っている場合は、現在のスキャン方向で次にあるタプルをps_ResultTupleSlotに入れます。 タプルが残っていないときは、NULLまたは空のスロットが戻されます。

void (*EndCustomScan) (CustomScanState *node);

Clean up any private data associated with the <literal>CustomScanState</literal>. This method is required, but it does not need to do anything if there is no associated data or it will be cleaned up automatically. CustomScanStateに関連付けられたプライベートデータを整理します。 このメソッドは必須ですが、関連付けられたデータがない場合、あるいはそれが自動的に整理される場合は、このメソッドは何もする必要はありません。

void (*ReScanCustomScan) (CustomScanState *node);

Rewind the current scan to the beginning and prepare to rescan the relation. 現在のスキャンを先頭まで巻き戻し、リレーションの再スキャンの準備をします。

void (*MarkPosCustomScan) (CustomScanState *node);

Save the current scan position so that it can subsequently be restored by the <function>RestrPosCustomScan</function> callback. This callback is optional, and need only be supplied if the <literal>CUSTOMPATH_SUPPORT_MARK_RESTORE</literal> flag is set. 現在のスキャン位置を保存し、後でRestrPosCustomScanコールバックでリストアできるようにします。 このコールバックは必須ではなく、CUSTOMPATH_SUPPORT_MARK_RESTOREフラグがセットされている場合にのみ、提供する必要があります。

void (*RestrPosCustomScan) (CustomScanState *node);

Restore the previous scan position as saved by the <function>MarkPosCustomScan</function> callback. This callback is optional, and need only be supplied if the <literal>CUSTOMPATH_SUPPORT_MARK_RESTORE</literal> flag is set. MarkPosCustomScanコールバックで保存された以前のスキャン位置をリストアします。 このコールバックは必須ではなく、CUSTOMPATH_SUPPORT_MARK_RESTOREフラグがセットされている場合にのみ、提供する必要があります。

Size (*EstimateDSMCustomScan) (CustomScanState *node,
                               ParallelContext *pcxt);

Estimate the amount of dynamic shared memory that will be required for parallel operation. This may be higher than the amount that will actually be used, but it must not be lower. The return value is in bytes. This callback is optional, and need only be supplied if this custom scan provider supports parallel execution. 並列操作に要求される動的共有メモリの使用量を予測します。 使用を予測される量よりも多い量の結果が返しても良いですが、少なく返してはいけません。 返り値の単位はバイトとなります。 このコールバックは必須ではなく、カスタムスキャンプロバイダが並列実行をサポートする場合にのみ提供される必要があります。

void (*InitializeDSMCustomScan) (CustomScanState *node,
                                 ParallelContext *pcxt,
                                 void *coordinate);

Initialize the dynamic shared memory that will be required for parallel operation. <literal>coordinate</literal> points to a shared memory area of size equal to the return value of <function>EstimateDSMCustomScan</function>. This callback is optional, and need only be supplied if this custom scan provider supports parallel execution. 並列操作に要求される動的共有メモリを初期化します。 coordinateは、EstimateDSMCustomScanの返り値と大きさが一致する動的共有メモリ領域を指します。 このコールバックは必須ではなく、カスタムスキャンプロバイダが並列実行をサポートする場合にのみ提供される必要があります。

void (*ReInitializeDSMCustomScan) (CustomScanState *node,
                                   ParallelContext *pcxt,
                                   void *coordinate);

Re-initialize the dynamic shared memory required for parallel operation when the custom-scan plan node is about to be re-scanned. This callback is optional, and need only be supplied if this custom scan provider supports parallel execution. Recommended practice is that this callback reset only shared state, while the <function>ReScanCustomScan</function> callback resets only local state. Currently, this callback will be called before <function>ReScanCustomScan</function>, but it's best not to rely on that ordering. カスタムスキャンプランノードが再スキャンしようとするときに、並列操作に必要な動的共有メモリを再初期化します。 このコールバックは必須ではなく、カスタムスキャンプロバイダが並列実行をサポートする場合にのみ提供される必要があります。 推奨する使い方としては、ReScanCustomScanコールバックはローカル状態だけをリセットし、このコールバックは共有状態だけをリセットするようにします。 今のところ、このコールバックはReScanCustomScanの前に呼ばれますが、この順序関係には依存しない方が良いです。

void (*InitializeWorkerCustomScan) (CustomScanState *node,
                                    shm_toc *toc,
                                    void *coordinate);

Initialize a parallel worker's local state based on the shared state set up by the leader during <function>InitializeDSMCustomScan</function>. This callback is optional, and need only be supplied if this custom scan provider supports parallel execution. InitializeDSMCustomScanによりリーダーにて設定された共有状態を元に、並列ワーカーのローカル状態を初期化します。 このコールバックは必須ではなく、カスタムスキャンプロバイダが並列実行をサポートする場合にのみ提供される必要があります。

void (*ShutdownCustomScan) (CustomScanState *node);

Release resources when it is anticipated the node will not be executed to completion. This is not called in all cases; sometimes, <literal>EndCustomScan</literal> may be called without this function having been called first. Since the DSM segment used by parallel query is destroyed just after this callback is invoked, custom scan providers that wish to take some action before the DSM segment goes away should implement this method. ノードが実行を完了しないと思われるときに、リソースを解放します。 これはすべての場合に呼ばれるわけではありません。 ときには、この関数がまず呼ばれることなしに、EndCustomScanが呼ばれるかもしれません。 パラレルクエリで使用されるDSMセグメントは、このコールバックが呼ばれた直後に削除されるので、DSMセグメントが削除される前に何らかのアクションを起こしたいカスタムスキャンプロバイダは、このメソッドを実装すべきです。

void (*ExplainCustomScan) (CustomScanState *node,
                           List *ancestors,
                           ExplainState *es);

Output additional information for <command>EXPLAIN</command> of a custom-scan plan node. This callback is optional. Common data stored in the <structname>ScanState</structname>, such as the target list and scan relation, will be shown even without this callback, but the callback allows the display of additional, private state. カスタムスキャンの計画ノードのEXPLAINについて追加情報を出力します。 このコールバックは必須ではありません。 対象のリストやスキャンのリレーションなどScanStateに格納される共通データは、このコールバックがなくても表示されますが、このコールバックにより、追加のプライベートな状態が表示できるようになります。