Advice on using materialized views - Mailing list pgsql-general

From Phil Endecott
Subject Advice on using materialized views
Date
Msg-id 1638816527952@dmwebmail.dmwebmail.chezphil.org
Whole thread Raw
Responses Re: Advice on using materialized views  (Nick Cleaton <nick@cleaton.net>)
Re: Advice on using materialized views  (Wicher <wicher+pglist@gavagai.nl>)
List pgsql-general
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.





pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Query planner issue with preferring primary key over a better index when using ORDER BY and LIMIT
Next
From: Rob Sargent
Date:
Subject: Re: Query planner issue with preferring primary key over a better index when using ORDER BY and LIMIT