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

71.3. 拡張性 #

<title>Extensibility</title>

The <acronym>BRIN</acronym> interface has a high level of abstraction, requiring the access method implementer only to implement the semantics of the data type being accessed. The <acronym>BRIN</acronym> layer itself takes care of concurrency, logging and searching the index structure. BRINのインタフェースは高度に抽象化されており、アクセスメソッドを実装する人は、アクセスされるデータ型のセマンティクスを実装するだけで良いようになっています。 BRIN層は、同時実行性、ログ、インデックス構造の検索を担当します。

All it takes to get a <acronym>BRIN</acronym> access method working is to implement a few user-defined methods, which define the behavior of summary values stored in the index and the way they interact with scan keys. In short, <acronym>BRIN</acronym> combines extensibility with generality, code reuse, and a clean interface. BRINアクセスメソッドを動作させるために必要なのは、インデックスに格納された要約値の振る舞いと、それらがインデックススキャンする際にどう関係するのかを定義する少数のメソッドを実装することだけです。 つまり、BRINは一般性、コードの再利用性、整理されたインタフェースと拡張性を同時に実現しています。

There are four methods that an operator class for <acronym>BRIN</acronym> must provide: BRIN用の演算子クラスは、4つのメソッドを提供する必要があります。

BrinOpcInfo *opcInfo(Oid type_oid)

Returns internal information about the indexed columns' summary data. The return value must point to a palloc'd <structname>BrinOpcInfo</structname>, which has this definition: インデックスが貼られた列の要約データに関する内部情報を返します。 返却値はpallocされたBrinOpcInfoへのポインタでなければなりません。 BrinOpcInfoは以下の定義を持ちます。

typedef struct BrinOpcInfo
{
    /* Number of columns stored in an index column of this opclass */
    uint16      oi_nstored;

    /* Opaque pointer for the opclass' private use */
    void       *oi_opaque;

    /* Type cache entries of the stored columns */
    TypeCacheEntry *oi_typcache[FLEXIBLE_ARRAY_MEMBER];
} BrinOpcInfo;

<structname>BrinOpcInfo</structname>.<structfield>oi_opaque</structfield> can be used by the operator class routines to pass information between support functions during an index scan. BrinOpcInfo.oi_opaqueは、演算子クラスのルーチンが、インデックススキャン中にサポート関数同士で情報のやり取りをするために使うことができます。

bool consistent(BrinDesc *bdesc, BrinValues *column, ScanKey *keys, int nkeys)

Returns whether all the ScanKey entries are consistent with the given indexed values for a range. The attribute number to use is passed as part of the scan key. Multiple scan keys for the same attribute may be passed at once; the number of entries is determined by the <literal>nkeys</literal> parameter. ある範囲について、すべてのScanKeyエントリが指定されたインデックス値と一致するかどうかを返します。 使用する属性の数はスキャンキーの一部として渡されます。 同じ属性の複数のスキャンキーを一度に渡すこともできます。 エントリの数はnkeysパラメータによって決定されます。

bool consistent(BrinDesc *bdesc, BrinValues *column, ScanKey key)

Returns whether the ScanKey is consistent with the given indexed values for a range. The attribute number to use is passed as part of the scan key. This is an older backward-compatible variant of the consistent function. ScanKeyがある範囲のインデックス値と一致しているかどうかを返します。 属性の数はスキャンキーの一部として渡されます。 これはconsistent関数の古い後方互換のための派生型です。

bool addValue(BrinDesc *bdesc, BrinValues *column, Datum newval, bool isnull)

Given an index tuple and an indexed value, modifies the indicated attribute of the tuple so that it additionally represents the new value. If any modification was done to the tuple, <literal>true</literal> is returned. 追加された新しい値をインデックスが表現できるように、与えられたインデックスタプルとインデックス値にしたがい、タプルの指定アトリビュートを変更します。 タプルの更新が行われれば、trueが返却されます。

bool unionTuples(BrinDesc *bdesc, BrinValues *a, BrinValues *b)

Consolidates two index tuples. Given two index tuples, modifies the indicated attribute of the first of them so that it represents both tuples. The second tuple is not modified. 2つのインデックスタプルを統合します。 与えられた2つのインデックスタプルのうち、最初のインデックスタプルを変更して、両方のタプルを表現できるようにします。 2番目のタプルは変更されません。

