From: Phil Endecott <spam_from_pgsql_lists@chezphil.org>
To: pgsql-general@lists.postgresql.org
Subject: Advice on using materialized views
Date: Mon, 06 Dec 2021 18:48:47 +0000
Message-ID: <1638816527952@dmwebmail.dmwebmail.chezphil.org> (raw)
Dear Experts,
Does anyone have any suggestions about how to use materialized
views in combination with regular views for the most recent data?
Example:
- I have a raw data table, indexed on a timestamp column, to which
new data is regularly being added.
- I have a set of views that produce hourly/daily/monthly summaries
of this data. Querying these views is slow, so I'd like to make
them materialized views.
- But I'd like the most recent data to be included in the results
of my queries. So I think I need a combined view that is the
union of the materialized view and a non-materialised view for
the recent values.
I can imagine how to implement this but it feels rather clunky;
I need a parallel set of views for the "old" and "new" data, and
I need to modify the definition of a view that filters the "new"
values from the raw table each time the materialised view is
refreshed.
I'm wondering if anyone has an advice or examples of how best
to do this.
Many thanks, Phil.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: spam_from_pgsql_lists@chezphil.org
Subject: Re: Advice on using materialized views
In-Reply-To: <1638816527952@dmwebmail.dmwebmail.chezphil.org>
References: <1638816527952@dmwebmail.dmwebmail.chezphil.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox