CLUSTER

Name

CLUSTER  --  Gives storage clustering advice to the backend 記憶領域のクラスタ構成情報をバックエンドに与えます。

Synopsis

CLUSTER indexname ON table
  

入力

インデックス名

The name of an index.

インデックスの名前です。

テーブル

The name of a table.

テーブルの名前です。

出力

CLUSTER

The clustering was done successfully.

クラスタ構成が正常に終了しました。

ERROR: relation <tablerelation_number> inherits "invoice"

この件についてはどこにも書かれていません。 継承されたテーブルをクラスタ構成することが出来ない のかもしれません。

ERROR: Relation x does not exist!

警告されたリレーションはエラーメッセージには表示されません。 エラーメッセージにはリレーション名ではなくでたらめな文字列が 入っています。

解説

CLUSTER instructs Postgres to cluster the class specified by classname approximately based on the index specified by indexname. The index must already have been defined on classname.

CLUSTERindexname で指定された インデックスにほぼ基づいた、 classname で指定された クラスでクラスタ構成するように Postgres に指示します。インデックスは前もって classname で定義 されていなければなりません。

When a class is clustered, it is physically reordered based on the index information. The clustering is static. In other words, as the class is updated, the changes are not clustered. No attempt is made to keep new instances or updated tuples clustered. If one wishes, one can recluster manually by issuing the command again.

クラスがクラスタ構成されると、インデックス情報に基づいて 物理的に再序列されます。クラスタ構成は静的です。 別の表現をすると、クラスが更新されるにしたがって、その 変更はクラスタ構成されません。新しいインスタンスやクラスタ 構成済みのタプルへの更新は保存されません。 保存したい場合、コマンドを再度入力し手作業で再クラスタ構成 を行います。

注意事項

The table is actually copied to a temporary table in index order, then renamed back to the original name. For this reason, all grant permissions and other indexes are lost when clustering is performed.

実際にはテーブルはインデックスの順序で暫定テーブルに コピーされ、そしてオリジナルの名前に戻されます。 この理由によって、全ての付与されたパーミッションと他の インデックスはクラスタ構成が行われるときに失われます。

In cases where you are accessing single rows randomly within a table, the actual order of the data in the heap table is unimportant. However, if you tend to access some data more than others, and there is an index that groups them together, you will benefit from using CLUSTER.

あるテーブル内の一つの行をランダムにアクセスする場合、 ヒープテーブル内のデータの実際の順序は重要でありません。 とは言っても、そのテーブル内のデータに更に多くアクセス しようとしたとき、そしてそれらのデータをグループ化している インデックスがあるときは、CLUSTER を 使うことによる利益を享受することが出来ます。

CLUSTER が便利な別の場面として、 あるテーブルからいくつかの行を抽出するインデックスを 使用する時があげられます。あるテーブルからインデックスの値 の範囲とか、適合する複数行を所持する単一のインデックスの 値を抽出する場合、インデックスがひとたび最初に一致する行に たいするヒープページを認識すると、他に適合する全ての他の行は、 多分同じヒープページに存在するので、CLUSTER はディスクアクセスを控え目にして問合せ処理の速度を速めます。

There are two ways to cluster data. The first is with the CLUSTER command, which reorders the original table with the ordering of the index you specify. This can be slow on large tables because the rows are fetched from the heap in index order, and if the heap table is unordered, the entries are on random pages, so there is one disk page retrieved for every row moved. Postgres has a cache, but the majority of a big table will not fit in the cache.

データをクラスタ構成するには二つの方法があります。 その一つは、CLUSTER コマンドで オリジナルのテーブルを指定したインデックスの順序によって 再順序付けをします。行はインデックスの順序におけるヒープ からフェッチされ、そしてヒープテーブルが順序付けらていない とき、項目はでたらめの順序のページ上に存在することになり、 したがって、それぞれの移動させられた行に対し一つのディスク ページが抽出されるため、大きなテーブルに対してこの方法は 遅い結果をもたらします。 Postgres にはキャッシュがありますが 大きなテーブルの大多数はキャッシュに収まり切れません。

Another way to cluster data is to use

データをクラスタ構成するもう一つの方法は次の SQL 文を実行 することです。

SELECT ... INTO TABLE temp FROM ... ORDER BY ...
    
This uses the Postgres sorting code in ORDER BY to match the index, and is much faster for unordered data. You then drop the old table, use ALTER TABLE/RENAME to rename temp to the old name, and recreate any indexes. The only problem is that OIDs will not be preserved. From then on, CLUSTER should be fast because most of the heap data has already been ordered, and the existing index is used. これは Postgres の ORDER BY のソートのコードをインデックスに一致させるために使用するので、 順序付けられていないデータに対して高速です。 その後、旧いテーブルを削除し、ALTER TABLE/RENAMEtemp を前の名前に リネームしてから、どんなインデックスを再生成して構いません。 OID が保存されないのが唯一の問題点です。 その後、CLUSTER はほとんどのヒープデータが 順序づけられて、そこにあるインデックスが使用されるため、 速くなるはずです。

使用法

Cluster the employees relation on the basis of its salary attribute

給与属性に基づいて従業員リレーションをクラスタ構成するには、

CLUSTER emp_ind ON emp;
  

のようにします。

互換性

SQL92

There is no CLUSTER statement in SQL92.

CLUSTER 文は SQL92 とは互換性がありません。