Postgresql 中文操作指南
REFRESH MATERIALIZED VIEW
REFRESH MATERIALIZED VIEW — 替换物化视图的内容
REFRESH MATERIALIZED VIEW — replace the contents of a materialized view
Description
REFRESH MATERIALIZED VIEW 完全替换物化视图的内容。要执行此命令,你必须是物化视图的所有者。旧内容将被丢弃。如果指定(或默认为) WITH DATA ,则执行后备查询以提供新数据,并且物化视图保留在可扫描状态。如果指定 WITH NO DATA ,则不会生成新数据,并且物化视图保留在不可扫描状态。
REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. To execute this command you must be the owner of the materialized view. The old contents are discarded. If WITH DATA is specified (or defaults) the backing query is executed to provide the new data, and the materialized view is left in a scannable state. If WITH NO DATA is specified no new data is generated and the materialized view is left in an unscannable state.
CONCURRENTLY 和 WITH NO DATA 可能不会一起指定。
CONCURRENTLY and WITH NO DATA may not be specified together.
Parameters
-
CONCURRENTLY
-
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.
-
This option is only allowed if there is at least one UNIQUE index on the materialized view which uses only column names and includes all rows; that is, it must not be an expression index or include a WHERE clause.
-
This option may not be used when the materialized view is not already populated.
-
Even with this option only one REFRESH at a time may run against any one materialized view.
-
-
name
-
The name (optionally schema-qualified) of the materialized view to refresh.
-
Notes
如果在物化视图的定义查询中有 ORDER BY 子句,则将按此方式对物化视图的原始内容进行排序;但 REFRESH MATERIALIZED VIEW 并不保证保留该顺序。
If there is an ORDER BY clause in the materialized view’s defining query, the original contents of the materialized view will be ordered that way; but REFRESH MATERIALIZED VIEW does not guarantee to preserve that ordering.
Examples
此命令将使用物化视图定义中的查询替换名为 order_summary 的物化视图的内容,并使其保持可扫描状态:
This command will replace the contents of the materialized view called order_summary using the query from the materialized view’s definition, and leave it in a scannable state:
REFRESH MATERIALIZED VIEW order_summary;
此命令将释放与物化视图 annual_statistics_basis 关联的存储,并使其保持不可扫描状态:
This command will free storage associated with the materialized view annual_statistics_basis and leave it in an unscannable state:
REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;