ALTER INDEX <refpurpose>change the definition of an index</refpurpose> — インデックス定義を変更する
ALTER INDEX [ IF EXISTS ]nameRENAME TOnew_nameALTER INDEX [ IF EXISTS ]nameSET TABLESPACEtablespace_nameALTER INDEXnameATTACH PARTITIONindex_nameALTER INDEXname[ NO ] DEPENDS ON EXTENSIONextension_nameALTER INDEX [ IF EXISTS ]nameSET (storage_parameter[=value] [, ... ] ) ALTER INDEX [ IF EXISTS ]nameRESET (storage_parameter[, ... ] ) ALTER INDEX [ IF EXISTS ]nameALTER [ COLUMN ]column_numberSET STATISTICSintegerALTER INDEX ALL IN TABLESPACEname[ OWNED BYrole_name[, ... ] ] SET TABLESPACEnew_tablespace[ NOWAIT ]
<command>ALTER INDEX</command> changes the definition of an existing index.
There are several subforms described below. Note that the lock level required
may differ for each subform. An <literal>ACCESS EXCLUSIVE</literal> lock is held
unless explicitly noted. When multiple subcommands are listed, the lock
held will be the strictest one required from any subcommand.
ALTER INDEXは既存のインデックスの定義を変更します。
以下のような副構文が存在します。
要求されるロックレベルはそれぞれの副構文によって異なることに注意してください。
特に記述がなければACCESS EXCLUSIVEロックを取得します。
複数のサブコマンドが使われるときは、それらのサブコマンドが要求するうち、もっとも高いレベルのロックを取得します。
RENAME
The <literal>RENAME</literal> form changes the name of the index.
If the index is associated with a table constraint (either
<literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>,
or <literal>EXCLUDE</literal>), the constraint is renamed as well.
There is no effect on the stored data.
このRENAME構文は、インデックスの名前を変更します。
インデックスがテーブル制約(UNIQUE、PRIMARY KEY、EXCLUDEのいずれか)と関連付けられていた場合、制約名も変更されます。
格納されたデータには影響しません。
Renaming an index acquires a <literal>SHARE UPDATE EXCLUSIVE</literal>
lock.
インデックスの名前の変更にはSHARE UPDATE EXCLUSIVEロックが必要です。
SET TABLESPACE
This form changes the index's tablespace to the specified tablespace and
moves the data file(s) associated with the index to the new tablespace.
To change the tablespace of an index, you must own the index and have
<literal>CREATE</literal> privilege on the new tablespace.
All indexes in the current database in a tablespace can be moved by using
the <literal>ALL IN TABLESPACE</literal> form, which will lock all
indexes to be moved and then move each one. This form also supports
<literal>OWNED BY</literal>, which will only move indexes owned by the
roles specified. If the <literal>NOWAIT</literal> option is specified
then the command will fail if it is unable to acquire all of the locks
required immediately. Note that system catalogs will not be moved by
this command, use <command>ALTER DATABASE</command> or explicit
<command>ALTER INDEX</command> invocations instead if desired.
See also
<link linkend="sql-createtablespace"><command>CREATE TABLESPACE</command></link>.
この構文は、インデックスのテーブル空間を指定したテーブル空間に変更し、インデックスに関連するデータファイルを移動します。
インデックスのテーブル空間を変更するには、インデックスの所有者であり、かつ新しいテーブル空間のCREATE権限を有している必要があります。
ALL IN TABLESPACE構文を使うことで、テーブル空間内の現在のデータベースのすべてのインデックスを移動することができます。
この場合、移動されるすべてのインデックスがロックされ、それから1つずつ移動されます。
この構文はOWNED BYもサポートしており、これを使うと、指定のロールが所有しているインデックスだけを移動します。
NOWAITオプションを指定した場合、必要とするすべてのロックを即座に獲得できなければ、このコマンドは失敗します。
このコマンドではシステムカタログは移動されないことに注意してください。
必要であれば、ALTER DATABASEを使うか、あるいはALTER INDEXで明示的に指定してください。
CREATE TABLESPACEも参照してください。
ATTACH PARTITION index_nameCauses the named index (possibly schema-qualified) to become attached to the altered index. The named index must be on a partition of the table containing the index being altered, and have an equivalent definition. An attached index cannot be dropped by itself, and will automatically be dropped if its parent index is dropped. 指定されたインデックス(スキーマ修飾可)を変更するインデックスに付加します。 指定されたインデックスは、変更するインデックスを持つテーブルのパーティションに対するもので、かつ、同じ定義を持たなければなりません。 付加されたインデックスは、それ自身として削除できず、親インデックスが削除された場合に自動的に削除されます。
DEPENDS ON EXTENSION extension_nameNO DEPENDS ON EXTENSION extension_name
This form marks the index as dependent on the extension, or no longer
dependent on that extension if <literal>NO</literal> is specified.
An index that's marked as dependent on an extension is automatically
dropped when the extension is dropped.
この構文は、インデックスが拡張に依存している、もしくはNOが指定された場合には拡張にもはや依存していないと印を付けます。
拡張に依存していると印をつけられたインデックスは、拡張が削除されると自動的に削除されます。
SET ( storage_parameter [= value] [, ... ] )
This form changes one or more index-method-specific storage parameters
for the index. See
<link linkend="sql-createindex"><command>CREATE INDEX</command></link>
for details on the available parameters. Note that the index contents
will not be modified immediately by this command; depending on the
parameter you might need to rebuild the index with
<link linkend="sql-reindex"><command>REINDEX</command></link>
to get the desired effects.
この構文は、インデックスに対し、インデックスメソッド固有の1つ以上の格納パラメータを変更します。
設定可能なパラメータについてはCREATE INDEXを参照してください。
このコマンドにより、インデックスの内容がすぐに変更されるわけではないことに注意してください。
パラメータによりますが、期待する効果を得るためにREINDEXを使用してインデックスを再構築しなければならない場合もあります。
RESET ( storage_parameter [, ... ] )
This form resets one or more index-method-specific storage parameters to
their defaults. As with <literal>SET</literal>, a <literal>REINDEX</literal>
might be needed to update the index entirely.
この構文は、1つ以上のインデックスメソッド固有の格納パラメータをデフォルト値に再設定します。
SET同様、インデックスを完全に更新するためにREINDEXが必要になる場合があります。
ALTER [ COLUMN ] column_number SET STATISTICS integer
This form sets the per-column statistics-gathering target for
subsequent <link linkend="sql-analyze"><command>ANALYZE</command></link> operations, though can
be used only on index columns that are defined as an expression.
Since expressions lack a unique name, we refer to them using the
ordinal number of the index column.
The target can be set in the range 0 to 10000; alternatively, set it
to -1 to revert to using the system default statistics
target (<xref linkend="guc-default-statistics-target"/>).
For more information on the use of statistics by the
<productname>PostgreSQL</productname> query planner, refer to
<xref linkend="planner-stats"/>.
この構文は、以後のANALYZE操作にむけた、列ごとの統計収集対象を設定します。ただし、式として定義されたインデックス列のみに使えます。
式には一意な名前が無いため、これらはインデックス列の序数を使って参照します。
対象は0から10000の範囲で設定できます。代わりに-1と設定すると、システムのデフォルト統計対象(default_statistics_target)に戻します。
PostgreSQLの問い合わせプランナによる統計の利用についての詳細は14.2を参照してください。
IF EXISTSDo not throw an error if the index does not exist. A notice is issued in this case. インデックスが存在しない場合にエラーとしません。 この場合注意メッセージが発生します。
column_numberThe ordinal number refers to the ordinal (left-to-right) position of the index column. インデックス列の順序位置(左から右)を参照する序数。
nameThe name (possibly schema-qualified) of an existing index to alter. 変更対象の既存のインデックスの名前です(スキーマ修飾名も可)。
new_nameThe new name for the index. インデックスの新しい名前です。
tablespace_nameThe tablespace to which the index will be moved. インデックスの移動先のテーブル空間です。
extension_nameThe name of the extension that the index is to depend on. インデックスが依存することになる拡張の名前です。
storage_parameterThe name of an index-method-specific storage parameter. インデックスメソッド固有の格納パラメータの名前です。
valueThe new value for an index-method-specific storage parameter. This might be a number or a word depending on the parameter. インデックスメソッド固有の格納パラメータの新しい値です。 パラメータに応じてこれが数値になることも文字列になることもあります。
These operations are also possible using
<link linkend="sql-altertable"><command>ALTER TABLE</command></link>.
<command>ALTER INDEX</command> is in fact just an alias for the forms
of <command>ALTER TABLE</command> that apply to indexes.
これらの操作はALTER TABLEを使用して行うこともできます。
実際には、ALTER INDEXは、ALTER TABLEのインデックス用構文の別名に過ぎません。
There was formerly an <command>ALTER INDEX OWNER</command> variant, but
this is now ignored (with a warning). An index cannot have an owner
different from its table's owner. Changing the table's owner
automatically changes the index as well.
以前はALTER INDEX OWNERという種類の構文がありましたが、(警告の上)無視されるようになりました。
インデックスの所有者は基のテーブルの所有者と異なるものにすることができません。
テーブルの所有者を変更すると自動的にインデックスの所有者も変わります。
Changing any part of a system catalog index is not permitted. システムカタログ用インデックスに対する変更は許されていません。
To rename an existing index: 既存のインデックスの名前を変更します。
ALTER INDEX distributors RENAME TO suppliers;
To move an index to a different tablespace: インデックスを別のテーブル空間に移動します。
ALTER INDEX distributors SET TABLESPACE fasttablespace;
To change an index's fill factor (assuming that the index method supports it): インデックスのフィルファクタを変更します(インデックスメソッドがフィルファクタをサポートしていることを前提とします)。
ALTER INDEX distributors SET (fillfactor = 75); REINDEX INDEX distributors;
Set the statistics-gathering target for an expression index: 式インデックスに対して統計収集対象を設定します。
CREATE INDEX coord_idx ON measured (x, y, (z + t)); ALTER INDEX coord_idx ALTER COLUMN 3 SET STATISTICS 1000;
<command>ALTER INDEX</command> is a <productname>PostgreSQL</productname>
extension.
ALTER INDEXはPostgreSQLの拡張です。