1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-31 22:04:40 +03:00

Add support for REFRESH MATERIALIZED VIEW CONCURRENTLY.

This allows reads to continue without any blocking while a REFRESH
runs.  The new data appears atomically as part of transaction
commit.

Review questioned the Assert that a matview was not a system
relation.  This will be addressed separately.

Reviewed by Hitoshi Harada, Robert Haas, Andres Freund.
Merged after review with security patch f3ab5d4.
This commit is contained in:
Kevin Grittner
2013-07-16 12:55:44 -05:00
parent 7f7485a0cd
commit cc1965a99b
16 changed files with 644 additions and 57 deletions

View File

@ -928,8 +928,7 @@ ERROR: could not serialize access due to read/write dependencies among transact
</para>
<para>
This lock mode is not automatically acquired on tables by any
<productname>PostgreSQL</productname> command.
Acquired by <command>REFRESH MATERIALIZED VIEW CONCURRENTLY</command>.
</para>
</listitem>
</varlistentry>

View File

@ -21,7 +21,7 @@ PostgreSQL documentation
<refsynopsisdiv>
<synopsis>
REFRESH MATERIALIZED VIEW <replaceable class="PARAMETER">name</replaceable>
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <replaceable class="PARAMETER">name</replaceable>
[ WITH [ NO ] DATA ]
</synopsis>
</refsynopsisdiv>
@ -38,12 +38,44 @@ REFRESH MATERIALIZED VIEW <replaceable class="PARAMETER">name</replaceable>
data is generated and the materialized view is left in an unscannable
state.
</para>
<para>
<literal>CONCURRENTLY</literal> and <literal>WITH NO DATA</literal> may not
be specified together.
</para>
</refsect1>
<refsect1>
<title>Parameters</title>
<variablelist>
<varlistentry>
<term><literal>CONCURRENTLY</literal></term>
<listitem>
<para>
Refresh the materialized view without locking out concurrent selects on
the materialized view. Without this option a refresh which affects a
lot of rows will tend to use fewer resources and complete more quickly,
but could block other connections which are trying to read from the
materialized view. This option may be faster in cases where a small
number of rows are affected.
</para>
<para>
This option is only allowed if there is at least one
<literal>UNIQUE</literal> index on the materialized view which uses only
column names and includes all rows; that is, it must not index on any
expressions nor include a <literal>WHERE</literal> clause.
</para>
<para>
This option may not be used when the materialized view is not already
populated.
</para>
<para>
Even with this option only one <literal>REFRESH</literal> at a time may
run against any one materialized view.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><replaceable class="PARAMETER">name</replaceable></term>
<listitem>