Skip to content

Commit 46794f9

Browse files
yugo-nCommitfest Bot
authored andcommitted
Add relisivm column to pg_class system catalog
If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. Also, isimmv columns is added to pg_matviews system view. isimmv
1 parent 1b53f92 commit 46794f9

File tree

9 files changed

+40
-0
lines changed

9 files changed

+40
-0
lines changed

src/backend/catalog/heap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ InsertPgClassTuple(Relation pg_class_desc,
938938
values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite);
939939
values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid);
940940
values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid);
941+
values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm);
941942
if (relacl != (Datum) 0)
942943
values[Anum_pg_class_relacl - 1] = relacl;
943944
else

src/backend/catalog/index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ index_create(Relation heapRelation,
10071007
indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner;
10081008
indexRelation->rd_rel->relam = accessMethodId;
10091009
indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid);
1010+
indexRelation->rd_rel->relisivm = false;
10101011

10111012
/*
10121013
* store index's pg_class entry

src/backend/catalog/system_views.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS
146146
T.spcname AS tablespace,
147147
C.relhasindex AS hasindexes,
148148
C.relispopulated AS ispopulated,
149+
C.relisivm AS isimmv,
149150
pg_get_viewdef(C.oid) AS definition
150151
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
151152
LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace)

src/backend/utils/cache/lsyscache.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,30 @@ get_rel_relispartition(Oid relid)
20422042
return false;
20432043
}
20442044

2045+
/*
2046+
* get_rel_relisivm
2047+
*
2048+
* Returns the relisivm flag associated with a given relation.
2049+
*/
2050+
bool
2051+
get_rel_relisivm(Oid relid)
2052+
{
2053+
HeapTuple tp;
2054+
2055+
tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid));
2056+
if (HeapTupleIsValid(tp))
2057+
{
2058+
Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp);
2059+
bool result;
2060+
2061+
result = reltup->relisivm;
2062+
ReleaseSysCache(tp);
2063+
return result;
2064+
}
2065+
else
2066+
return false;
2067+
}
2068+
20452069
/*
20462070
* get_rel_tablespace
20472071
*

src/backend/utils/cache/relcache.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,8 @@ formrdesc(const char *relationName, Oid relationReltype,
19311931

19321932
/* ... and they're always populated, too */
19331933
relation->rd_rel->relispopulated = true;
1934+
/* ... and they're always no ivm, too */
1935+
relation->rd_rel->relisivm = false;
19341936

19351937
relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING;
19361938
relation->rd_rel->relpages = 0;

src/include/catalog/pg_class.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat
119119
/* is relation a partition? */
120120
bool relispartition BKI_DEFAULT(f);
121121

122+
/* is relation a matview with ivm? */
123+
bool relisivm BKI_DEFAULT(f);
124+
122125
/* link to original rel during table rewrite; otherwise 0 */
123126
Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class);
124127

src/include/utils/lsyscache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ extern Oid get_rel_namespace(Oid relid);
139139
extern Oid get_rel_type_id(Oid relid);
140140
extern char get_rel_relkind(Oid relid);
141141
extern bool get_rel_relispartition(Oid relid);
142+
extern bool get_rel_relisivm(Oid relid);
142143
extern Oid get_rel_tablespace(Oid relid);
143144
extern char get_rel_persistence(Oid relid);
144145
extern Oid get_rel_relam(Oid relid);

src/include/utils/rel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,12 @@ RelationCloseSmgr(Relation relation)
676676
*/
677677
#define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated)
678678

679+
/*
680+
* RelationIsIVM
681+
* True if relation is an incrementally maintainable materialized view.
682+
*/
683+
#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm)
684+
679685
/*
680686
* RelationIsAccessibleInLogicalDecoding
681687
* True if we need to log enough information to have access via

src/test/regress/expected/rules.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,6 +1393,7 @@ pg_matviews| SELECT n.nspname AS schemaname,
13931393
t.spcname AS tablespace,
13941394
c.relhasindex AS hasindexes,
13951395
c.relispopulated AS ispopulated,
1396+
c.relisivm AS isimmv,
13961397
pg_get_viewdef(c.oid) AS definition
13971398
FROM ((pg_class c
13981399
LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace)))

0 commit comments

Comments
 (0)