agora inbox for [email protected]help / color / mirror / Atom feed
[PATCH v24 02/15] Add relisivm column to pg_class system catalog 72+ messages / 1 participants [nested] [flat]
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v24 02/15] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 81cc39fb70..e2bc308dff 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -966,6 +966,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 26bfa74ce7..763f442a1d 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -961,6 +961,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 4ebaa552a2..c626df32cc 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2013,6 +2013,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 9fa9e671a1..d80b652f55 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1916,6 +1916,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index fef9945ed8..2058978b89 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 77871aaefc..09346aaa17 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index b4faa1c123..b5028f3449 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -649,6 +649,8 @@ RelationGetSmgr(Relation rel) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.17.1 --Multipart=_Fri__29_Oct_2021_18_16_28_+0900_jlYRKjywLqhZ7oyk Content-Type: text/x-diff; name="v24-0003-Add-new-deptype-option-m-in-pg_depend-system-cat.patch" Content-Disposition: attachment; filename="v24-0003-Add-new-deptype-option-m-in-pg_depend-system-cat.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v33 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 00074c8a94..8d5470c8f7 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -938,6 +938,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index a819b4197c..eb81685f6b 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1007,6 +1007,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 19cabc9a47..c88c8af96b 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 48a280d089..59c06b853c 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2042,6 +2042,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 66ed24e401..cba2eac1e8 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1931,6 +1931,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 0fc2c093b0..80cbee29ca 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 20446f6f83..6b17921d23 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -139,6 +139,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 8700204953..7f36d6f5fa 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -676,6 +676,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 4c789279e5..c7ba7be647 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1393,6 +1393,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.25.1 --Multipart=_Tue__2_Jul_2024_17_03_11_+0900_6OrVBZxOB4o_k6A1 Content-Type: text/x-diff; name="v33-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v33-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v26 02/10] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 7e99de88b3..212a6293aa 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -935,6 +935,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 5e3fc2b35d..d861211f66 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -982,6 +982,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 1b7e11b93e..3275963886 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2023,6 +2023,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fccffce572..149c84535c 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1903,6 +1903,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 304e8c18d5..fbaa1438d6 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index b8dd27d4a9..cc2f635122 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 3b4ab65ae2..fc6b6ddec8 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -650,6 +650,8 @@ RelationGetSmgr(Relation rel) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.17.1 --Multipart=_Mon__14_Mar_2022_19_12_17_+0900_E9HVp8j5QFkIIek. Content-Type: text/x-diff; name="v26-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v26-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v27 2/9] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 9b512ccd3c..a9a314fefe 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -920,6 +920,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index fd389c28d8..4d1c99a8bd 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -982,6 +982,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 1b7e11b93e..3275963886 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2023,6 +2023,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 43f14c233d..a67ba4d8b1 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1923,6 +1923,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 304e8c18d5..fbaa1438d6 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index b8dd27d4a9..cc2f635122 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index eadbd00904..0e28716e6b 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -661,6 +661,8 @@ RelationGetSmgr(Relation rel) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.17.1 --Multipart=_Fri__22_Apr_2022_14_58_01_+0900_MN3L/o2YUVF2g4zw Content-Type: text/x-diff; name="v27-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v27-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v25 02/15] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 7e99de88b3..212a6293aa 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -935,6 +935,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 2308d40256..244c9af7b8 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -981,6 +981,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index feef999863..1db83878c6 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2013,6 +2013,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 2e760e8a3b..0dd901d6ed 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1902,6 +1902,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 304e8c18d5..fbaa1438d6 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index b8dd27d4a9..cc2f635122 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 6da1b220cd..6356c24f84 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -650,6 +650,8 @@ RelationGetSmgr(Relation rel) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.17.1 --Multipart=_Fri__4_Feb_2022_01_48_06_+0900_N8BNZpfOR27sWrgY Content-Type: text/x-diff; name="v25-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v25-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v32 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index cc31909012..1d2e2228c4 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -937,6 +937,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index b6a7c60e23..906ec6c088 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1007,6 +1007,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 401fb35947..16c3399975 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 26368ffcc9..01af4ad5bb 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2020,6 +2020,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 039c0d3eef..c64b9e7bf5 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1936,6 +1936,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 0fc2c093b0..80cbee29ca 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 35a8dec2b9..93c2fcb21c 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f25f769af2..d3144c949f 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -678,6 +678,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 5e45ce64f7..04c54482a1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1392,6 +1392,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.25.1 --Multipart=_Sun__31_Mar_2024_22_59_31_+0900_msknEviJj08_wgqO Content-Type: text/x-diff; name="v32-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v32-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v29 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ src/test/regress/expected/rules.out | 1 + 9 files changed, 36 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index b534da7d80..d9eac41463 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -924,6 +924,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index fd09378848..e4b52fdd21 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -993,6 +993,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 77b06e2a7a..2b60ed9e52 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index fc6d267e44..2b29ab4409 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2046,6 +2046,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 7234cb3da6..96cd510780 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1924,6 +1924,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 2d1bb7af3a..62b9c0e5cb 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index f5fdbfe116..7b433749f5 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -138,6 +138,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 1426a353cd..b8961176bb 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -677,6 +677,8 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 5058be5411..cc5287344d 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1392,6 +1392,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.25.1 --Multipart=_Mon__28_Aug_2023_11_52_52_+0900_hj6L5h176QaSGtg7 Content-Type: text/x-diff; name="v29-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v29-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v30 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ src/test/regress/expected/rules.out | 1 + 9 files changed, 36 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 348943e36c..b186d9e82c 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -927,6 +927,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 4b88a9cb87..3b59c44b0e 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -992,6 +992,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 04227a72d1..273ae3062f 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index f730aa26c4..20b873b38e 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2019,6 +2019,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 50acae4529..278b8519b1 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1927,6 +1927,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 3b7533e7bb..23a933e46c 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index e4a200b00e..544fa94a68 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index ab9fa4faf9..ae693adaa5 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -675,6 +675,8 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 0cd2c64fca..984fe16bb8 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1392,6 +1392,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.25.1 --Multipart=_Mon__4_Mar_2024_11_58_46_+0900_UaponF/qQhQrVCFt Content-Type: text/x-diff; name="v30-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v30-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v23 02/15] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 83746d3fd9..ade3586779 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -963,6 +963,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 26bfa74ce7..763f442a1d 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -961,6 +961,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 6bba5f8ec4..8d5214fb90 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2013,6 +2013,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 13d9994af3..5b130f0ed2 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1865,6 +1865,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index fef9945ed8..2058978b89 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 77871aaefc..09346aaa17 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index b4faa1c123..b5028f3449 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -649,6 +649,8 @@ RelationGetSmgr(Relation rel) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.17.1 --Multipart=_Mon__2_Aug_2021_15_28_34_+0900_wlHCjIpnD/FrGAKu Content-Type: text/x-diff; name="v23-0003-Add-new-deptype-option-m-in-pg_depend-system-cat.patch" Content-Disposition: attachment; filename="v23-0003-Add-new-deptype-option-m-in-pg_depend-system-cat.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v27 2/9] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 9b512ccd3c..a9a314fefe 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -920,6 +920,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index fd389c28d8..4d1c99a8bd 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -982,6 +982,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 1b7e11b93e..3275963886 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2023,6 +2023,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 43f14c233d..a67ba4d8b1 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1923,6 +1923,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 304e8c18d5..fbaa1438d6 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index b8dd27d4a9..cc2f635122 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index eadbd00904..0e28716e6b 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -661,6 +661,8 @@ RelationGetSmgr(Relation rel) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.17.1 --Multipart=_Fri__22_Apr_2022_11_29_39_+0900_ZOAC7UMt5e8j1Nvx Content-Type: text/x-diff; name="v27-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v27-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v31 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index cc31909012..1d2e2228c4 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -937,6 +937,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index b6a7c60e23..906ec6c088 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1007,6 +1007,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 401fb35947..16c3399975 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 26368ffcc9..01af4ad5bb 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2020,6 +2020,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 1f419c2a6d..71c0fd506c 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1932,6 +1932,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 0fc2c093b0..80cbee29ca 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 35a8dec2b9..93c2fcb21c 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index f25f769af2..d3144c949f 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -678,6 +678,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index f53c3036a6..c6e878c3ab 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1392,6 +1392,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.25.1 --Multipart=_Fri__29_Mar_2024_23_47_00_+0900_KGpmmDOIs1266Ib1 Content-Type: text/x-diff; name="v31-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v31-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v28 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 2a0d82aedd..37a7759753 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -924,6 +924,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 352e43d0e6..f715cf31ac 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -994,6 +994,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 60978f9415..c3bf9aeac6 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2024,6 +2024,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 8a08463c2b..1ba5c3c883 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1924,6 +1924,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 2d1bb7af3a..62b9c0e5cb 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 4f5418b972..078cdf963b 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 1426a353cd..b8961176bb 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -677,6 +677,8 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.25.1 --Multipart=_Thu__1_Jun_2023_23_59_09_+0900_/G5+8nG46.f1T42K Content-Type: text/x-diff; name="v28-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v28-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v29 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ src/test/regress/expected/rules.out | 1 + 9 files changed, 36 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index b534da7d80..d9eac41463 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -924,6 +924,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index fd09378848..e4b52fdd21 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -993,6 +993,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 77b06e2a7a..2b60ed9e52 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index fc6d267e44..2b29ab4409 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2046,6 +2046,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 7234cb3da6..96cd510780 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1924,6 +1924,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 2d1bb7af3a..62b9c0e5cb 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index f5fdbfe116..7b433749f5 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -138,6 +138,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 1426a353cd..b8961176bb 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -677,6 +677,8 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 5058be5411..cc5287344d 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1392,6 +1392,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.25.1 --Multipart=_Mon__28_Aug_2023_16_05_30_+0900_b1OvQD_3A3ZMTGvj Content-Type: text/x-diff; name="v29-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Disposition: attachment; filename="v29-0003-Allow-to-prolong-life-span-of-transition-tables-.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v24 02/15] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) If this boolean column is true, a relations is Incrementally Maintainable Materialized View (IMMV). This is set when IMMV is created. --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 2 ++ 7 files changed, 34 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 83746d3fd9..ade3586779 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -963,6 +963,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 26bfa74ce7..763f442a1d 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -961,6 +961,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodObjectId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 4ebaa552a2..c626df32cc 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2013,6 +2013,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 13d9994af3..5b130f0ed2 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1865,6 +1865,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index fef9945ed8..2058978b89 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 77871aaefc..09346aaa17 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -137,6 +137,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_transform_fromsql(Oid typid, Oid langid, List *trftypes); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index b4faa1c123..b5028f3449 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -649,6 +649,8 @@ RelationGetSmgr(Relation rel) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via -- 2.17.1 --Multipart=_Thu__23_Sep_2021_04_57_30_+0900_b5pmgR1N8oMaMz.U Content-Type: text/x-diff; name="v24-0003-Add-new-deptype-option-m-in-pg_depend-system-cat.patch" Content-Disposition: attachment; filename="v24-0003-Add-new-deptype-option-m-in-pg_depend-system-cat.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v34 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 00074c8a94..8d5470c8f7 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -938,6 +938,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index a819b4197c..eb81685f6b 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1007,6 +1007,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 19cabc9a47..c88c8af96b 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -146,6 +146,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 48a280d089..59c06b853c 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2042,6 +2042,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 66ed24e401..cba2eac1e8 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1931,6 +1931,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index 0fc2c093b0..80cbee29ca 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -119,6 +119,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 20446f6f83..6b17921d23 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -139,6 +139,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index 8700204953..7f36d6f5fa 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -676,6 +676,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index 4c789279e5..c7ba7be647 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1393,6 +1393,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.34.1 --Multipart=_Thu__11_Jul_2024_13_23_57_+0900_hKsU2G3a3BgS2FFs Content-Type: text/x-diff; name="v34-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v34-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v39 2/8] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 6c1c5545cb5..c132472dfbb 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index e266f501d87..9d136c89dd1 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__3_Jul_2026_19_11_16_+0900_CskxSIu_iGcDMEyM Content-Type: text/x-diff; name="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v39-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v38 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 8f129baec90..7f0112f9d61 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036de5f79ef..33e6b0027b4 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2348,6 +2348,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index fb4e042be8a..6a208401ef0 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1945,6 +1945,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 865980cb0f1..de456145b31 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -148,6 +148,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Wed__1_Jul_2026_00_04_01_+0900_OVSy2WWK_9aByzDJ Content-Type: text/x-diff; name="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v38-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v37 02/11] Add relisivm column to pg_class system catalog @ 2019-12-20 01:07 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:07 UTC (permalink / raw) 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 --- src/backend/catalog/heap.c | 1 + src/backend/catalog/index.c | 1 + src/backend/catalog/system_views.sql | 1 + src/backend/utils/cache/lsyscache.c | 24 ++++++++++++++++++++++++ src/backend/utils/cache/relcache.c | 2 ++ src/include/catalog/pg_class.h | 3 +++ src/include/utils/lsyscache.h | 1 + src/include/utils/rel.h | 6 ++++++ src/test/regress/expected/rules.out | 1 + 9 files changed, 40 insertions(+) diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c index 88087654de9..d7eca35d080 100644 --- a/src/backend/catalog/heap.c +++ b/src/backend/catalog/heap.c @@ -971,6 +971,7 @@ InsertPgClassTuple(Relation pg_class_desc, values[Anum_pg_class_relrewrite - 1] = ObjectIdGetDatum(rd_rel->relrewrite); values[Anum_pg_class_relfrozenxid - 1] = TransactionIdGetDatum(rd_rel->relfrozenxid); values[Anum_pg_class_relminmxid - 1] = MultiXactIdGetDatum(rd_rel->relminmxid); + values[Anum_pg_class_relisivm - 1] = BoolGetDatum(rd_rel->relisivm); if (relacl != (Datum) 0) values[Anum_pg_class_relacl - 1] = relacl; else diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 9407c357f27..7ba874417c5 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -1014,6 +1014,7 @@ index_create(Relation heapRelation, indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner; indexRelation->rd_rel->relam = accessMethodId; indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid); + indexRelation->rd_rel->relisivm = false; /* * store index's pg_class entry diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 73a1c1c4670..4db2cafdb6a 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -151,6 +151,7 @@ CREATE VIEW pg_matviews AS T.spcname AS tablespace, C.relhasindex AS hasindexes, C.relispopulated AS ispopulated, + C.relisivm AS isimmv, pg_get_viewdef(C.oid) AS definition FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace) LEFT JOIN pg_tablespace T ON (T.oid = C.reltablespace) diff --git a/src/backend/utils/cache/lsyscache.c b/src/backend/utils/cache/lsyscache.c index 036086057d7..0ab1604ec42 100644 --- a/src/backend/utils/cache/lsyscache.c +++ b/src/backend/utils/cache/lsyscache.c @@ -2273,6 +2273,30 @@ get_rel_relispartition(Oid relid) return false; } +/* + * get_rel_relisivm + * + * Returns the relisivm flag associated with a given relation. + */ +bool +get_rel_relisivm(Oid relid) +{ + HeapTuple tp; + + tp = SearchSysCache1(RELOID, ObjectIdGetDatum(relid)); + if (HeapTupleIsValid(tp)) + { + Form_pg_class reltup = (Form_pg_class) GETSTRUCT(tp); + bool result; + + result = reltup->relisivm; + ReleaseSysCache(tp); + return result; + } + else + return false; +} + /* * get_rel_tablespace * diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index 0572ab424e7..6b56d95a892 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -1943,6 +1943,8 @@ formrdesc(const char *relationName, Oid relationReltype, /* ... and they're always populated, too */ relation->rd_rel->relispopulated = true; + /* ... and they're always no ivm, too */ + relation->rd_rel->relisivm = false; relation->rd_rel->relreplident = REPLICA_IDENTITY_NOTHING; relation->rd_rel->relpages = 0; diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h index c4af599dc90..ed5cfa20587 100644 --- a/src/include/catalog/pg_class.h +++ b/src/include/catalog/pg_class.h @@ -124,6 +124,9 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat /* is relation a partition? */ bool relispartition BKI_DEFAULT(f); + /* is relation a matview with ivm? */ + bool relisivm BKI_DEFAULT(f); + /* link to original rel during table rewrite; otherwise 0 */ Oid relrewrite BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_class); diff --git a/src/include/utils/lsyscache.h b/src/include/utils/lsyscache.h index 8545e67a632..f7b45f6a89d 100644 --- a/src/include/utils/lsyscache.h +++ b/src/include/utils/lsyscache.h @@ -146,6 +146,7 @@ extern Oid get_rel_namespace(Oid relid); extern Oid get_rel_type_id(Oid relid); extern char get_rel_relkind(Oid relid); extern bool get_rel_relispartition(Oid relid); +extern bool get_rel_relisivm(Oid relid); extern Oid get_rel_tablespace(Oid relid); extern char get_rel_persistence(Oid relid); extern Oid get_rel_relam(Oid relid); diff --git a/src/include/utils/rel.h b/src/include/utils/rel.h index fa07ebf8ff7..fce5bbc1882 100644 --- a/src/include/utils/rel.h +++ b/src/include/utils/rel.h @@ -696,6 +696,12 @@ RelationCloseSmgr(Relation relation) */ #define RelationIsPopulated(relation) ((relation)->rd_rel->relispopulated) +/* + * RelationIsIVM + * True if relation is an incrementally maintainable materialized view. + */ +#define RelationIsIVM(relation) ((relation)->rd_rel->relisivm) + /* * RelationIsAccessibleInLogicalDecoding * True if we need to log enough information to have access via diff --git a/src/test/regress/expected/rules.out b/src/test/regress/expected/rules.out index a65a5bf0c4f..c5febf6a3d6 100644 --- a/src/test/regress/expected/rules.out +++ b/src/test/regress/expected/rules.out @@ -1415,6 +1415,7 @@ pg_matviews| SELECT n.nspname AS schemaname, t.spcname AS tablespace, c.relhasindex AS hasindexes, c.relispopulated AS ispopulated, + c.relisivm AS isimmv, pg_get_viewdef(c.oid) AS definition FROM ((pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) -- 2.43.0 --Multipart=_Fri__29_May_2026_23_14_17_+0900_Te0o73X2VqYK57Gd Content-Type: text/x-diff; name="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Disposition: attachment; filename="v37-0001-Add-a-syntax-to-create-Incrementally-Maintainabl.patch" Content-Transfer-Encoding: 7bit ^ permalink raw reply [nested|flat] 72+ messages in thread
* [PATCH v28 11/11] Add documentations about Incremental View Maintenance @ 2019-12-20 01:25 Yugo Nagata <[email protected]> 0 siblings, 0 replies; 72+ messages in thread From: Yugo Nagata @ 2019-12-20 01:25 UTC (permalink / raw) --- doc/src/sgml/catalogs.sgml | 9 + .../sgml/ref/create_materialized_view.sgml | 131 +++++- .../sgml/ref/refresh_materialized_view.sgml | 8 +- doc/src/sgml/rules.sgml | 443 ++++++++++++++++++ 4 files changed, 587 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml index ed32ca0349..51378358a1 100644 --- a/doc/src/sgml/catalogs.sgml +++ b/doc/src/sgml/catalogs.sgml @@ -2223,6 +2223,15 @@ SCRAM-SHA-256$<replaceable><iteration count></replaceable>:<replaceable>&l </para></entry> </row> + <row> + <entry role="catalog_table_entry"><para role="column_definition"> + <structfield>relisivm</structfield> <type>bool</type> + </para> + <para> + True if materialized view enables incremental view maintenance + </para></entry> + </row> + <row> <entry role="catalog_table_entry"><para role="column_definition"> <structfield>relrewrite</structfield> <type>oid</type> diff --git a/doc/src/sgml/ref/create_materialized_view.sgml b/doc/src/sgml/ref/create_materialized_view.sgml index 0d2fea2b97..52a4d206b1 100644 --- a/doc/src/sgml/ref/create_materialized_view.sgml +++ b/doc/src/sgml/ref/create_materialized_view.sgml @@ -21,7 +21,7 @@ PostgreSQL documentation <refsynopsisdiv> <synopsis> -CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] <replaceable>table_name</replaceable> +CREATE [ INCREMENTAL ] MATERIALIZED VIEW [ IF NOT EXISTS ] <replaceable>table_name</replaceable> [ (<replaceable>column_name</replaceable> [, ...] ) ] [ USING <replaceable class="parameter">method</replaceable> ] [ WITH ( <replaceable class="parameter">storage_parameter</replaceable> [= <replaceable class="parameter">value</replaceable>] [, ... ] ) ] @@ -60,6 +60,132 @@ CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] <replaceable>table_name</replaceable> <title>Parameters</title> <variablelist> + <varlistentry> + <term><literal>INCREMENTAL</literal></term> + <listitem> + <para> + If specified, some triggers are automatically created so that the rows + of the materialized view are immediately updated when base tables of the + materialized view are updated. In general, this allows faster update of + the materialized view at a price of slower update of the base tables + because the triggers will be invoked. We call this form of materialized + view as "Incrementally Maintainable Materialized View" (IMMV). + </para> + <para> + When <acronym>IMMV</acronym> is defined without using <command>WITH NO DATA</command>, + a unique index is created on the view automatically if possible. If the view + definition query has a GROUP BY clause, a unique index is created on the columns + of GROUP BY expressions. Also, if the view has DISTINCT clause, a unique index + is created on all columns in the target list. Otherwise, if the view contains all + primary key attritubes of its base tables in the target list, a unique index is + created on these attritubes. In other cases, no index is created. + </para> + <para> + There are restrictions of query definitions allowed to use this + option. The following are supported in query definitions for IMMV: + <itemizedlist> + + <listitem> + <para> + Inner joins (including self-joins). + </para> + </listitem> + + <listitem> + <para> + Some built-in aggregate functions (count, sum, avg, min, max) without a HAVING + clause. + </para> + </listitem> + </itemizedlist> + + Unsupported queries with this option include the following: + + <itemizedlist> + <listitem> + <para> + Outer joins. + </para> + </listitem> + + <listitem> + <para> + Sub-queries. + </para> + </listitem> + + <listitem> + <para> + Aggregate functions other than built-in count, sum, avg, min and max. + </para> + </listitem> + <listitem> + <para> + Aggregate functions with a HAVING clause. + </para> + </listitem> + <listitem> + <para> + DISTINCT ON, WINDOW, VALUES, LIMIT and OFFSET clause. + </para> + </listitem> + </itemizedlist> + + Other restrictions include: + <itemizedlist> + + <listitem> + <para> + IMMVs must be based on simple base tables. It's not supported to + create them on top of views or materialized views. + </para> + </listitem> + + <listitem> + <para> + When the TRUNCATE command is executed on a base table, + no changes are made to the materialized view. + </para> + </listitem> + + <listitem> + <para> + It is not supported to include system columns in an IMMV. + <programlisting> +CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm02 AS SELECT i,j FROM mv_base_a WHERE xmin = '610'; +ERROR: system column is not supported with IVM + </programlisting> + </para> + </listitem> + + <listitem> + <para> + Non-immutable functions are not supported. + <programlisting> +CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm12 AS SELECT i,j FROM mv_base_a WHERE i = random()::int; +ERROR: functions in IMMV must be marked IMMUTABLE + </programlisting> + </para> + </listitem> + + <listitem> + <para> + IMMVs do not support expressions that contains aggregates + </para> + </listitem> + + <listitem> + <para> + Logical replication does not support IMMVs. + </para> + </listitem> + + </itemizedlist> + + </para> + </listitem> + </varlistentry> + <varlistentry> <term><literal>IF NOT EXISTS</literal></term> <listitem> @@ -155,7 +281,8 @@ CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] <replaceable>table_name</replaceable> This clause specifies whether or not the materialized view should be populated at creation time. If not, the materialized view will be flagged as unscannable and cannot be queried until <command>REFRESH - MATERIALIZED VIEW</command> is used. + MATERIALIZED VIEW</command> is used. Also, if the view is IMMV, + triggers for maintaining the view are not created. </para> </listitem> </varlistentry> diff --git a/doc/src/sgml/ref/refresh_materialized_view.sgml b/doc/src/sgml/ref/refresh_materialized_view.sgml index 4d79b6ae7f..4e27e29e35 100644 --- a/doc/src/sgml/ref/refresh_materialized_view.sgml +++ b/doc/src/sgml/ref/refresh_materialized_view.sgml @@ -38,9 +38,13 @@ REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] <replaceable class="parameter">name</ privilege on the materialized view. The old contents are discarded. If <literal>WITH DATA</literal> is specified (or defaults) the backing query is executed to provide the new data, and the materialized view is left in a - scannable state. If <literal>WITH NO DATA</literal> is specified no new + scannable state. If the view is an incrementally maintainable materialized + view (IMMV) and was unpopulated, triggers for maintaining the view are + created. Also, a unique index is created for IMMV if it is possible and the + view doesn't have that yet. + If <literal>WITH NO DATA</literal> is specified no new data is generated and the materialized view is left in an unscannable - state. + state. If the view is IMMV, the triggers are dropped. </para> <para> <literal>CONCURRENTLY</literal> and <literal>WITH NO DATA</literal> may not diff --git a/doc/src/sgml/rules.sgml b/doc/src/sgml/rules.sgml index d229b94d39..d000beacdf 100644 --- a/doc/src/sgml/rules.sgml +++ b/doc/src/sgml/rules.sgml @@ -1096,6 +1096,449 @@ SELECT word FROM words ORDER BY word <-> 'caterpiler' LIMIT 10; </sect1> +<sect1 id="rules-ivm"> +<title>Incremental View Maintenance</title> + +<indexterm zone="rules-ivm"> + <primary>incremental view maintenance</primary> +</indexterm> + +<indexterm zone="rules-ivm"> + <primary>materialized view</primary> + <secondary>incremental view maintenance</secondary> +</indexterm> + +<indexterm zone="rules-ivm"> + <primary>view</primary> + <secondary>incremental view maintenance</secondary> +</indexterm> + +<sect2 id="rules-ivm-overview"> +<title>Overview</title> + +<para> + Incremental View Maintenance (<acronym>IVM</acronym>) is a way to make + materialized views up-to-date in which only incremental changes are computed + and applied on views rather than recomputing the contents from scratch as + <command>REFRESH MATERIALIZED VIEW</command> does. <acronym>IVM</acronym> + can update materialized views more efficiently than recomputation when only + small parts of the view are changed. +</para> + +<para> + There are two approaches with regard to timing of view maintenance: + immediate and deferred. In immediate maintenance, views are updated in the + same transaction that its base table is modified. In deferred maintenance, + views are updated after the transaction is committed, for example, when the + view is accessed, as a response to user command like <command>REFRESH + MATERIALIZED VIEW</command>, or periodically in background, and so on. + <productname>PostgreSQL</productname> currently implements only a kind of + immediate maintenance, in which materialized views are updated immediately + in AFTER triggers when a base table is modified. +</para> + +<para> + To create materialized views supporting <acronym>IVM</acronym>, use the + <command>CREATE INCREMENTAL MATERIALIZED VIEW</command>, for example: +<programlisting> +CREATE <emphasis>INCREMENTAL</emphasis> MATERIALIZED VIEW mymatview AS SELECT * FROM mytab; +</programlisting> + When a materialized view is created with the <literal>INCREMENTAL</literal> + keyword, some triggers are automatically created so that the view's contents are + immediately updated when its base tables are modified. We call this form + of materialized view an Incrementally Maintainable Materialized View + (<acronym>IMMV</acronym>). +<programlisting> +postgres=# CREATE INCREMENTAL MATERIALIZED VIEW m AS SELECT * FROM t0; +NOTICE: could not create an index on materialized view "m" automatically +HINT: Create an index on the materialized view for effcient incremental maintenance. +SELECT 3 +postgres=# SELECT * FROM m; + i +--- + 1 + 2 + 3 +(3 rows) + +postgres=# INSERT INTO t0 VALUES (4); +INSERT 0 1 +postgres=# SELECT * FROM m; -- automatically updated + i +--- + 1 + 2 + 3 + 4 +(4 rows) +</programlisting> +</para> + +<para> + Some <acronym>IMMV</acronym>s have hidden columns which are added + automatically when a materialized view is created. Their name starts + with <literal>__ivm_</literal> and they contain information required + for maintaining the <acronym>IMMV</acronym>. Such columns are not visible + when the <acronym>IMMV</acronym> is accessed by <literal>SELECT *</literal> + but are visible if the column name is explicitly specified in the target + list. We can also see the hidden columns in <literal>\d</literal> + meta-commands of <command>psql</command> commands. +</para> + +<para> + In general, <acronym>IMMV</acronym>s allow faster updates of materialized + views at the price of slower updates to their base tables. Updates of + <acronym>IMMV</acronym> is slower because triggers will be invoked and the + view is updated in triggers per modification statement. +</para> + +<para> + For example, suppose a normal materialized view defined as below: + +<programlisting> +test=# CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm AS + SELECT a.aid, b.bid, a.abalance, b.bbalance + FROM pgbench_accounts a JOIN pgbench_branches b USING(bid); +SELECT 10000000 + +</programlisting> + + Updating a tuple in a base table of this materialized view is rapid but the + <command>REFRESH MATERIALIZED VIEW</command> command on this view takes a long time: + +<programlisting> +test=# UPDATE pgbench_accounts SET abalance = 1000 WHERE aid = 1; +UPDATE 1 +Time: 0.990 ms + +test=# REFRESH MATERIALIZED VIEW mv_normal ; +REFRESH MATERIALIZED VIEW +Time: 33533.952 ms (00:33.534) +</programlisting> +</para> + +<para> + On the other hand, after creating <acronym>IMMV</acronym> with the same view + definition as below: + +<programlisting> +test=# CREATE INCREMENTAL MATERIALIZED VIEW mv_ivm AS + SELECT a.aid, b.bid, a.abalance, b.bbalance + FROM pgbench_accounts a JOIN pgbench_branches b USING(bid); +test=# UPDATE pgbench_accounts SET abalance = 1000 WHERE aid = 1; +NOTICE: created index "mv_ivm_index" on materialized view "mv_ivm" +</programlisting> + + updating a tuple in a base table takes more than the normal view, + but its content is updated automatically and this is faster than the + <command>REFRESH MATERIALIZED VIEW</command> command. + +<programlisting> +test=# UPDATE pgbench_accounts SET abalance = 1000 WHERE aid = 1; +UPDATE 1 +Time: 13.068 ms +</programlisting> + +</para> + +<para> + Appropriate indexes on <acronym>IMMV</acronym>s are necessary for + efficient <acronym>IVM</acronym> because it looks for tuples to be + updated in <acronym>IMMV</acronym>. If there are no indexes, it + will take a long time. +</para> + +<para> + Therefore, when <acronym>IMMV</acronym> is defined, a unique index is created on the view + automatically if possible. If the view definition query has a GROUP BY clause, a unique + index is created on the columns of GROUP BY expressions. Also, if the view has DISTINCT + clause, a unique index is created on all columns in the target list. Otherwise, if the + view contains all primary key attritubes of its base tables in the target list, a unique + index is created on these attritubes. In other cases, no index is created. +</para> + +<para> + In the previous example, a unique index "mv_ivm_index" is created on aid and bid + columns of materialized view "mv_ivm", and this enables the rapid update of the view. + Dropping this index make updating the view take a loger time. +<programlisting> +test=# DROP INDEX mv_ivm_index; +DROP INDEX +Time: 67.081 ms + +test=# UPDATE pgbench_accounts SET abalance = 1000 WHERE aid = 1; +UPDATE 1 +Time: 16386.245 ms (00:16.386) +</programlisting> + +</para> + +<para> + <acronym>IVM</acronym> is effective when we want to keep a materialized + view up-to-date and small fraction of a base table is modified + infrequently. Due to the overhead of immediate maintenance, <acronym>IVM</acronym> + is not effective when a base table is modified frequently. Also, when a + large part of a base table is modified or large data is inserted into a + base table, <acronym>IVM</acronym> is not effective and the cost of + maintenance can be larger than the <command>REFRESH MATERIALIZED VIEW</command> + command. In such situation, we can use <command>REFRESH MATERIALIZED VIEW</command> + and specify <literal>WITH NO DATA</literal> to disable immediate + maintenance before modifying a base table. After a base table modification, + execute the <command>REFRESH MATERIALIZED VIEW</command> (with <literal>WITH DATA</literal>) + command to refresh the view data and enable immediate maintenance. +</para> + +</sect2> + +<sect2> +<title>Supported View Definitions and Restrictions</title> + +<para> + Currently, we can create <acronym>IMMV</acronym>s using inner joins, and some + aggregates. However, several restrictions apply to the definition of IMMV. +</para> + +<sect3> +<title>Joins</title> +<para> + Inner joins including self-join are supported. Outer joins are not supported. +</para> +</sect3> + +<sect3> +<title>Aggregates</title> +<para> + Supported aggregate functions are <function>count</function>, <function>sum</function>, + <function>avg</function>, <function>min</function>, and <function>max</function>. + Currently, only built-in aggregate functions are supported and user defined + aggregates cannot be used. When a base table is modified, the new aggregated + values are incrementally calculated using the old aggregated values and values + of related hidden columns stored in <acronym>IMMV</acronym>. +</para> + +<para> + Note that for <function>min</function> or <function>max</function>, the new values + could be re-calculated from base tables with regard to the affected groups when a + tuple containing the current minimal or maximal values are deleted from a base table. + Therefore, it can takes a long time to update an <acronym>IMMV</acronym> containing + these functions. +</para> + +<para> + Also note that using <function>sum</function> or <function>avg</function> on + <type>real</type> (<type>float4</type>) type or <type>double precision</type> + (<type>float8</type>) type in <acronym>IMMV</acronym> is unsafe. This is + because aggregated values in <acronym>IMMV</acronym> can become different from + results calculated from base tables due to the limited precision of these types. + To avoid this problem, use the <type>numeric</type> type instead. +</para> + + <sect4> + <title>Restrictions on Aggregates</title> + <para> + There are the following restrictions: + <itemizedlist> + <listitem> + <para> + If we have a <literal>GROUP BY</literal> clause, expressions specified in + <literal>GROUP BY</literal> must appear in the target list. This is + how tuples to be updated in the <acronym>IMMV</acronym> are identified. + These attributes are used as scan keys for searching tuples in the + <acronym>IMMV</acronym>, so indexes on them are required for efficient + <acronym>IVM</acronym>. + </para> + </listitem> + + <listitem> + <para> + <literal>HAVING</literal> clause cannot be used. + </para> + </listitem> + </itemizedlist> + </para> + </sect4> +</sect3> + +<sect3> +<title>Other General Restrictions</title> +<para> + There are other restrictions which generally apply to <acronym>IMMV</acronym>: + <itemizedlist> + <listitem> + <para> + Sub-queries cannot be used. + </para> + </listitem> + + <listitem> + <para> + CTEs cannot be used. + </para> + </listitem> + + <listitem> + <para> + Window functions cannot be used. + </para> + </listitem> + + <listitem> + <para> + <acronym>IMMV</acronym>s must be based on simple base tables. It's not + supported to create them on top of views, materialized views, foreign tables, inhe. + </para> + </listitem> + + <listitem> + <para> + LIMIT and OFFSET clauses cannot be used. + </para> + </listitem> + + <listitem> + <para> + <acronym>IMMV</acronym>s cannot contain system columns. + </para> + </listitem> + + <listitem> + <para> + <acronym>IMMV</acronym>s cannot contain non-immutable functions. + </para> + </listitem> + + <listitem> + <para> + UNION/INTERSECT/EXCEPT clauses cannnot be used. + </para> + </listitem> + + <listitem> + <para> + DISTINCT ON clauses cannot be used. + </para> + </listitem> + + <listitem> + <para> + TABLESAMPLE parameter cannot be used. + </para> + </listitem> + + <listitem> + <para> + inheritance parent tables cannnot be used. + </para> + </listitem> + + <listitem> + <para> + VALUES clause cannnot be used. + </para> + </listitem> + + <listitem> + <para> + <literal>GROUPING SETS</literal> and <literal>FILTER</literal> clauses cannot be used. + </para> + </listitem> + + <listitem> + <para> + FOR UPDATE/SHARE cannot be used. + </para> + </listitem> + + <listitem> + <para> + targetlist cannot contain columns whose name start with <literal>__ivm_</literal>. + </para> + </listitem> + + <listitem> + <para> + targetlist cannot contain expressions which contain an aggregate in it. + </para> + </listitem> + + <listitem> + <para> + Logical replication is not supported, that is, even when a base table + at a publisher node is modified, <acronym>IMMV</acronym>s at subscriber + nodes are not updated. + </para> + </listitem> + + <listitem> + <para> + When the <literal>TRUNCATE</literal> command is executed on a base table, + nothing is changed on the <acronym>IMMV</acronym>. + </para> + </listitem> + + </itemizedlist> +</para> +</sect3> + +</sect2> + +<sect2> +<title><literal>DISTINCT</literal></title> + +<para> + <productname>PostgreSQL</productname> supports <acronym>IMMV</acronym> with + <literal>DISTINCT</literal>. For example, suppose a <acronym>IMMV</acronym> + defined with <literal>DISTINCT</literal> on a base table containing duplicate + tuples. When tuples are deleted from the base table, a tuple in the view is + deleted if and only if the multiplicity of the tuple becomes zero. Moreover, + when tuples are inserted into the base table, a tuple is inserted into the + view only if the same tuple doesn't already exist in it. +</para> + +<para> + Physically, an <acronym>IMMV</acronym> defined with <literal>DISTINCT</literal> + contains tuples after eliminating duplicates, and the multiplicity of each tuple + is stored in a hidden column named <literal>__ivm_count__</literal>. +</para> +</sect2> + +<sect2> +<title>Concurrent Transactions</title> +<para> + Suppose an <acronym>IMMV</acronym> is defined on two base tables and each + table was modified in different a concurrent transaction simultaneously. + In the transaction which was committed first, <acronym>IMMV</acronym> can + be updated considering only the change which happened in this transaction. + On the other hand, in order to update the view correctly in the transaction + which was committed later, we need to know the changes occurred in + both transactions. For this reason, <literal>ExclusiveLock</literal> + is held on an <acronym>IMMV</acronym> immediately after a base table is + modified in <literal>READ COMMITTED</literal> mode to make sure that + the <acronym>IMMV</acronym> is updated in the latter transaction after + the former transaction is committed. In <literal>REPEATABLE READ</literal> + or <literal>SERIALIZABLE</literal> mode, an error is raised immediately + if lock acquisition fails because any changes which occurred in + other transactions are not be visible in these modes and + <acronym>IMMV</acronym> cannot be updated correctly in such situations. + However, as an exception if the view has only one base table, + the lock held on thew view is <literal>RowExclusiveLock</literal>. +</para> +</sect2> + +<sect2> +<title>Row Level Security</title> +<para> + If some base tables have row level security policy, rows that are not visible + to the materialized view's owner are excluded from the result. In addition, such + rows are excluded as well when views are incrementally maintained. However, if a + new policy is defined or policies are changed after the materialized view was created, + the new policy will not be applied to the view contents. To apply the new policy, + you need to refresh materialized views. +</para> +</sect2> + +</sect1> + <sect1 id="rules-update"> <title>Rules on <command>INSERT</command>, <command>UPDATE</command>, and <command>DELETE</command></title> -- 2.25.1 --Multipart=_Thu__1_Jun_2023_23_59_09_+0900_/G5+8nG46.f1T42K-- ^ permalink raw reply [nested|flat] 72+ messages in thread
end of thread, other threads:[~2019-12-20 01:25 UTC | newest] Thread overview: 72+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v24 02/15] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v33 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v26 02/10] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v27 2/9] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v25 02/15] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v32 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v29 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v30 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v23 02/15] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v27 2/9] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v31 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v28 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v29 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v24 02/15] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v34 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v39 2/8] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v38 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:07 [PATCH v37 02/11] Add relisivm column to pg_class system catalog Yugo Nagata <[email protected]> 2019-12-20 01:25 [PATCH v28 11/11] Add documentations about Incremental View Maintenance Yugo Nagata <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox