pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Kellerer <shammat@gmx.net>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Dependencies of Matviews?
Date: Tue, 23 Jun 2020 17:25:01 -0400
Message-ID: <2164198.1592947501@sss.pgh.pa.us> (raw)
In-Reply-To: <800f556a-29cf-3528-d720-84e7eae8ad45@gmx.net>
References: <800f556a-29cf-3528-d720-84e7eae8ad45@gmx.net>

Thomas Kellerer <shammat@gmx.net> writes:
> I would like to extract the dependency between materialized views.
> e.g. in the following situation:
>     create materialized view mv1 as select ....;
>     create materialized view mv2 as select ... from mv1, ...;
> I would like to know that mv2 depends on mv1.
> I assumed this could be done through pg_depend, but the only dependency I see there for the matviews is the one for the namespace.

Most of the interesting dependencies for a view or matview are actually
held by its ON SELECT rule.  For example:

regression=# create materialized view mv1 as select * from int8_tbl;
SELECT 5
regression=# create materialized view mv2 as select * from mv1;
SELECT 5
regression=# select 'mv1'::regclass::oid;
  oid  
-------
 58550
(1 row)
regression=# select * from pg_depend where objid >= 58550 or refobjid >= 58550;
 classid | objid | objsubid | refclassid | refobjid | refobjsubid | deptype 
---------+-------+----------+------------+----------+-------------+---------
    1247 | 58552 |        0 |       1259 |    58550 |           0 | i
    1247 | 58551 |        0 |       1247 |    58552 |           0 | i
    1259 | 58550 |        0 |       2615 |     2200 |           0 | n
    2618 | 58553 |        0 |       1259 |    58550 |           0 | i
    2618 | 58553 |        0 |       1259 |    58550 |           0 | n
    2618 | 58553 |        0 |       1259 |    37540 |           1 | n
    2618 | 58553 |        0 |       1259 |    37540 |           2 | n
    1247 | 58556 |        0 |       1259 |    58554 |           0 | i
    1247 | 58555 |        0 |       1247 |    58556 |           0 | i
    1259 | 58554 |        0 |       2615 |     2200 |           0 | n
    2618 | 58557 |        0 |       1259 |    58554 |           0 | i
    2618 | 58557 |        0 |       1259 |    58554 |           0 | n
    2618 | 58557 |        0 |       1259 |    58550 |           1 | n
    2618 | 58557 |        0 |       1259 |    58550 |           2 | n
(14 rows)

or more readably,

regression=# select pg_describe_object(classid,objid,objsubid) as obj, pg_describe_object(refclassid,refobjid,refobjsubid) as ref, deptype from pg_depend where objid >= 58550 or refobjid >= 58550;
                  obj                  |                ref                 | deptype 
---------------------------------------+------------------------------------+---------
 type mv1                              | materialized view mv1              | i
 type mv1[]                            | type mv1                           | i
 materialized view mv1                 | schema public                      | n
 rule _RETURN on materialized view mv1 | materialized view mv1              | i
 rule _RETURN on materialized view mv1 | materialized view mv1              | n
 rule _RETURN on materialized view mv1 | column q1 of table int8_tbl        | n   <<<<<
 rule _RETURN on materialized view mv1 | column q2 of table int8_tbl        | n   <<<<<
 type mv2                              | materialized view mv2              | i
 type mv2[]                            | type mv2                           | i
 materialized view mv2                 | schema public                      | n
 rule _RETURN on materialized view mv2 | materialized view mv2              | i
 rule _RETURN on materialized view mv2 | materialized view mv2              | n
 rule _RETURN on materialized view mv2 | column q1 of materialized view mv1 | n   <<<<<
 rule _RETURN on materialized view mv2 | column q2 of materialized view mv1 | n   <<<<<
(14 rows)

where I marked the actually-interesting dependencies with <<<<<.

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <2164198.1592947501@sss.pgh.pa.us>
Permalink:  ../2164198.1592947501@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2164198.1592947501@sss.pgh.pa.us

 · 

reply

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: tgl@sss.pgh.pa.us, shammat@gmx.net
  Subject: Re: Dependencies of Matviews?
  In-Reply-To: <2164198.1592947501@sss.pgh.pa.us>
  References: <800f556a-29cf-3528-d720-84e7eae8ad45@gmx.net> <2164198.1592947501@sss.pgh.pa.us>

* 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