mirror of
https://github.com/postgres/postgres.git
synced 2025-08-27 07:42:10 +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:
@@ -37,6 +37,7 @@
|
||||
#include "commands/event_trigger.h"
|
||||
#include "commands/explain.h"
|
||||
#include "commands/extension.h"
|
||||
#include "commands/matview.h"
|
||||
#include "commands/lockcmds.h"
|
||||
#include "commands/portalcmds.h"
|
||||
#include "commands/prepare.h"
|
||||
@@ -202,6 +203,7 @@ check_xact_readonly(Node *parsetree)
|
||||
case T_CreateSeqStmt:
|
||||
case T_CreateStmt:
|
||||
case T_CreateTableAsStmt:
|
||||
case T_RefreshMatViewStmt:
|
||||
case T_CreateTableSpaceStmt:
|
||||
case T_CreateTrigStmt:
|
||||
case T_CompositeTypeStmt:
|
||||
@@ -713,6 +715,7 @@ standard_ProcessUtility(Node *parsetree,
|
||||
case OBJECT_TABLE:
|
||||
case OBJECT_SEQUENCE:
|
||||
case OBJECT_VIEW:
|
||||
case OBJECT_MATVIEW:
|
||||
case OBJECT_FOREIGN_TABLE:
|
||||
RemoveRelations((DropStmt *) parsetree);
|
||||
break;
|
||||
@@ -1164,6 +1167,13 @@ standard_ProcessUtility(Node *parsetree,
|
||||
queryString, params, completionTag));
|
||||
break;
|
||||
|
||||
case T_RefreshMatViewStmt:
|
||||
if (isCompleteQuery)
|
||||
EventTriggerDDLCommandStart(parsetree);
|
||||
ExecRefreshMatView((RefreshMatViewStmt *) parsetree,
|
||||
queryString, params, completionTag);
|
||||
break;
|
||||
|
||||
case T_VariableSetStmt:
|
||||
ExecSetVariableStmt((VariableSetStmt *) parsetree);
|
||||
break;
|
||||
@@ -1290,6 +1300,7 @@ standard_ProcessUtility(Node *parsetree,
|
||||
ReindexIndex(stmt->relation);
|
||||
break;
|
||||
case OBJECT_TABLE:
|
||||
case OBJECT_MATVIEW:
|
||||
ReindexTable(stmt->relation);
|
||||
break;
|
||||
case OBJECT_DATABASE:
|
||||
@@ -1509,9 +1520,10 @@ QueryReturnsTuples(Query *parsetree)
|
||||
* We assume it is invoked only on already-parse-analyzed statements
|
||||
* (else the contained parsetree isn't a Query yet).
|
||||
*
|
||||
* In some cases (currently, only EXPLAIN of CREATE TABLE AS/SELECT INTO),
|
||||
* potentially Query-containing utility statements can be nested. This
|
||||
* function will drill down to a non-utility Query, or return NULL if none.
|
||||
* In some cases (currently, only EXPLAIN of CREATE TABLE AS/SELECT INTO and
|
||||
* CREATE MATERIALIZED VIEW), potentially Query-containing utility statements
|
||||
* can be nested. This function will drill down to a non-utility Query, or
|
||||
* return NULL if none.
|
||||
*/
|
||||
Query *
|
||||
UtilityContainsQuery(Node *parsetree)
|
||||
@@ -1655,6 +1667,9 @@ AlterObjectTypeCommandTag(ObjectType objtype)
|
||||
case OBJECT_VIEW:
|
||||
tag = "ALTER VIEW";
|
||||
break;
|
||||
case OBJECT_MATVIEW:
|
||||
tag = "ALTER MATERIALIZED VIEW";
|
||||
break;
|
||||
default:
|
||||
tag = "???";
|
||||
break;
|
||||
@@ -1852,6 +1867,9 @@ CreateCommandTag(Node *parsetree)
|
||||
case OBJECT_VIEW:
|
||||
tag = "DROP VIEW";
|
||||
break;
|
||||
case OBJECT_MATVIEW:
|
||||
tag = "DROP MATERIALIZED VIEW";
|
||||
break;
|
||||
case OBJECT_INDEX:
|
||||
tag = "DROP INDEX";
|
||||
break;
|
||||
@@ -2113,10 +2131,24 @@ CreateCommandTag(Node *parsetree)
|
||||
break;
|
||||
|
||||
case T_CreateTableAsStmt:
|
||||
if (((CreateTableAsStmt *) parsetree)->is_select_into)
|
||||
tag = "SELECT INTO";
|
||||
else
|
||||
tag = "CREATE TABLE AS";
|
||||
switch (((CreateTableAsStmt *) parsetree)->relkind)
|
||||
{
|
||||
case OBJECT_TABLE:
|
||||
if (((CreateTableAsStmt *) parsetree)->is_select_into)
|
||||
tag = "SELECT INTO";
|
||||
else
|
||||
tag = "CREATE TABLE AS";
|
||||
break;
|
||||
case OBJECT_MATVIEW:
|
||||
tag = "CREATE MATERIALIZED VIEW";
|
||||
break;
|
||||
default:
|
||||
tag = "???";
|
||||
}
|
||||
break;
|
||||
|
||||
case T_RefreshMatViewStmt:
|
||||
tag = "REFRESH MATERIALIZED VIEW";
|
||||
break;
|
||||
|
||||
case T_VariableSetStmt:
|
||||
@@ -2681,6 +2713,10 @@ GetCommandLogLevel(Node *parsetree)
|
||||
lev = LOGSTMT_DDL;
|
||||
break;
|
||||
|
||||
case T_RefreshMatViewStmt:
|
||||
lev = LOGSTMT_DDL;
|
||||
break;
|
||||
|
||||
case T_VariableSetStmt:
|
||||
lev = LOGSTMT_ALL;
|
||||
break;
|
||||
|
Reference in New Issue
Block a user