Skip to content

Commit 1b53f92

Browse files
yugo-nCommitfest Bot
authored and
Commitfest Bot
committed
Add a syntax to create Incrementally Maintainable Materialized Views
Allow to create Incrementally Maintainable Materialized View (IMMV) by using INCREMENTAL option in CREATE MATERIALIZED VIEW command as follow: CREATE [INCREMANTAL] MATERIALIZED VIEW xxxxx AS SELECT ....;
1 parent 0a8ca12 commit 1b53f92

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/backend/parser/gram.y

+21-11
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
468468

469469
%type <range> OptTempTableName
470470
%type <into> into_clause create_as_target create_mv_target
471+
%type <boolean> incremental
471472

472473
%type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
473474
%type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
@@ -738,7 +739,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
738739
HANDLER HAVING HEADER_P HOLD HOUR_P
739740

740741
IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
741-
INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
742+
INCLUDING INCREMENT INCREMENTAL INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
742743
INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
743744
INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
744745

@@ -4803,32 +4804,34 @@ opt_with_data:
48034804
*****************************************************************************/
48044805

48054806
CreateMatViewStmt:
4806-
CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
4807+
CREATE OptNoLog incremental MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
48074808
{
48084809
CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
48094810

4810-
ctas->query = $7;
4811-
ctas->into = $5;
4811+
ctas->query = $8;
4812+
ctas->into = $6;
48124813
ctas->objtype = OBJECT_MATVIEW;
48134814
ctas->is_select_into = false;
48144815
ctas->if_not_exists = false;
48154816
/* cram additional flags into the IntoClause */
4816-
$5->rel->relpersistence = $2;
4817-
$5->skipData = !($8);
4817+
$6->rel->relpersistence = $2;
4818+
$6->skipData = !($9);
4819+
$6->ivm = $3;
48184820
$$ = (Node *) ctas;
48194821
}
4820-
| CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
4822+
| CREATE OptNoLog incremental MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
48214823
{
48224824
CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
48234825

4824-
ctas->query = $10;
4825-
ctas->into = $8;
4826+
ctas->query = $11;
4827+
ctas->into = $9;
48264828
ctas->objtype = OBJECT_MATVIEW;
48274829
ctas->is_select_into = false;
48284830
ctas->if_not_exists = true;
48294831
/* cram additional flags into the IntoClause */
4830-
$8->rel->relpersistence = $2;
4831-
$8->skipData = !($11);
4832+
$9->rel->relpersistence = $2;
4833+
$9->skipData = !($12);
4834+
$9->ivm = $3;
48324835
$$ = (Node *) ctas;
48334836
}
48344837
;
@@ -4845,9 +4848,14 @@ create_mv_target:
48454848
$$->tableSpaceName = $5;
48464849
$$->viewQuery = NULL; /* filled at analysis time */
48474850
$$->skipData = false; /* might get changed later */
4851+
$$->ivm = false;
48484852
}
48494853
;
48504854

4855+
incremental: INCREMENTAL { $$ = true; }
4856+
| /*EMPTY*/ { $$ = false; }
4857+
;
4858+
48514859
OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
48524860
| /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
48534861
;
@@ -17686,6 +17694,7 @@ unreserved_keyword:
1768617694
| INCLUDE
1768717695
| INCLUDING
1768817696
| INCREMENT
17697+
| INCREMENTAL
1768917698
| INDENT
1769017699
| INDEX
1769117700
| INDEXES
@@ -18274,6 +18283,7 @@ bare_label_keyword:
1827418283
| INCLUDE
1827518284
| INCLUDING
1827618285
| INCREMENT
18286+
| INCREMENTAL
1827718287
| INDENT
1827818288
| INDEX
1827918289
| INDEXES

src/include/nodes/primnodes.h

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ typedef struct IntoClause
168168
/* materialized view's SELECT query */
169169
Node *viewQuery pg_node_attr(query_jumble_ignore);
170170
bool skipData; /* true for WITH NO DATA */
171+
bool ivm; /* true for WITH IVM */
171172
} IntoClause;
172173

173174

src/include/parser/kwlist.h

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ PG_KEYWORD("in", IN_P, RESERVED_KEYWORD, BARE_LABEL)
210210
PG_KEYWORD("include", INCLUDE, UNRESERVED_KEYWORD, BARE_LABEL)
211211
PG_KEYWORD("including", INCLUDING, UNRESERVED_KEYWORD, BARE_LABEL)
212212
PG_KEYWORD("increment", INCREMENT, UNRESERVED_KEYWORD, BARE_LABEL)
213+
PG_KEYWORD("incremental", INCREMENTAL, UNRESERVED_KEYWORD, BARE_LABEL)
213214
PG_KEYWORD("indent", INDENT, UNRESERVED_KEYWORD, BARE_LABEL)
214215
PG_KEYWORD("index", INDEX, UNRESERVED_KEYWORD, BARE_LABEL)
215216
PG_KEYWORD("indexes", INDEXES, UNRESERVED_KEYWORD, BARE_LABEL)

0 commit comments

Comments
 (0)