Support yet another syntax for specifying distribution strategy for
authorPavan Deolasee <[email protected]>
Fri, 15 Jan 2016 10:34:10 +0000 (16:04 +0530)
committerPavan Deolasee <[email protected]>
Fri, 15 Jan 2016 10:35:45 +0000 (16:05 +0530)
a table

DISTSTYLE KEY DISTKEY (col) maps to DISTRIBUTE BY HASH (col)
DISTSTYLE EVEN maps to DISTRIBUTE BY ROUNDROBIN
DISTSTYLE ALL maps to DISTRIBUTE BY REPLICATION

doc/src/sgml/ref/create_table.sgml
doc/src/sgml/ref/create_table_as.sgml
src/backend/parser/gram.y
src/include/parser/kwlist.h

index c001195d56214983a279f93635b35445b3f79418..1a87c24b413a9e3187615afb2aef0bce6c07190b 100755 (executable)
@@ -31,7 +31,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
 [ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
 [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
 [ TABLESPACE <replaceable class="PARAMETER">tablespace_name</replaceable> ]
-[ DISTRIBUTE BY { REPLICATION | ROUNDROBIN | { [HASH | MODULO ] ( <replaceable class="PARAMETER">column_name</replaceable> ) } } ]
+[ 
+  DISTRIBUTE BY { REPLICATION | ROUNDROBIN | { [HASH | MODULO ] ( <replaceable class="PARAMETER">column_name</replaceable> ) } } |
+  DISTRIBUTED { BY ( <replaceable class="PARAMETER">column_name</replaceable> ) } |
+  DISTSTYLE { EVEN | KEY | ALL } DISTKEY ( <replaceable class="PARAMETER">column_name</replaceable> )
+]
 [ TO { GROUP <replaceable class="PARAMETER">groupname</replaceable> | NODE ( <replaceable class="PARAMETER">nodename</replaceable> [, ... ] ) } ]
 
 CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXISTS ] <replaceable class="PARAMETER">table_name</replaceable>
@@ -43,7 +47,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
 [ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
 [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
 [ TABLESPACE <replaceable class="PARAMETER">tablespace_name</replaceable> ]
-[ DISTRIBUTE BY { REPLICATION | ROUNDROBIN | { [HASH | MODULO ] ( <replaceable class="PARAMETER">column_name</replaceable> ) } } ]
+[ 
+  DISTRIBUTE BY { REPLICATION | ROUNDROBIN | { [HASH | MODULO ] ( <replaceable class="PARAMETER">column_name</replaceable> ) } } |
+  DISTRIBUTED { BY ( <replaceable class="PARAMETER">column_name</replaceable> ) } |
+  DISTSTYLE { EVEN | KEY | ALL } DISTKEY ( <replaceable class="PARAMETER">column_name</replaceable> )
+]
 [ TO { GROUP <replaceable class="PARAMETER">groupname</replaceable> | NODE ( <replaceable class="PARAMETER">nodename</replaceable> [, ... ] ) } ]
 
 <phrase>where <replaceable class="PARAMETER">column_constraint</replaceable> is:</phrase>
index 790597f9d31a6d5be2b6e8a341b0a541bc6b8b0d..273157b24347600509953522344ef42e81001926 100755 (executable)
@@ -26,7 +26,11 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
     [ WITH ( <replaceable class="PARAMETER">storage_parameter</replaceable> [= <replaceable class="PARAMETER">value</replaceable>] [, ... ] ) | WITH OIDS | WITHOUT OIDS ]
     [ ON COMMIT { PRESERVE ROWS | DELETE ROWS | DROP } ]
     [ TABLESPACE <replaceable class="PARAMETER">tablespace_name</replaceable> ]
-    [ DISTRIBUTE BY { REPLICATION | ROUNDROBIN | { [HASH | MODULO ] ( <replaceable class="PARAMETER">column_name</replaceable> ) } } ]
+    [ 
+      DISTRIBUTE BY { REPLICATION | ROUNDROBIN | { [HASH | MODULO ] ( <replaceable class="PARAMETER">column_name</replaceable> ) } } |
+      DISTRIBUTED { BY ( <replaceable class="PARAMETER">column_name</replaceable> ) } |
+      DISTSTYLE { EVEN | KEY | ALL } DISTKEY ( <replaceable class="PARAMETER">column_name</replaceable> )
+    ]
     [ TO { GROUP <replaceable class="PARAMETER">groupname</replaceable> | NODE ( <replaceable class="PARAMETER">nodename</replaceable> [, ... ] ) } ]
     AS <replaceable>query</replaceable>
     [ WITH [ NO ] DATA ]
index 8d272573c0c7ed75c2c3650d9e5945e981248b81..3d12c3cc035ff5f454223ea367110d441942ca37 100644 (file)
@@ -552,7 +552,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
                                opt_frame_clause frame_extent frame_bound
 %type <str>            opt_existing_window_name
 /* PGXC_BEGIN */
-%type <str>            opt_barrier_id OptDistributeType
+%type <str>            opt_barrier_id OptDistributeType DistributeStyle OptDistKey
 %type <distby> OptDistributeBy OptDistributeByInternal
 %type <subclus> OptSubCluster OptSubClusterInternal
 /* PGXC_END */
@@ -580,7 +580,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
  */
 
 /* ordinary key words in alphabetical order */
-/* PGXC - added DISTRIBUTE, DISTRIBUTED, RANDOMLY, DIRECT, COORDINATOR, CLEAN,  NODE, BARRIER */
+/* PGXC - added DISTRIBUTE, DISTRIBUTED, DISTSYLE, DISTKEY, RANDOMLY, DIRECT, COORDINATOR, CLEAN,  NODE, BARRIER */
 %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
        AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
        ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
@@ -600,7 +600,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
        DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
        DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
 /* PGXC_BEGIN */
-       DICTIONARY DIRECT DISABLE_P DISCARD DISTINCT DISTRIBUTE DISTRIBUTED DO DOCUMENT_P DOMAIN_P DOUBLE_P
+       DICTIONARY DIRECT DISABLE_P DISCARD DISTINCT DISTKEY DISTRIBUTE DISTRIBUTED
+       DISTSTYLE DO DOCUMENT_P DOMAIN_P DOUBLE_P
 /* PGXC_END */
        DROP
 
@@ -3569,6 +3570,22 @@ OptDistributeBy: OptDistributeByInternal                 { $$ = $1; }
 OptDistributeType: IDENT                                                       { $$ = $1; }
                ;
 
+DistributeStyle: ALL                                                           { $$ = strdup("all"); }
+                       | KEY                                                                   { $$ = strdup("key"); }
+                       | IDENT                                                                 
+                               { 
+                                       if (strcmp($1, "even") != 0)
+                        ereport(ERROR,
+                                (errcode(ERRCODE_SYNTAX_ERROR),
+                                 errmsg("unrecognized distribution style \"%s\"", $1)));
+                                       $$ = $1;
+                               }
+               ;
+
+OptDistKey: DISTKEY '(' name ')'                                       { $$ = $3; }
+                       | /* EMPTY */                                                   { $$ = NULL; }
+               ;
+
 OptDistributeByInternal:  DISTRIBUTE BY OptDistributeType '(' name ')'
                                {
                                        DistributeBy *n = makeNode(DistributeBy);
@@ -3611,6 +3628,34 @@ OptDistributeByInternal:  DISTRIBUTE BY OptDistributeType '(' name ')'
                                        n->colname = NULL;
                                        $$ = n;
                                }
+                       | DISTSTYLE DistributeStyle OptDistKey
+                               {
+                                       DistributeBy *n = makeNode(DistributeBy);
+                                       if (strcmp($2, "even") == 0)
+                                               n->disttype = DISTTYPE_ROUNDROBIN;
+                                       else if (strcmp($2, "key") == 0)
+                                               n->disttype = DISTTYPE_HASH;
+                                       else if (strcmp($2, "all") == 0)
+                                               n->disttype = DISTTYPE_REPLICATION;
+                                       else
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                errmsg("unrecognized distribution style \"%s\"", $2)));
+                                       if ((n->disttype == DISTTYPE_ROUNDROBIN ||
+                                                n->disttype == DISTTYPE_REPLICATION) &&
+                                               ($3 != NULL))
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                errmsg("distribution key cannot be specified for distribution style \"%s\"", $2)));
+
+                                       if ((n->disttype == DISTTYPE_HASH) && ($3 == NULL))
+                                               ereport(ERROR,
+                                                               (errcode(ERRCODE_SYNTAX_ERROR),
+                                                                errmsg("distribution key must be specified for distribution style \"%s\"", $2)));
+
+                                       n->colname = $3;
+                                       $$ = n;
+                               }
                ;
 
 OptSubCluster: OptSubClusterInternal                           { $$ = $1; }
