Thread: 9.3 beta and materialized views

9.3 beta and materialized views

From
Thomas Kellerer
Date:
Hi,

I'm currently adding the support for materialized views to my SQL tool, and noticed that when creating a materialized
view,a rewrite rule is also created that looks just like a rewrite rule for a "normal" view. 

Using pg_get_ruledef() I see that the rule is defined like this:

REATE RULE "_RETURN" AS
     ON SELECT TO matview_test DO INSTEAD
   SELECT <here comes the select of the mview>


As the materialized view should be a "table" that can be selected from, I wonder what the purpose of the rewrite rule
is?

Regards
Thomas

Re: 9.3 beta and materialized views

From
Tom Lane
Date:
Thomas Kellerer <spam_eater@gmx.net> writes:
> I'm currently adding the support for materialized views to my SQL tool, and noticed that when creating a materialized
view,a rewrite rule is also created that looks just like a rewrite rule for a "normal" view. 

Yup.

> As the materialized view should be a "table" that can be selected from, I wonder what the purpose of the rewrite rule
is?

To store the matview's definition for use in REFRESH.

            regards, tom lane


Re: 9.3 beta and materialized views

From
Thomas Kellerer
Date:
Tom Lane wrote on 16.05.2013 19:36:
>> As the materialized view should be a "table" that can be selected from, I wonder what the purpose of the rewrite
ruleis? 
>
> To store the matview's definition for use in REFRESH.
>
Ah, right. Makes sense.

Thanks for the quick reply.



Re: 9.3 beta and materialized views

From
Kevin Grittner
Date:
Thomas Kellerer <spam_eater@gmx.net> wrote:
> Tom Lane wrote on 16.05.2013 19:36:

>>> As the materialized view should be a "table" that can be
>>> selected from, I wonder what the purpose of the rewrite rule
>>> is?
>>
>> To store the matview's definition for use in REFRESH.
>>
> Ah, right. Makes sense.

It will also be used to drive incremental update (in future
releases), as it does in every other product with materialized
views that I know of.  In 9.3 we only got as far as explicit
REFRESH, but I hope to improve on that in 9.4.

--
Kevin Grittner
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company