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

71.1. はじめに #

<title>Introduction</title>

<acronym>BRIN</acronym> stands for Block Range Index. <acronym>BRIN</acronym> is designed for handling very large tables in which certain columns have some natural correlation with their physical location within the table. BRINは「ブロックレンジインデックス」(Block Range Index)の略です。 BRINは、ある列がテーブル内の物理的な位置と自然な相関があるような、非常に大規模なテーブルのために設計されています。

<acronym>BRIN</acronym> works in terms of <firstterm>block ranges</firstterm> (or <quote>page ranges</quote>). A block range is a group of pages that are physically adjacent in the table; for each block range, some summary info is stored by the index. For example, a table storing a store's sale orders might have a date column on which each order was placed, and most of the time the entries for earlier orders will appear earlier in the table as well; a table storing a ZIP code column might have all codes for a city grouped together naturally. BRINブロックレンジ(block range)(またはページレンジ(page range))として動作します。 ブロックレンジ(block range)は、テーブル内で物理的に隣接するページのグループです。それぞれのブロックレンジに対して、ある種の要約情報がインデックス内に格納されます。 たとえば、店舗の受注情報を格納するテーブルは、各々の受注時期を格納する日付列を持つでしょう。大抵の場合、より前の受注エントリは、テーブルのより前の方にあるでしょう。 郵便番号を管理するテーブルでは、ある市に属する郵便番号が自然にグループ化されることになるでしょう。

<acronym>BRIN</acronym> indexes can satisfy queries via regular bitmap index scans, and will return all tuples in all pages within each range if the summary info stored by the index is <firstterm>consistent</firstterm> with the query conditions. The query executor is in charge of rechecking these tuples and discarding those that do not match the query conditions &mdash; in other words, these indexes are lossy. Because a <acronym>BRIN</acronym> index is very small, scanning the index adds little overhead compared to a sequential scan, but may avoid scanning large parts of the table that are known not to contain matching tuples. BRINインデックスは、通常のビットマップインデックススキャンを通じて要求されるクエリに使用することができます。 すなわち、インデックス内のレンジ要約情報が検索条件と一致すれば、BRINインデックスは、レンジ内の全タプルを返します。 クエリエグゼキュータの役割は、検索条件を再チェックし、条件に合致しないタプルを捨てることです。 つまり言い換えると、BRINインデックスには損失性があります。 BRINインデックスは非常に小さいため、それに対するスキャンは順スキャンに比べると小さなオーバーヘッドしか与えません。しかし、あらかじめ条件に合致しないと分かっているテーブルの多くの部分をスキャンすることを避けることができます。

The specific data that a <acronym>BRIN</acronym> index will store, as well as the specific queries that the index will be able to satisfy, depend on the operator class selected for each column of the index. Data types having a linear sort order can have operator classes that store the minimum and maximum value within each block range, for instance; geometrical types might store the bounding box for all the objects in the block range. BRINインデックスに格納される特定のデータと、そのインデックスが対応できる特定のクエリは、インデックスに対応する各々の列に与えられた演算子クラスに依存します。 線形のソート順を持つデータ型は、ブロックレンジ内の最小値と最大値と格納する演算子クラスを持つことができます。 たとえば、幾何データ型は、ブロックレンジ内のすべてのオブジェクトを含む外接矩形を持つことでしょう。

The size of the block range is determined at index creation time by the <literal>pages_per_range</literal> storage parameter. The number of index entries will be equal to the size of the relation in pages divided by the selected value for <literal>pages_per_range</literal>. Therefore, the smaller the number, the larger the index becomes (because of the need to store more index entries), but at the same time the summary data stored can be more precise and more data blocks can be skipped during an index scan. ブロックレンジの大きさは、ストレージパラメータpages_per_rangeでインデックス作成時に決定されます。 インデックスエントリの数は、リレーションのページ数をpages_per_rangeに設定した数で割ったものと等しくなります。 ですから、pages_per_rangeの設定値が小さいほど、インデックスは大きくなります(より多くのインデックスエントリを格納する必要があるので)が、反面、格納されたサマリーデータはより精密になり、インデックススキャンの際により多くのデータブロックをスキップすることができるようになります。

