

> Index Only Scan using wrd_word on wrd (cost=0.42.4.44 rows=1 width=0) (actual time=0.039.0.039 rows=0 loops=1)Įither way, the word is spelled wrong, so let's look for what we might have wanted. If the materialized view is used instead, the query is much faster:Īggregate (cost=4.44.4.45 rows=1 width=0) (actual time=0.042.0.042 rows=1 loops=1) Sum(invoice_amt)::numeric(13,2) as sales_amt

If people want to be able to quickly graph historical sales data, they might want to summarize, and they may not care about the incomplete data for the current date:ĬREATE MATERIALIZED VIEW sales_summary AS Invoice_amt numeric(13,2) - amount of sale While access to the data stored in a materialized view is often much faster than accessing the underlying tables directly or through a view, the data is not always current yet sometimes current data is not needed. When a materialized view is referenced in a query, the data is returned directly from the materialized view, like from a table the rule is only used for populating the materialized view. So for the parser, a materialized view is a relation, just like a table or a view.

The information about a materialized view in the PostgreSQL system catalogs is exactly the same as it is for a table or view. The main differences between:ĬREATE MATERIALIZED VIEW mymatview AS SELECT * FROM mytab ĬREATE TABLE mymatview AS SELECT * FROM mytab Īre that the materialized view cannot subsequently be directly updated and that the query used to create the materialized view is stored in exactly the same way that a view's query is stored, so that fresh data can be generated for the materialized view with: Materialized views in PostgreSQL use the rule system like views do, but persist the results in a table-like form.