@@ -14143,8 +14188,10 @@ unreserved_keyword:
                        | DISABLE_P
                        | DISCARD
 /* PGXC_BEGIN */
+                       | DISTKEY
                        | DISTRIBUTE
                        | DISTRIBUTED
+                       | DISTSTYLE
 /* PGXC_END */
                        | DOCUMENT_P
                        | DOMAIN_P
index ec5c880c91f3756e0a642c74ed63aa9c349532fd..13ac665f82b36449eb17c7b6c4beeae3cec53feb 100644 (file)
@@ -140,8 +140,10 @@ PG_KEYWORD("disable", DISABLE_P, UNRESERVED_KEYWORD)
 PG_KEYWORD("discard", DISCARD, UNRESERVED_KEYWORD)
 PG_KEYWORD("distinct", DISTINCT, RESERVED_KEYWORD)
 #ifdef PGXC
+PG_KEYWORD("distkey", DISTKEY, UNRESERVED_KEYWORD)
 PG_KEYWORD("distribute", DISTRIBUTE, UNRESERVED_KEYWORD)
 PG_KEYWORD("distributed", DISTRIBUTED, UNRESERVED_KEYWORD)
+PG_KEYWORD("diststyle", DISTSTYLE, UNRESERVED_KEYWORD)
 #endif
 PG_KEYWORD("do", DO, RESERVED_KEYWORD)
 PG_KEYWORD("document", DOCUMENT_P, UNRESERVED_KEYWORD)