aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt
diff options
context:
space:
mode:
authorKevin Grittner <kgrittn@postgresql.org>2013-03-03 18:23:31 -0600
committerKevin Grittner <kgrittn@postgresql.org>2013-03-03 18:23:31 -0600
commit3bf3ab8c563699138be02f9dc305b7b77a724307 (patch)
treea36ddfded0bea88ee863595f58f62661cc61948b /src/backend/utils/adt
parentb15a6da29217b14f02895af1d9271e84415a91ae (diff)
downloadpostgresql-3bf3ab8c563699138be02f9dc305b7b77a724307.tar.gz
postgresql-3bf3ab8c563699138be02f9dc305b7b77a724307.zip
Add a materialized view relations.
A materialized view has a rule just like a view and a heap and other physical properties like a table. The rule is only used to populate the table, references in queries refer to the materialized data. This is a minimal implementation, but should still be useful in many cases. Currently data is only populated "on demand" by the CREATE MATERIALIZED VIEW and REFRESH MATERIALIZED VIEW statements. It is expected that future releases will add incremental updates with various timings, and that a more refined concept of defining what is "fresh" data will be developed. At some point it may even be possible to have queries use a materialized in place of references to underlying tables, but that requires the other above-mentioned features to be working first. Much of the documentation work by Robert Haas. Review by Noah Misch, Thom Brown, Robert Haas, Marko Tiikkaja Security review by KaiGai Kohei, with a decision on how best to implement sepgsql still pending.
Diffstat (limited to 'src/backend/utils/adt')
-rw-r--r--src/backend/utils/adt/dbsize.c24
-rw-r--r--src/backend/utils/adt/xml.c4
2 files changed, 26 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 ");");
}