Skip to content

Commit 01b4486

Browse files
yugo-nyjhjstz
authored andcommitted
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 4235967 commit 01b4486

3 files changed

Lines changed: 24 additions & 12 deletions

File tree

src/backend/parser/gram.y

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ static void check_expressions_in_partition_key(PartitionSpec *spec, core_yyscan_
491491

492492
%type <range> OptTempTableName
493493
%type <into> into_clause create_as_target create_mv_target
494+
%type <boolean> incremental
494495

495496
%type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
496497
%type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
@@ -769,7 +770,7 @@ static void check_expressions_in_partition_key(PartitionSpec *spec, core_yyscan_
769770
HANDLER HAVING HEADER_P HOLD HOUR_P
770771

771772
IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
772-
INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
773+
INCLUDING INCREMENT INCREMENTAL INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
773774
INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
774775
INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
775776

@@ -6839,31 +6840,33 @@ ext_opt_encoding_item:
68396840
*****************************************************************************/
68406841

68416842
CreateMatViewStmt:
6842-
CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data OptDistributedBy
6843+
CREATE OptNoLog incremental MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data OptDistributedBy
68436844
{
68446845
CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
6845-
ctas->query = $7;
6846-
ctas->into = $5;
6846+
ctas->query = $8;
6847+
ctas->into = $6;
68476848
ctas->objtype = OBJECT_MATVIEW;
68486849
ctas->is_select_into = false;
68496850
ctas->if_not_exists = false;
68506851
/* cram additional flags into the IntoClause */
6851-
$5->rel->relpersistence = $2;
6852-
$5->skipData = !($8);
6853-
ctas->into->distributedBy = $9;
6852+
$6->rel->relpersistence = $2;
6853+
$6->skipData = !($9);
6854+
$6->ivm = $3;
6855+
ctas->into->distributedBy = $10;
68546856
$$ = (Node *) ctas;
68556857
}
6856-
| CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
6858+
| CREATE OptNoLog incremental MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
68576859
{
68586860
CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
6859-
ctas->query = $10;
6860-
ctas->into = $8;
6861+
ctas->query = $11;
6862+
ctas->into = $9;
68616863
ctas->objtype = OBJECT_MATVIEW;
68626864
ctas->is_select_into = false;
68636865
ctas->if_not_exists = true;
68646866
/* cram additional flags into the IntoClause */
6865-
$8->rel->relpersistence = $2;
6866-
$8->skipData = !($11);
6867+
$9->rel->relpersistence = $2;
6868+
$9->skipData = !($12);
6869+
$9->ivm = $3;
68676870
$$ = (Node *) ctas;
68686871
}
68696872
;
@@ -6880,11 +6883,16 @@ create_mv_target:
68806883
$$->tableSpaceName = $5;
68816884
$$->viewQuery = NULL; /* filled at analysis time */
68826885
$$->skipData = false; /* might get changed later */
6886+
$$->ivm = false;
68836887

68846888
$$->accessMethod = greenplumLegacyAOoptions($$->accessMethod, &$$->options);
68856889
}
68866890
;
68876891

6892+
incremental: INCREMENTAL { $$ = true; }
6893+
| /*EMPTY*/ { $$ = false; }
6894+
;
6895+
68886896
OptNoLog: UNLOGGED { $$ = RELPERSISTENCE_UNLOGGED; }
68896897
| /*EMPTY*/ { $$ = RELPERSISTENCE_PERMANENT; }
68906898
;
@@ -18794,6 +18802,7 @@ unreserved_keyword:
1879418802
| INCLUDING
1879518803
| INCLUSIVE
1879618804
| INCREMENT
18805+
| INCREMENTAL
1879718806
| INDEX
1879818807
| INDEXES
1879918808
| INHERIT
@@ -19730,6 +19739,7 @@ bare_label_keyword:
1973019739
| INCLUDING
1973119740
| INCLUSIVE
1973219741
| INCREMENT
19742+
| INCREMENTAL
1973319743
| INDEX
1973419744
| INDEXES
1973519745
| INHERIT

src/include/nodes/primnodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ typedef struct IntoClause
122122
Node *viewQuery; /* materialized view's SELECT query */
123123
bool skipData; /* true for WITH NO DATA */
124124
Node *distributedBy; /* GPDB: columns to distribubte the data on. */
125+
bool ivm; /* true for WITH IVM */
125126
} IntoClause;
126127

127128
typedef struct CopyIntoClause

src/include/parser/kwlist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ PG_KEYWORD("include", INCLUDE, UNRESERVED_KEYWORD, BARE_LABEL)
232232
PG_KEYWORD("including", INCLUDING, UNRESERVED_KEYWORD, BARE_LABEL)
233233
PG_KEYWORD("inclusive", INCLUSIVE, UNRESERVED_KEYWORD, BARE_LABEL) /* GPDB */
234234
PG_KEYWORD("increment", INCREMENT, UNRESERVED_KEYWORD, BARE_LABEL)
235+
PG_KEYWORD("incremental", INCREMENTAL, UNRESERVED_KEYWORD, BARE_LABEL)
235236
PG_KEYWORD("index", INDEX, UNRESERVED_KEYWORD, BARE_LABEL)
236237
PG_KEYWORD("indexes", INDEXES, UNRESERVED_KEYWORD, BARE_LABEL)
237238
PG_KEYWORD("inherit", INHERIT, UNRESERVED_KEYWORD, BARE_LABEL)

0 commit comments

Comments
 (0)