aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/dbsize.c24
-rw-r--r--src/backend/utils/adt/xml.c4
-rw-r--r--src/backend/utils/cache/relcache.c26
3 files changed, 52 insertions, 2 deletions
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 11b004072f6..d589d26070d 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -719,6 +719,7 @@ pg_relation_filenode(PG_FUNCTION_ARGS)
switch (relform->relkind)
{
case RELKIND_RELATION:
+ case RELKIND_MATVIEW:
case RELKIND_INDEX:
case RELKIND_SEQUENCE:
case RELKIND_TOASTVALUE:
@@ -767,6 +768,7 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
switch (relform->relkind)
{
case RELKIND_RELATION:
+ case RELKIND_MATVIEW:
case RELKIND_INDEX:
case RELKIND_SEQUENCE:
case RELKIND_TOASTVALUE:
@@ -832,3 +834,25 @@ pg_relation_filepath(PG_FUNCTION_ARGS)
PG_RETURN_TEXT_P(cstring_to_text(path));
}
+
+
+/*
+ * Indicate whether a relation is scannable.
+ *
+ * Currently, this is always true except for a materialized view which has not
+ * been populated.
+ */
+Datum
+pg_relation_is_scannable(PG_FUNCTION_ARGS)
+{
+ Oid relid;
+ Relation relation;
+ bool result;
+
+ relid = PG_GETARG_OID(0);
+ relation = RelationIdGetRelation(relid);
+ result = relation->rd_isscannable;
+ RelationClose(relation);
+
+ PG_RETURN_BOOL(result);
+}
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index e101ea63492..d5d48d5c060 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -2285,7 +2285,7 @@ schema_get_xml_visible_tables(Oid nspid)
StringInfoData query;
initStringInfo(&query);
- appendStringInfo(&query, "SELECT oid FROM pg_catalog.pg_class WHERE relnamespace = %u AND relkind IN ('r', 'v') AND pg_catalog.has_table_privilege (oid, 'SELECT') ORDER BY relname;", nspid);
+ appendStringInfo(&query, "SELECT oid FROM pg_catalog.pg_class WHERE relnamespace = %u AND relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (oid, 'SELECT') ORDER BY relname;", nspid);
return query_to_oid_list(query.data);
}
@@ -2311,7 +2311,7 @@ static List *
database_get_xml_visible_tables(void)
{
/* At the moment there is no order required here. */
- return query_to_oid_list("SELECT oid FROM pg_catalog.pg_class WHERE relkind IN ('r', 'v') AND pg_catalog.has_table_privilege (pg_class.oid, 'SELECT') AND relnamespace IN (" XML_VISIBLE_SCHEMAS ");");
+ return query_to_oid_list("SELECT oid FROM pg_catalog.pg_class WHERE relkind IN ('r', 'm', 'v') AND pg_catalog.has_table_privilege (pg_class.oid, 'SELECT') AND relnamespace IN (" XML_VISIBLE_SCHEMAS ");");
}
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index e85c7a98725..ba03dfcbb2d 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -37,6 +37,7 @@
#include "access/transam.h"
#include "access/xact.h"
#include "catalog/catalog.h"
+#include "catalog/heap.h"
#include "catalog/index.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
@@ -399,6 +400,7 @@ RelationParseRelOptions(Relation relation, HeapTuple tuple)
case RELKIND_TOASTVALUE:
case RELKIND_INDEX:
case RELKIND_VIEW:
+ case RELKIND_MATVIEW:
break;
default:
return;
@@ -954,6 +956,12 @@ RelationBuildDesc(Oid targetRelId, bool insertIt)
/* make sure relation is marked as having no open file yet */
relation->rd_smgr = NULL;
+ if (relation->rd_rel->relkind == RELKIND_MATVIEW &&
+ heap_is_matview_init_state(relation))
+ relation->rd_isscannable = false;
+ else
+ relation->rd_isscannable = true;
+
/*
* now we can free the memory allocated for pg_class_tuple
*/
@@ -1523,6 +1531,7 @@ formrdesc(const char *relationName, Oid relationReltype,
* initialize physical addressing information for the relation
*/
RelationInitPhysicalAddr(relation);
+ relation->rd_isscannable = true;
/*
* initialize the rel-has-index flag, using hardwired knowledge
@@ -1747,6 +1756,7 @@ RelationReloadIndexInfo(Relation relation)
heap_freetuple(pg_class_tuple);
/* We must recalculate physical address in case it changed */
RelationInitPhysicalAddr(relation);
+ relation->rd_isscannable = true;
/*
* For a non-system index, there are fields of the pg_index row that are
@@ -1893,6 +1903,11 @@ RelationClearRelation(Relation relation, bool rebuild)
if (relation->rd_isnailed)
{
RelationInitPhysicalAddr(relation);
+ if (relation->rd_rel->relkind == RELKIND_MATVIEW &&
+ heap_is_matview_init_state(relation))
+ relation->rd_isscannable = false;
+ else
+ relation->rd_isscannable = true;
if (relation->rd_rel->relkind == RELKIND_INDEX)
{
@@ -2681,6 +2696,12 @@ RelationBuildLocalRelation(const char *relname,
RelationInitPhysicalAddr(rel);
+ /* materialized view not initially scannable */
+ if (relkind == RELKIND_MATVIEW)
+ rel->rd_isscannable = false;
+ else
+ rel->rd_isscannable = true;
+
/*
* Okay to insert into the relcache hash tables.
*/
@@ -4424,6 +4445,11 @@ load_relcache_init_file(bool shared)
*/
RelationInitLockInfo(rel);
RelationInitPhysicalAddr(rel);
+ if (rel->rd_rel->relkind == RELKIND_MATVIEW &&
+ heap_is_matview_init_state(rel))
+ rel->rd_isscannable = false;
+ else
+ rel->rd_isscannable = true;
}
/*