An operator class for <acronym>BRIN</acronym> can optionally specify the following method: 省略可能ですが、BRINに対する演算子クラスは以下のメソッドを指定できます。

void options(local_relopts *relopts)

Defines a set of user-visible parameters that control operator class behavior. 演算子クラスの振舞いを制御するユーザに可視のパラメータの集合を定義します。

The <function>options</function> function is passed a pointer to a <structname>local_relopts</structname> struct, which needs to be filled with a set of operator class specific options. The options can be accessed from other support functions using the <literal>PG_HAS_OPCLASS_OPTIONS()</literal> and <literal>PG_GET_OPCLASS_OPTIONS()</literal> macros. options関数にはlocal_relopts構造体へのポインタが渡されますが、構造体を演算子クラスに固有のオプションの集合で満たすことが必要です。 オプションはマクロPG_HAS_OPCLASS_OPTIONS()PG_GET_OPCLASS_OPTIONS()を使って他のサポート関数からアクセスできます。

Since both key extraction of indexed values and representation of the key in <acronym>BRIN</acronym> are flexible, they may depend on user-specified parameters. インデックス付けされた値からのキーの抽出にもBRINでのキーの表現にも柔軟性がありますので、ユーザに固有のパラメータに依存するかもしれません。

The core distribution includes support for four types of operator classes: minmax, minmax-multi, inclusion and bloom. Operator class definitions using them are shipped for in-core data types as appropriate. Additional operator classes can be defined by the user for other data types using equivalent definitions, without having to write any source code; appropriate catalog entries being declared is enough. Note that assumptions about the semantics of operator strategies are embedded in the support functions' source code. コア配布物には、4種類の演算子クラスが含まれます。すなわち、minmax、inclusion、minmax-multiとbloomです。 それらを使った演算子クラスの定義がコア配布物に必要に応じて含まれます。 同じ定義を使って、ユーザは他のデータ型のために演算子クラスを定義することができます。 そのためにソースコードを書く必要はありません。適切なシステムカタログの定義があれば十分です。 演算子ストラテジのセマンティクスは、サポート関数のソースコード中に埋め込まれていることに注意してください。

Operator classes that implement completely different semantics are also possible, provided implementations of the four main support functions described above are written. Note that backwards compatibility across major releases is not guaranteed: for example, additional support functions might be required in later releases. 前述の4つの主要なサポート関数を実装することにより、まったく異なるセマンティクスを実装する演算子クラスも可能です。 なお、メジャーリリース間では下位互換性は保証されていません。 たとえば、新しいリリースでは、サポート関数が追加で必要になるかもしれません。

To write an operator class for a data type that implements a totally ordered set, it is possible to use the minmax support functions alongside the corresponding operators, as shown in <xref linkend="brin-extensibility-minmax-table"/>. All operator class members (functions and operators) are mandatory. 表 71.2で示すように、全順序集合を実装するデータ型のための演算子クラスを書くために、関連する演算子とともにminmaxサポート関数を使うことができます。 演算子クラスのメンバー(関数と演算子)はすべて必須です。

表71.2 Minmax演算子クラスの関数とサポート番号

<title>Function and Support Numbers for Minmax Operator Classes</title>
演算子クラスメンバーオブジェクト
サポート関数 1内部関数brin_minmax_opcinfo()
サポート関数 2内部関数brin_minmax_add_value()
サポート関数 3内部関数brin_minmax_consistent()
サポート関数 4内部関数brin_minmax_union()
Operator Strategy 1operator less-than
Operator Strategy 2operator less-than-or-equal-to
Operator Strategy 3operator equal-to
Operator Strategy 4operator greater-than-or-equal-to
Operator Strategy 5operator greater-than

To write an operator class for a complex data type which has values included within another type, it's possible to use the inclusion support functions alongside the corresponding operators, as shown in <xref linkend="brin-extensibility-inclusion-table"/>. It requires only a single additional function, which can be written in any language. More functions can be defined for additional functionality. All operators are optional. Some operators require other operators, as shown as dependencies on the table. 表 71.3で示すように、他のデータ型の値を含む複合データ型の演算子クラスを書くには、関連する演算子とともに、inclusionサポート関数を使うことができます。 任意の言語で書かれたたったひとつの関数を追加するだけです。 機能を追加するために関数を追加できます。 すべての演算子はオプションです。 表の中依存性の項目で示されているように、ある種の演算子は他の演算子を必要とすることもあります。

