aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache/relcache.c
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/cache/relcache.c
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/cache/relcache.c')
-rw-r--r--src/backend/utils/cache/relcache.c26
1 files changed, 26 insertions, 0 deletions
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;
}
/*