.\" This is -*-nroff-*- .\" XXX standard disclaimer belongs here.... .\" $Header: /usr/local/cvsroot/pgsql/src/man/create_index.l,v 1.10 1998/04/07 18:12:52 momjian Exp $ .\" .\" Japanese Version Copyright (c) 1998 Michihide Hotta .\" all rights reserved. .\" Translated Wed Jun 3 18:46:34 JST 1998 .\" by Michihide Hotta .\" .TH "CREATE INDEX" SQL 11/05/95 PostgreSQL PostgreSQL .\"0 .SH NAME .\"0 create index - construct a secondary index .SH 名前 create index - 二次インデックスを構築する .\"0 .SH SYNOPSIS .\"0 .nf .\"0 \fBcreate\fR [\fBunique\fR] \fBindex\fR index-name .\"0 \fBon\fR classname [\fBusing\fR am-name] .\"0 \fB(\fR attname [type_class], ...\fB )\fR .\"0 .\"0 \fBcreate\fR [\fBunique\fR] \fBindex\fR index-name .\"0 \fBon\fR classname [\fBusing\fR am-name] .\"0 \fB(\fR funcname \fB(\fR attname\-1 { , attname\-i } .\"0 \fB)\fR type_class \fB)\fR .\"0 .fi .SH 書式 .nf \fBcreate\fR [\fBunique\fR] \fBindex\fR インデックス名 \fBon\fR クラス名 [\fBusing\fR アクセス方式名] \fB(\fR 属性名 [型クラス], ...\fB )\fR \fBcreate\fR [\fBunique\fR] \fBindex\fR インデックス名 \fBon\fR クラス名 [\fBusing\fR アクセス方式名] \fB(\fR 関数名 \fB(\fR 属性名\-1 { , 属性名\-i } \fB)\fR 型クラス \fB)\fR .fi .\"0 .SH DESCRIPTION .\"0 This command constructs an index called .\"0 .IR index-name. .SH 説明 このコマンドは .IR インデックス名 と呼ばれるインデックスを構築する。 .PP .\"0 .IR Am-name .\"0 is the name of the access method which is used for the index. .\"0 The default access method is btree. .IR アクセス方式名 はそのインデックスのために使われるアクセス方式の名前である。 デフォルトのアクセス方式は btree である。 .PP .\"0 In the first syntax shown above, the key fields for the index are .\"0 specified as attribute names. It may also have an associated .\"0 .IR "operator class" . .\"0 An operator class is used to specify the operators to be used .\"0 for a particular index. .\"0 For example, a btree index on four-byte integers would use the .\"0 .IR int4_ops .\"0 class; this operator class includes comparison functions for .\"0 four-byte integers. .\"0 The default operator class is the appropriate operator class for .\"0 that field type. 上記における最初の書式では、インデックスのキー項目は属性名 として指定される。これには関連する .IR "演算子クラス" がある場合もある。演算子クラスは、特殊なインデックスにおいて 使われる演算子を指定するのに使われる。たとえば、4 バイト整数 における btree インデックスは .IR int4_ops クラスを使う場合がある。この演算子クラスは 4 バイト整数を比較 するための関数を含んでいる。デフォルトの演算子クラスは、その 項目型において適切な演算子クラスとなる。 .PP .\"0 \fBNote:\fR currently, only .\"0 .IR btree .\"0 access method supports multi-attribute indices. .\"0 Up to 7 keys may be specified. \fB注意:\fR 現在のところ、 .IR btree アクセス方式だけが複数属性インデックスをサポートしている。 .PP .\"0 In the second syntax shown above, an index can be defined on .\"0 the result of a user-defined function .\"0 .IR funcname .\"0 applied to one or more attributes of a single class. These .\"0 .IR "functional indices" .\"0 can be used to obtain fast access to data based on .\"0 operators that would normally require some transformation to .\"0 be applied to the base data. For example, say you have an .\"0 attribute in class \*(lqmyclass\*(rq called \*(lqpt\*(rq that .\"0 consists of a 2D point type. Now, suppose that you would like .\"0 to index this attribute but you only have index operator classes .\"0 for 2D polygon types. You can define an index on the point .\"0 attribute using a function that you write (call it .\"0 \*(lqpoint_to_polygon\*(rq) and your existing polygon operator .\"0 class; after that, queries using existing polygon operators .\"0 that reference \*(lqpoint_to_polygon(myclass.pt)\*(rq on one .\"0 side will use the precomputed polygons stored in the functional .\"0 index instead of computing a polygon for each and every .\"0 instance in \*(lqmyclass\*(rq and then comparing it to the .\"0 value on the other side of the operator. Obviously, the .\"0 decision to build a functional index represents a .\"0 tradeoff between space (for the index) and execution time. 2 番目の書式を使うと、単一クラスの中の 1 つ以上の属性に適用 されるユーザ定義関数 .IR 関数名 の結果によりインデックスを定義できる。これらの .IR 関数インデックス を使うと、通常元になるデータに対してある種の変換が必要となる ような演算子をベースとするデータに対し、高速なアクセスを行う ことができるようになる。たとえば、あなたは \*(lqmyclass\*(rq 内部に、2D 座標型を持つような \*(lqpt\*(rq と呼ばれる属性を 持っているとしよう。ここで、この属性に対してインデックスを 張りたいが、あなたは 2D 多角形型のインデックス演算子クラス しか持っていないとする。あなたは、自分で書いた関数(それを \*(lqpoint_to_polygon\*(rq とする)と、元々あった多角形演算子 クラスを使って、その座標属性に対してインデックスを張ることが できる。そうすることにより、演算子のうち一方の \*(lqpoint_to_polygon(myclass.pt)\*(rq を参照する既存の多角形 演算子を使った問い合わせは、\*(lqmyclass\*(rq 中のすべての インスタンスについて毎回各多角形の計算をしてそれをその演算子 のもう一方の値と比較するかわりに、関数インデックス内に格納して ある前もって計算しておいた多角形を使う。関数インデックス を構築するということは、(インデックス用の)記憶領域と実行時間 とのトレードオフであることは明らかである。 .PP .\"0 The \fBunique\fR keyword causes the system to check for .\"0 duplicate values when the index is created (if data already .\"0 exist) and each time data is added. Attempts to insert or .\"0 update non-duplicate data will generate an error. \fBunique\fR キーワードを使うと、システムはインデックスを 生成する際に、(データがすでに存在していれば)値の重複チェック を行ってからデータを追加する。重複しないデータを挿入したり 更新したりしようとするとエラーとなる。 .PP .\"0 Postgres provides btree, rtree and hash access methods for .\"0 secondary indices. The btree access method is an .\"0 implementation of the Lehman-Yao high-concurrency btrees. .\"0 The rtree access method implements standard rtrees using .\"0 Guttman's quadratic split algorithm. The hash access method .\"0 is an implementation of Litwin's linear hashing. We mention .\"0 the algorithms used solely to indicate that all of these .\"0 access methods are fully dynamic and do not have to be .\"0 optimized periodically (as is the case with, for example, .\"0 static hash access methods). Postgres では、二次インデックスに対して btree, rtree および ハッシュ(hash)アクセス方式を提供している。btree アクセス方式は、 Lehman-Yao の高並列 btree 実装系を採用している。rtree アクセス 方式では Guttman の四分の一分割アルゴリズムを使った標準 rtree で実装されている。ハッシュアクセス方式は Litwin の線形ハッシュ の実装系である。これらすべてのアクセス方法は完全に動的であり、 また定期的に最適化される必要はない(たとえばこのケースとして 静的ハッシュ方式があげられる)ことをお断りしておく。 .PP .\"0 This list was generated from the Postgres system catalogs .\"0 with the query: このリストは、Postgres システムカタログから以下の問い合わせ により生成されたものである。 .nf 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; acc_name|ops_name |ops_comp --------+-----------+-------- btree |abstime_ops|< btree |abstime_ops|<= btree |abstime_ops|= btree |abstime_ops|> btree |abstime_ops|>= btree |bpchar_ops |< btree |bpchar_ops |<= btree |bpchar_ops |= btree |bpchar_ops |> btree |bpchar_ops |>= btree |char16_ops |< btree |char16_ops |<= btree |char16_ops |= btree |char16_ops |> btree |char16_ops |>= btree |char2_ops |< btree |char2_ops |<= btree |char2_ops |= btree |char2_ops |> btree |char2_ops |>= btree |char4_ops |< btree |char4_ops |<= btree |char4_ops |= btree |char4_ops |> btree |char4_ops |>= btree |char8_ops |< btree |char8_ops |<= btree |char8_ops |= btree |char8_ops |> btree |char8_ops |>= btree |char_ops |< btree |char_ops |<= btree |char_ops |= btree |char_ops |> btree |char_ops |>= btree |date_ops |< btree |date_ops |<= btree |date_ops |= btree |date_ops |> btree |date_ops |>= btree |float4_ops |< btree |float4_ops |<= btree |float4_ops |= btree |float4_ops |> btree |float4_ops |>= btree |float8_ops |< btree |float8_ops |<= btree |float8_ops |= btree |float8_ops |> btree |float8_ops |>= btree |int24_ops |< btree |int24_ops |<= btree |int24_ops |= btree |int24_ops |> btree |int24_ops |>= btree |int2_ops |< btree |int2_ops |<= btree |int2_ops |= btree |int2_ops |> btree |int2_ops |>= btree |int42_ops |< btree |int42_ops |<= btree |int42_ops |= btree |int42_ops |> btree |int42_ops |>= btree |int4_ops |< btree |int4_ops |<= btree |int4_ops |= btree |int4_ops |> btree |int4_ops |>= btree |name_ops |< btree |name_ops |<= btree |name_ops |= btree |name_ops |> btree |name_ops |>= btree |oid_ops |< btree |oid_ops |<= btree |oid_ops |= btree |oid_ops |> btree |oid_ops |>= btree |oidint2_ops|< btree |oidint2_ops|<= btree |oidint2_ops|= btree |oidint2_ops|> btree |oidint2_ops|>= btree |oidint4_ops|< btree |oidint4_ops|<= btree |oidint4_ops|= btree |oidint4_ops|> btree |oidint4_ops|>= btree |oidname_ops|< btree |oidname_ops|<= btree |oidname_ops|= btree |oidname_ops|> btree |oidname_ops|>= btree |text_ops |< btree |text_ops |<= btree |text_ops |= btree |text_ops |> btree |text_ops |>= btree |time_ops |< btree |time_ops |<= btree |time_ops |= btree |time_ops |> btree |time_ops |>= btree |varchar_ops|< btree |varchar_ops|<= btree |varchar_ops|= btree |varchar_ops|> btree |varchar_ops|>= hash |bpchar_ops |= hash |char16_ops |= hash |char2_ops |= hash |char4_ops |= hash |char8_ops |= hash |char_ops |= hash |date_ops |= hash |float4_ops |= hash |float8_ops |= hash |int2_ops |= hash |int4_ops |= hash |name_ops |= hash |oid_ops |= hash |text_ops |= hash |time_ops |= hash |varchar_ops|= rtree |bigbox_ops |&& rtree |bigbox_ops |&< rtree |bigbox_ops |&> rtree |bigbox_ops |<< rtree |bigbox_ops |>> rtree |bigbox_ops |@ rtree |bigbox_ops |~ rtree |bigbox_ops |~= rtree |box_ops |&& rtree |box_ops |&< rtree |box_ops |&> rtree |box_ops |<< rtree |box_ops |>> rtree |box_ops |@ rtree |box_ops |~ rtree |box_ops |~= rtree |poly_ops |&& rtree |poly_ops |&< rtree |poly_ops |&> rtree |poly_ops |<< rtree |poly_ops |>> rtree |poly_ops |@ rtree |poly_ops |~ rtree |poly_ops |~= .fi .\"0 The .\"0 .IR int24_ops .\"0 operator class is useful for constructing indices on int2 .\"0 data, and doing comparisons against int4 data in query .\"0 qualifications. Similarly, .\"0 .IR int42_ops .\"0 support indices on int4 data that is to be compared against .\"0 int2 data in queries. .IR int24_ops 演算子クラスは、int2 データのインデックスを構築してから int4 データとの比較を行う際に有用である。同様に、 .IR int42_ops では int4 データを int2 データと比較するためのインデックス をサポートしている。 .PP .\"0 The operator classes 演算子クラス .IR oidint2_ops , .IR oidint4_ops , .\"0 and と .IR oidchar16_ops .\"0 represent the use of .\"0 .IR "functional indices" .\"0 to simulate multi-key indices. .\"0 These are no longer needed now that multi-key indexes are .\"0 supported. は、複数キーインデックスをシミュレートするために .IR "関数インデックス" を使う場合に使用するが、複数キーインデックスがサポートされた ためにこれらはもはや必要とされない。 .PP .\"0 The Postgres query optimizer will consider using btree .\"0 indices in a scan whenever an indexed attribute is involved .\"0 in a comparison using one of: Postgres の問い合わせ最適化機構では、インデックスされた属性が .nf < <= = >= > .fi を使った比較で呼び出される際は常に、スキャンするのに btree インデックスを使うことを考える。 .\"0 Both box classes support indices on the \*(lqbox\*(rq datatype .\"0 in Postgres. The difference between them is that .\"0 .IR bigbox_ops .\"0 scales box coordinates down, to avoid floating point .\"0 exceptions from doing multiplication, addition, and .\"0 subtraction on very large floating-point coordinates. .\"0 If the field on which your rectangles lie is about .\"0 20,000 units square or larger, you should use .\"0 .IR bigbox_ops . .\"0 The .\"0 .IR poly_ops .\"0 operator class supports rtree indices on \*(lqpolygon\*(rq data. いずれの長方形(box)クラスにおいても、Postgres では \*(lqbox\*(rq データ型におけるインデックスがサポートされて いる。それらの違いは、 .IR bigbox_ops では乗算および巨大な浮動小数点座標における減算において浮動 小数点例外が発生するのを防ぐために、長方形の座標をスケール ダウンを行うことである。長方形を含む項目が 2 万個以上ある 場合は .IR bigbox_ops を使う方がよいだろう。 .PP .\"0 The Postgres query optimizer will consider using an rtree .\"0 index whenever an indexed attribute is involved in a .\"0 comparison using one of: Postgres の問い合わせ最適化機構では、インデックスされた属性が .nf << &< &> >> @ ~= && .fi を使った比較で呼び出される際は常に、rtree インデックスを使う ことを考える。 .\"0 The Postgres query optimizer will consider using a hash index .\"0 whenever an indexed attribute is involved in a comparison .\"0 using the \fB=\fR operator. Postgres の問い合わせ最適化機構では、インデックスされた属性が \fB=\fR を使った比較で呼び出される際は常に、ハッシュインデックス を使うことを考える。 .\"0 .SH EXAMPLES .SH 例 .nf -- .\"0 --Create a btree index on the emp class using the age attribute. -- 従業員クラスに年齢属性を使って btree インデックスを生成する -- .\"0 create index empindex on emp using btree (age int4_ops) create index 従業員インデックス on 従業員 using btree (年齢 int4_ops) .fi .nf -- .\"0 --Create a btree index on employee name. 従業員名で btree インデックスを生成する -- .\"0 create index empname .\"0 on emp using btree (name char16_ops) create index 従業員名 on 従業員 using btree (名前 char16_ops) .fi .nf -- .\"0 --Create an rtree index on the bounding rectangle of cities. -- 都市の境界長方形の rtree インデックスを生成する -- .\"0 create index cityrect .\"0 on city using rtree (boundbox box_ops) create index 都市境界 on 都市 using rtree (境界長方形 box_ops) .fi .nf -- .\"0 --Create a rtree index on a point attribute such that we .\"0 --can efficiently use box operators on the result of the .\"0 --conversion function. Such a qualification might look .\"0 --like "where point2box(points.pointloc) = boxes.box". .\"0 -- -- 変換関数の結果における長方形演算子を効率的に使用する -- ような座標属性の rtree インデックスを生成する。このような -- 修飾子は "where point2box(points.pointloc) = boxes.box" -- のようになるだろう。 create index pointloc on points using rtree (point2box(location) box_ops) .nf .SH 翻訳者 堀田 倫英