表71.3 Inclusion演算子クラスの関数とサポート番号

<title>Function and Support Numbers for Inclusion Operator Classes</title>
演算子クラスメンバーオブジェクト依存性
サポート関数 1内部関数brin_inclusion_opcinfo() 
サポート関数 2内部関数brin_inclusion_add_value() 
サポート関数 3内部関数brin_inclusion_consistent() 
サポート関数 4内部関数brin_inclusion_union() 
サポート関数 112つの要素をマージする関数 
サポート関数 122つの要素がマージ可能かどうか確認するオプションの関数 
サポート関数 13要素が他の要素に含まれるかどうかを確認するオプションの関数 
サポート関数 14要素が空かどうかを確認するオプションの関数 
Operator Strategy 1operator left-ofOperator Strategy 4
Operator Strategy 2operator does-not-extend-to-the-right-ofOperator Strategy 5
Operator Strategy 3operator overlaps 
Operator Strategy 4operator does-not-extend-to-the-left-ofOperator Strategy 1
Operator Strategy 5operator right-ofOperator Strategy 2
Operator Strategy 6, 18operator same-as-or-equal-toOperator Strategy 7
Operator Strategy 7, 16, 24, 25operator contains-or-equal-to 
Operator Strategy 8, 26, 27operator is-contained-by-or-equal-toOperator Strategy 3
Operator Strategy 9operator does-not-extend-aboveOperator Strategy 11
Operator Strategy 10operator is-belowOperator Strategy 12
Operator Strategy 11operator is-aboveOperator Strategy 9
Operator Strategy 12operator does-not-extend-belowOperator Strategy 10
Operator Strategy 20operator less-thanOperator Strategy 5
Operator Strategy 21operator less-than-or-equal-toOperator Strategy 5
Operator Strategy 22operator greater-thanOperator Strategy 1
Operator Strategy 23operator greater-than-or-equal-toOperator Strategy 1

Support function numbers 1 through 10 are reserved for the BRIN internal functions, so the SQL level functions start with number 11. Support function number 11 is the main function required to build the index. It should accept two arguments with the same data type as the operator class, and return the union of them. The inclusion operator class can store union values with different data types if it is defined with the <literal>STORAGE</literal> parameter. The return value of the union function should match the <literal>STORAGE</literal> data type. サポート関数番号1から10は、BRINの内部関数用に予約されており、SQLレベルの関数は番号11から始まります。 サポート関数11は、インデックスを構築するのに必要なメイン関数です。 その関数は演算子クラスと同じデータ型を持つ2つの引数を受け取り、それらの和を返します。 もしSTORAGEパラメータで定義されていれば、inclusion 演算子クラスは異なるデータ型の和を格納できます。 和関数の返り値は、STORAGEデータ型と一致していなければなりません。

Support function numbers 12 and 14 are provided to support irregularities of built-in data types. Function number 12 is used to support network addresses from different families which are not mergeable. Function number 14 is used to support empty ranges. Function number 13 is an optional but recommended one, which allows the new value to be checked before it is passed to the union function. As the BRIN framework can shortcut some operations when the union is not changed, using this function can improve index performance. サポート関数番号12と14は、組み込みデータ型の例外事象をサポートするために提供されます。 サポート関数番号12は、マージできない異なるファミリーのネットワークアドレスをサポートするために使用されます。 サポート関数番号14は、空のレンジをサポートするために使用されます。 サポート関数番号13はオプションですが、和関数に渡される前に新しい値のチェックを行うためのものとして推奨されます。 BRINフレームワークは和が変化しない時に操作を省略することができるため、この関数を使うことによってインデックスの性能が向上する可能性があります。

To write an operator class for a data type that implements only an equality operator and supports hashing, it is possible to use the bloom support procedures alongside the corresponding operators, as shown in <xref linkend="brin-extensibility-bloom-table"/>. All operator class members (procedures and operators) are mandatory. 表 71.4で示すように、等号演算子のみを実装しハッシュをサポートするデータ型の演算子クラスを書くために、関連する演算子とともにbloomがサポートするプロシージャを使うことができます。 演算子クラスのメンバー(プロシージャと演算子)はすべて必須です。

表71.4 Bloom演算子クラスのプロシージャとサポート番号

