| 1 |
<!-- doc/src/sgml/tsm-system-time.sgml --> |
| 2 |
|
| 3 |
<sect1 id="tsm-system-time" xreflabel="tsm_system_time"> |
| 4 |
<title>tsm_system_time — |
| 5 |
the <literal>SYSTEM_TIME</literal> sampling method for <literal>TABLESAMPLE</literal></title> |
| 6 |
|
| 7 |
<indexterm zone="tsm-system-time"> |
| 8 |
<primary>tsm_system_time</primary> |
| 9 |
</indexterm> |
| 10 |
|
| 11 |
<para> |
| 12 |
The <filename>tsm_system_time</filename> module provides the table sampling method |
| 13 |
<literal>SYSTEM_TIME</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 floating-point argument that |
| 20 |
is the maximum number of milliseconds to spend reading the table. This |
| 21 |
gives you direct control over how long the query takes, at the price that |
| 22 |
the size of the sample becomes hard to predict. The resulting sample will |
| 23 |
contain as many rows as could be read in the specified time, unless the |
| 24 |
whole table has been read first. |
| 25 |
</para> |
| 26 |
|
| 27 |
<para> |
| 28 |
Like the built-in <literal>SYSTEM</literal> sampling |
| 29 |
method, <literal>SYSTEM_TIME</literal> performs block-level sampling, so |
| 30 |
that the sample is not completely random but may be subject to clustering |
| 31 |
effects, especially if only a small number of rows are selected. |
| 32 |
</para> |
| 33 |
|
| 34 |
<para> |
| 35 |
<literal>SYSTEM_TIME</literal> does not support |
| 36 |
the <literal>REPEATABLE</literal> clause. |
| 37 |
</para> |
| 38 |
|
| 39 |
<para> |
| 40 |
This module is considered <quote>trusted</quote>, that is, it can be |
| 41 |
installed by non-superusers who have <literal>CREATE</literal> privilege |
| 42 |
on the current database. |
| 43 |
</para> |
| 44 |
|
| 45 |
<sect2 id="tsm-system-time-examples"> |
| 46 |
<title>Examples</title> |
| 47 |
|
| 48 |
<para> |
| 49 |
Here is an example of selecting a sample of a table with |
| 50 |
<literal>SYSTEM_TIME</literal>. First install the extension: |
| 51 |
</para> |
| 52 |
|
| 53 |
<programlisting> |
| 54 |
CREATE EXTENSION tsm_system_time; |
| 55 |
</programlisting> |
| 56 |
|
| 57 |
<para> |
| 58 |
Then you can use it in a <command>SELECT</command> command, for instance: |
| 59 |
|
| 60 |
<programlisting> |
| 61 |
SELECT * FROM my_table TABLESAMPLE SYSTEM_TIME(1000); |
| 62 |
</programlisting> |
| 63 |
</para> |
| 64 |
|
| 65 |
<para> |
| 66 |
This command will return as large a sample of <structname>my_table</structname> as |
| 67 |
it can read in 1 second (1000 milliseconds). Of course, if the whole |
| 68 |
table can be read in under 1 second, all its rows will be returned. |
| 69 |
</para> |
| 70 |
</sect2> |
| 71 |
|
| 72 |
</sect1> |