Re: Implementing Incremental View Maintenance - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Implementing Incremental View Maintenance
Date
Msg-id CAM-w4HOvDrL4ou6m=592zUiKGVzTcOpNj-d_cJqzL00fdsS5kg@mail.gmail.com
Whole thread Raw
In response to Re: Implementing Incremental View Maintenance  (Yugo Nagata <nagata@sraoss.co.jp>)
Responses Re: Implementing Incremental View Maintenance
List pgsql-hackers
On Sun, 31 Mar 2019 at 23:22, Yugo Nagata <nagata@sraoss.co.jp> wrote:
>
> Firstly, this will handle simple definition views which includes only
> selection, projection, and join.  Standard aggregations (count, sum, avg,
> min, max) are not planned to be implemented in the first patch, but these
> are commonly used in materialized views, so I'll implement them later on.

It's fine to not have all the features from day 1 of course. But I
just picked up this comment and the followup talking about splitting
AVG into SUM and COUNT and I had a comment. When you do look at
tackling aggregates I don't think you should restrict yourself to
these specific standard aggregations. We have all the necessary
abstractions to handle all aggregations that are feasible, see
https://www.postgresql.org/docs/devel/xaggr.html#XAGGR-MOVING-AGGREGATES

What you need to do -- I think -- is store the "moving aggregate
state" before the final function. Then whenever a row is inserted or
deleted or updated (or whenever another column is updated which causes
the value to row to enter or leave the aggregation) apply either
aggtransfn or aggminvtransfn to the state. I'm not sure if you want to
apply the final function on every update or only lazily either may be
better in some usage.



pgsql-hackers by date:

Previous
From: Sergei Kornilov
Date:
Subject: Re: allow online change primary_conninfo
Next
From: Shawn Debnath
Date:
Subject: Re: Refactoring the checkpointer's fsync request queue