<title>Procedure and Support Numbers for Bloom Operator Classes</title>
演算子クラスメンバーオブジェクト
サポートプロシージャ 1内部関数brin_bloom_opcinfo()
サポートプロシージャ 2内部関数brin_bloom_add_value()
サポートプロシージャ 3内部関数brin_bloom_consistent()
サポートプロシージャ 4内部関数brin_bloom_union()
サポートプロシージャ 5内部関数brin_bloom_options()
サポートプロシージャ 11要素のハッシュを計算する関数
Operator Strategy 1operator equal-to

Support procedure numbers 1-10 are reserved for the BRIN internal functions, so the SQL level functions start with number 11. Support function number 11 is the main function required to build the index. It should accept one argument with the same data type as the operator class, and return a hash of the value. サポートプロシージャ番号1から10は、BRINの内部関数として予約されており、SQLレベルの関数は11番から始まります。 サポート関数11は、インデックスを構築するのに必要なメイン関数です。 演算子クラスと同じデータ型の引数を1つ受け取り、その値のハッシュを返す必要があります。

The minmax-multi operator class is also intended for data types implementing a totally ordered set, and may be seen as a simple extension of the minmax operator class. While minmax operator class summarizes values from each block range into a single contiguous interval, minmax-multi allows summarization into multiple smaller intervals to improve handling of outlier values. It is possible to use the minmax-multi support procedures alongside the corresponding operators, as shown in <xref linkend="brin-extensibility-minmax-multi-table"/>. All operator class members (procedures and operators) are mandatory. minmax-multi演算子クラスもまた、全順序集合を実装するデータ型を対象としており、minmax演算子クラスの単純な拡張と見なすことができます。 minmax演算子クラスは各ブロックの範囲を一つの連続した区間にまとめますが、minmax-multiはより小さな複数の区間にまとめることで、外れ値の扱いを改善します。 表 71.5で示すように、関連する演算子とともにminmax-multiがサポートするプロシージャを使うことができます。 演算子クラスのメンバー(プロシージャと演算子)はすべて必須です。

表71.5 minmax-multi演算子クラスのプロシージャとサポート番号

<title>Procedure and Support Numbers for minmax-multi Operator Classes</title>
演算子クラスメンバーオブジェクト
サポートプロシージャ 1内部関数brin_minmax_multi_opcinfo()
サポートプロシージャ 2内部関数brin_minmax_multi_add_value()
サポートプロシージャ 3内部関数brin_minmax_multi_consistent()
サポートプロシージャ 4内部関数brin_minmax_multi_union()
サポートプロシージャ 5内部関数brin_minmax_multi_options()
サポートプロシージャ 112つの値の間の距離(範囲の長さ)を計算する関数
Operator Strategy 1operator less-than
Operator Strategy 2operator less-than-or-equal-to
Operator Strategy 3operator equal-to
Operator Strategy 4operator greater-than-or-equal-to
Operator Strategy 5operator greater-than

Both minmax and inclusion operator classes support cross-data-type operators, though with these the dependencies become more complicated. The minmax operator class requires a full set of operators to be defined with both arguments having the same data type. It allows additional data types to be supported by defining extra sets of operators. Inclusion operator class operator strategies are dependent on another operator strategy as shown in <xref linkend="brin-extensibility-inclusion-table"/>, or the same operator strategy as themselves. They require the dependency operator to be defined with the <literal>STORAGE</literal> data type as the left-hand-side argument and the other supported data type to be the right-hand-side argument of the supported operator. See <literal>float4_minmax_ops</literal> as an example of minmax, and <literal>box_inclusion_ops</literal> as an example of inclusion. minmaxとinclusion演算子クラスは、データ型をまたがる演算子をサポートします。 しかし、これらを使用すると依存関係はより複雑になります。 minmax演算子クラスは、両方の引数がデータ型が同じ型である完全な演算子のセットが必要になります。 追加の演算子の組を定義することにより、追加のデータ型をサポートすることができます。 表 71.3で示すように、inclusion演算子クラスのストラテジは、他の演算子クラスのストラテジに依存するか、自分自身の演算子クラスのストラテジに依存します。 演算子クラスは、依存演算子がSTORAGEデータ型とともにサポートするデータ型の左辺引数、他のサポートするデータ型をサポートする演算子の右辺引数として定義される必要があります。 minmaxの例としてfloat4_minmax_ops、inclusionの例としてbox_inclusion_opsを参照してください。