1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-21 10:42:50 +03:00

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.
This commit is contained in:
Kevin Grittner
2013-03-03 18:23:31 -06:00
parent b15a6da292
commit 3bf3ab8c56
103 changed files with 4238 additions and 436 deletions

View File

@@ -190,6 +190,7 @@ transformTopLevelStmt(ParseState *pstate, Node *parseTree)
ctas->query = parseTree;
ctas->into = stmt->intoClause;
ctas->relkind = OBJECT_TABLE;
ctas->is_select_into = true;
/*
@@ -324,6 +325,11 @@ analyze_requires_snapshot(Node *parseTree)
result = true;
break;
case T_RefreshMatViewStmt:
/* yes, because the SELECT from pg_rewrite must be analyzed */
result = true;
break;
default:
/* other utility statements don't have any real parse analysis */
result = false;
@@ -2117,7 +2123,8 @@ transformExplainStmt(ParseState *pstate, ExplainStmt *stmt)
/*
* transformCreateTableAsStmt -
* transform a CREATE TABLE AS (or SELECT ... INTO) Statement
* transform a CREATE TABLE AS, SELECT ... INTO, or CREATE MATERIALIZED VIEW
* Statement
*
* As with EXPLAIN, transform the contained statement now.
*/
@@ -2126,6 +2133,24 @@ transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
{
Query *result;
/*
* Set relkind in IntoClause based on statement relkind. These are
* different types, because the parser users the ObjectType enumeration
* and the executor uses RELKIND_* defines.
*/
switch (stmt->relkind)
{
case (OBJECT_TABLE):
stmt->into->relkind = RELKIND_RELATION;
break;
case (OBJECT_MATVIEW):
stmt->into->relkind = RELKIND_MATVIEW;
break;
default:
elog(ERROR, "unrecognized object relkind: %d",
(int) stmt->relkind);
}
/* transform contained query */
stmt->query = (Node *) transformStmt(pstate, stmt->query);