| 1 |
<!-- doc/src/sgml/tsm-system-rows.sgml --> |
| 2 |
|
| 3 |
<sect1 id="tsm-system-rows" xreflabel="tsm_system_rows"> |
| 4 |
<title>tsm_system_rows — |
| 5 |
the <literal>SYSTEM_ROWS</literal> sampling method for <literal>TABLESAMPLE</literal></title> |
| 6 |
|
| 7 |
<indexterm zone="tsm-system-rows"> |
| 8 |
<primary>tsm_system_rows</primary> |
| 9 |
</indexterm> |
| 10 |
|
| 11 |
<para> |
| 12 |
The <filename>tsm_system_rows</filename> module provides the table sampling method |
| 13 |
<literal>SYSTEM_ROWS</literal>, which can be used in |
| 14 |
the <literal>TABLESAMPLE</literal> clause of a <link linkend="sql-select"><command>SELECT</command></link> |
| 15 |
command. |
| 16 |
</para> |
| 17 |
|
| 18 |
<para> |
| 19 |
This table sampling method accepts a single integer argument that is the |
| 20 |
maximum number of rows to read. The resulting sample will always contain |
| 21 |
exactly that many rows, unless the table does not contain enough rows, in |
| 22 |
which case the whole table is selected. |
| 23 |
</para> |
| 24 |
|
| 25 |
<para> |
| 26 |
Like the built-in <literal>SYSTEM</literal> sampling |
| 27 |
method, <literal>SYSTEM_ROWS</literal> performs block-level sampling, so |
| 28 |
that the sample is not completely random but may be subject to clustering |
| 29 |
effects, especially if only a small number of rows are requested. |
| 30 |
</para> |
| 31 |
|
| 32 |
<para> |
| 33 |
<literal>SYSTEM_ROWS</literal> does not support |
| 34 |
the <literal>REPEATABLE</literal> clause. |
| 35 |
</para> |
| 36 |
|
| 37 |
<para> |
| 38 |
This module is considered <quote>trusted</quote>, that is, it can be |
| 39 |
installed by non-superusers who have <literal>CREATE</literal> privilege |
| 40 |
on the current database. |
| 41 |
</para> |
| 42 |
|
| 43 |
<sect2 id="tsm-system-rows-examples"> |
| 44 |
<title>Examples</title> |
| 45 |
|
| 46 |
<para> |
| 47 |
Here is an example of selecting a sample of a table with |
| 48 |
<literal>SYSTEM_ROWS</literal>. First install the extension: |
| 49 |
</para> |
| 50 |
|
| 51 |
<programlisting> |
| 52 |
CREATE EXTENSION tsm_system_rows; |
| 53 |
</programlisting> |
| 54 |
|
| 55 |
<para> |
| 56 |
Then you can use it in a <command>SELECT</command> command, for instance: |
| 57 |
|
| 58 |
<programlisting> |
| 59 |
SELECT * FROM my_table TABLESAMPLE SYSTEM_ROWS(100); |
| 60 |
</programlisting> |
| 61 |
</para> |
| 62 |
|
| 63 |
<para> |
| 64 |
This command will return a sample of 100 rows from the |
| 65 |
table <structname>my_table</structname> (unless the table does not have 100 |
| 66 |
visible rows, in which case all its rows are returned). |
| 67 |
</para> |
| 68 |
</sect2> |
| 69 |
|
| 70 |
</sect1> |