CREATE INDEX

Name

CREATE INDEX  --  Constructs a secondary index 補助的インデックスを作成します。

Synopsis

CREATE [ UNIQUE ] INDEX index_name
    ON table [ USING acc_name ]
    ( column [ ops_name] [, ...] )
CREATE [ UNIQUE ] INDEX index_name
    ON table [ USING acc_name ]
    ( func_name( r">colle> [, ... ]) ops_name )
  

入力

UNIQUE

Causes the system to check for duplicate values in the table when the index is created (if data already exist) and each time data is added. Attempts to insert or update non-duplicate data will generate an error.

テーブルに(既にデータがあり)インデックスが作成されたときと、 データが追加される毎に値が重複していないかをチェックします。 重複行を作成するようなデータの挿入または更新はエラーとなります。

index_name

The name of the index to be created.

作成されるインデックスの名前です。

table

The name of the table to be indexed.

インデックスが付けられるテーブルの名前です。

acc_name

the name of the access method which is to be used for the index. The default access method is BTREE. Postgres provides three access methods for secondary indexes:

インデックスに用いられるアクセスメソッドの名前です。 デフォルトのアクセスメソッドは BTREE です。 Postgres は補助的インデックスに対して 3 つのアクセスメソッド を提供しています。

BTREE

an implementation of the Lehman-Yao high-concurrency btrees.

Lehman-Yao による高度の同時性を有した btrees の 実装です。

RTREE

implements standard rtrees using Guttman's quadratic split algorithm.

は Guttman の 2 次分割アルゴリズムを使用して 標準 の rtrees を実装します。

HASH

an implementation of Litwin's linear hashing.

Litwin の線形ハッシングの実装です。

column

The name of a column of the table.

テーブルのカラムの名前です。

ops_name

An associated operator class. The following select list returns all ops_names:

対応する演算子のクラスです。 以下の select 文は全ての ops_names を返します。 ※ 訳注:演算子クラス(オペレータクラス)については 片岡裕生氏(mailto:kataoka@interwiz.koganei.ktoyo.jp) による判りやすい説明が「ソフトウェアデザイン」 6 月号に掲載しあり、それによると、オペレータクラス は「物の尺度」つまりどのように物を比較するかの判断 基準を表現していると解説しています。

SELECT am.amname AS acc_name,
       opc.opcname AS ops_name,
       opr.oprname AS ops_comp
    FROM pg_am am, pg_amop amop,
         pg_opclass opc, pg_operator opr
    WHERE amop.amopid = am.oid AND
          amop.amopclaid = opc.oid AND
          amop.amopopr = opr.oid
    ORDER BY acc_name, ops_name, ops_comp
	

func_name

A user-defined function, which returns a value that can be indexed.

インデックス付けされる値を返す、ユーザ定義の関数です。

出力

CREATE

The message returned if the index is successfully created.

インデックスが正常に作成された場合に返されるメッセージです。

ERROR: Cannot create index: 'index_name' already exists.

This error occurs if it is impossible to create the index.

インデックスを作成出来なかった場合に出力されるエラーです。

説明

CREATE INDEX constructs an index index_name. on the specified table.

CREATE INDEX はインデックス index_name を指定されたテーブル table 上に構成します。

Tip: Indexes are primarily used to enhance database performance. But inappropriate use will result in slower performance.

インデックスは主としてデータベースの効率を向上する ために使用されますが、適切な方法で使用しないと逆に 効率を落すことになります。

In the first syntax shown above, the key fields for the index are specified as column names; a column may also have an associated operator class. An operator class is used to specify the operators to be used for a particular index. For example, a btree index on four-byte integers would use the int4_ops class; this operator class includes comparison functions for four-byte integers. The default operator class is the appropriate operator class for that field type.

上記の最初の構文では、インデックスに対するキーフィールドは カラムの名前として指定されていて、そのカラムも対応する 演算子クラスを持っていることがあります。 演算子クラスはある特定のインデックスで使用 される演算子を特定する場合に使用されます。例えば、4 バイト の整数上の btree インデックスは int4_ops クラスを使用し、この演算子クラスは 4 バイト整数を比較する 機能を持っています。デフォルトの演算子クラスはそのフィールド 型に対して適切な演算子クラスです。

In the second syntax, an index is defined on the result of a user-defined function func_name applied to one or more attributes of a single class. These functional indexes can be used to obtain fast access to data based on operators that would normally require some transformation to apply them to the base data.

第二の構文では、ある一つのクラスの一つまたは複数の 属性に適用されるユーザ定義関数 func_name の結果に従ってインデックスが指定されます。 これらの関数によるインデックスは、データベースに適用する際、 何らかの変換が必要とされる演算子に基づいてデータに高速に アクセスするときに使用することが出来ます。

注意事項

Currently, only the BTREE access method supports multi-column indexes. Up to 7 keys may be specified.

現時点では、 BTREE アクセスメソッドのみが複数カラムインデックス をサポートしています。

Use DROP INDEX to remove an index.

インデックスを削除するには DROP INDEX を使います。

使用法

テーブル films 内のフィールド title 上に btree インデックスを作成 するには:

CREATE UNIQUE INDEX title_idx
    ON films (title);
  

と書きます。

互換性

SQL92

CREATE INDEX is a Postgres language extension.

CREATE INDEX は Postgres の 拡張言語です。

There is no CREATE INDEX command in SQL92.

SQL92 に CREATE INDEX コマンドはありません。