Re: Advice on using materialized views

From: Nick Cleaton <nick(at)cleaton(dot)net>
To: Phil Endecott <spam_from_pgsql_lists(at)chezphil(dot)org>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Advice on using materialized views
Date: 2021-12-07 07:07:37
Message-ID: CAFgz3kujqese1a4Ymi7U_KRFOysG_yT8tMSOYQRkCaToiGLWeg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 6 Dec 2021 at 18:48, Phil Endecott
<spam_from_pgsql_lists(at)chezphil(dot)org> wrote:
>
> - 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.

Assuming your table is insert-only:

How about instead of using a materialized view at all, you define a
table of hourly summaries which your script updates, and define a view
which merges that with an on-the-fly summary of main table rows newer
than the most recent summarised hour.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Avi Weinberg 2021-12-07 07:51:33 RE: Are Foreign Key Disabled During Logical Replication Initial Sync?
Previous Message Peter Eisentraut 2021-12-07 05:18:56 Re: Are Foreign Key Disabled During Logical Replication Initial Sync?