71.1.1. インデックスの保守 #

<title>Index Maintenance</title>

At the time of creation, all existing heap pages are scanned and a summary index tuple is created for each range, including the possibly-incomplete range at the end. As new pages are filled with data, page ranges that are already summarized will cause the summary information to be updated with data from the new tuples. When a new page is created that does not fall within the last summarized range, the range that the new page belongs to does not automatically acquire a summary tuple; those tuples remain unsummarized until a summarization run is invoked later, creating the initial summary for that range. インデックスを作成した当初は、すべてのヒープページがスキャンされ、終端が不完全なものも含め、各々のレンジに対してサマリーインデックスタプルが作成されます。 新しいページにデータが登録されると、新しいタプルのデータを元に、すでにサマリー済みのページレンジのサマリー情報が更新されます。 最終サマリーレンジに適合しない新しいページが作成されると、そのレンジに対して自動的にはサマリータプルが作成されません。 これらのタプルは、後でサマリー処理が走って初期サマリー情報が作成されるまではサマリーされません。

There are several ways to trigger the initial summarization of a page range. If the table is vacuumed, either manually or by <link linkend="autovacuum">autovacuum</link>, all existing unsummarized page ranges are summarized. Also, if the index's <xref linkend="index-reloption-autosummarize"/> parameter is enabled, which it isn't by default, whenever autovacuum runs in that database, summarization will occur for all unsummarized page ranges that have been filled, regardless of whether the table itself is processed by autovacuum; see below. ページレンジの初期サマリー処理を起動する複数の方法があります。 手動あるいはautovacuumのどちらでも良いですが、テーブルがバキュームされるとすべてのまだサマライズされていないページレンジがサマライズされます。 また、インデックスのautosummarizeパラメータが有効なら、これはデフォルトでは有効ではありませんが、そのデータベースに対してバキュームが実行されると、自動バキュームによってそのテーブル自体が処理されるかどうかにかかわらず、すべての挿入された未サマリーページレンジに対してサマリー処理が実行されます。 以下を見てください。

Lastly, the following functions can be used: 最後に、次の関数が利用できます。

<function>brin_summarize_new_values(regclass)</function> which summarizes all unsummarized ranges; すべての未サマリーレンジをサマライズするbrin_summarize_new_values(regclass)
<function>brin_summarize_range(regclass, bigint)</function> which summarizes only the range containing the given page, if it is unsummarized. もしまだサマライズされていなければ、指定されたページを含む指定されたレンジのみをサマライズするbrin_summarize_range(regclass, bigint)

When autosummarization is enabled, a request is sent to <literal>autovacuum</literal> to execute a targeted summarization for a block range when an insertion is detected for the first item of the first page of the next block range, to be fulfilled the next time an autovacuum worker finishes running in the same database. If the request queue is full, the request is not recorded and a message is sent to the server log: 自動サマリー機能が有効な場合、次のブロックレンジの最初のページの最初の項目の挿入が検出されると、同じデータベースで実行中の自動バキュームワーカーの次の実行の終了時に処理されるブロックレンジをターゲットとするサマリー機能を実行する要求がautovacuumに送信されます。 もしリクエストキューが満杯ならばそのリクエストは記録されず、次のメッセージがサーバのログに送信されます。

LOG:  request for BRIN range summarization for index "brin_wi_idx" page 128 was not recorded

When this happens, the range will remain unsummarized until the next regular vacuum run on the table, or one of the functions mentioned above are invoked. この状態が発生すると、テーブルの次の通常バキュームが実行されるか、上で述べた関数のどれかが実行されるまでは、そのレンジはサマライズされない状態にとどまります。

Conversely, a range can be de-summarized using the <function>brin_desummarize_range(regclass, bigint)</function> function, which is useful when the index tuple is no longer a very good representation because the existing values have changed. See <xref linkend="functions-admin-index"/> for details. 反対に、レンジはbrin_desummarize_range(regclass, bigint)関数で非サマリー化できます。 これは、既存の値が変更されたためにインデックスタプルがもはや値の表現としては適当でなくなった場合に有効です。 詳細は9.27.8を見てください。