TABLESAMPLEに対するSYSTEM_ROWSサンプリングメソッド #
The <filename>tsm_system_rows</filename> module provides the table sampling method
<literal>SYSTEM_ROWS</literal>, which can be used in
the <literal>TABLESAMPLE</literal> clause of a <link linkend="sql-select"><command>SELECT</command></link>
command.
tsm_system_rowsモジュールはSYSTEM_ROWSというテーブルサンプリングメソッドを提供します。
これはSELECTコマンドのTABLESAMPLE句で利用できます。
This table sampling method accepts a single integer argument that is the maximum number of rows to read. The resulting sample will always contain exactly that many rows, unless the table does not contain enough rows, in which case the whole table is selected. このテーブルサンプリングメソッドは読み込む最大行数を指定する整数の引数を1つ取ります。 結果のサンプルにはいつでもそれと正確に同じだけの行数が含まれます。 ただしテーブルにそれだけの行数がないときは、テーブル全体が選択されることになります。
Like the built-in <literal>SYSTEM</literal> sampling
method, <literal>SYSTEM_ROWS</literal> performs block-level sampling, so
that the sample is not completely random but may be subject to clustering
effects, especially if only a small number of rows are requested.
組み込みのSYSTEMサンプリングメソッドと同様、SYSTEM_ROWSはブロックレベルのサンプリングを行うため、サンプルは完全にはランダムではなく、特にごく少数の行が要求されたときはクラスタリングの影響を受けます。
<literal>SYSTEM_ROWS</literal> does not support
the <literal>REPEATABLE</literal> clause.
SYSTEM_ROWSはREPEATABLE句をサポートしません。
This module is considered <quote>trusted</quote>, that is, it can be
installed by non-superusers who have <literal>CREATE</literal> privilege
on the current database.
このモジュールは「trusted」と見なされます。つまり、現在のデータベースに対してCREATE権限を持つ非スーパーユーザがインストールできます。
Here is an example of selecting a sample of a table with
<literal>SYSTEM_ROWS</literal>. First install the extension:
以下にSYSTEM_ROWSを使ってテーブルのサンプルをSELECTする例を示します。
まず、拡張をインストールします。
CREATE EXTENSION tsm_system_rows;
Then you can use it in a <command>SELECT</command> command, for instance:
これで、例えば以下のようにSELECTコマンドを使うことができます。
SELECT * FROM my_table TABLESAMPLE SYSTEM_ROWS(100);
This command will return a sample of 100 rows from the
table <structname>my_table</structname> (unless the table does not have 100
visible rows, in which case all its rows are returned).
このコマンドはテーブルmy_tableからサンプルの100行を返します。
(ただし、テーブルに可視の行が100行ないときは、すべての行が返されます。)