Skip to content

Commit fb71d3c

Browse files
committed
Make syntax changes for custom compression methods
Signed-off-by: Ildus Kurbangaliev <i.kurbangaliev@gmail.com>
1 parent e8fdcac commit fb71d3c

File tree

5 files changed

+82
-7
lines changed

5 files changed

+82
-7
lines changed

src/backend/parser/gram.y

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
405405
transform_element_list transform_type_list
406406
TriggerTransitions TriggerReferencing
407407
publication_name_list
408+
optCompressionParameters
408409
vacuum_relation_list opt_vacuum_relation_list
409410

410411
%type <list> group_by_list
@@ -590,6 +591,10 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
590591
%type <list> hash_partbound
591592
%type <defelt> hash_partbound_elem
592593

594+
%type <node> optColumnCompression alterColumnCompression
595+
%type <str> compressionClause
596+
%type <list> optCompressionPreserve
597+
593598
/*
594599
* Non-keyword token types. These are hard-wired into the "flex" lexer.
595600
* They must be listed first so that their numeric codes do not depend on
@@ -622,9 +627,9 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
622627
CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
623628
CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
624629
CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
625-
COMMITTED CONCURRENTLY CONFIGURATION CONFLICT CONNECTION CONSTRAINT
626-
CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE
627-
CROSS CSV CUBE CURRENT_P
630+
COMMITTED COMPRESSION CONCURRENTLY CONFIGURATION CONFLICT
631+
CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
632+
COST CREATE CROSS CSV CUBE CURRENT_P
628633
CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
629634
CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
630635

@@ -2219,6 +2224,15 @@ alter_table_cmd:
22192224
n->missing_ok = true;
22202225
$$ = (Node *)n;
22212226
}
2227+
/* ALTER TABLE <name> ALTER [COLUMN] <colname> SET (COMPRESSION <cm> [WITH (<options>)]) */
2228+
| ALTER opt_column ColId SET alterColumnCompression
2229+
{
2230+
AlterTableCmd *n = makeNode(AlterTableCmd);
2231+
n->subtype = AT_SetCompression;
2232+
n->name = $3;
2233+
n->def = $5;
2234+
$$ = (Node *)n;
2235+
}
22222236
/* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
22232237
| DROP opt_column IF_P EXISTS ColId opt_drop_behavior
22242238
{
@@ -3326,11 +3340,12 @@ TypedTableElement:
33263340
| TableConstraint { $$ = $1; }
33273341
;
33283342

3329-
columnDef: ColId Typename create_generic_options ColQualList
3343+
columnDef: ColId Typename optColumnCompression create_generic_options ColQualList
33303344
{
33313345
ColumnDef *n = makeNode(ColumnDef);
33323346
n->colname = $1;
33333347
n->typeName = $2;
3348+
n->compression = (ColumnCompression *) $3;
33343349
n->inhcount = 0;
33353350
n->is_local = true;
33363351
n->is_not_null = false;
@@ -3339,8 +3354,8 @@ columnDef: ColId Typename create_generic_options ColQualList
33393354
n->raw_default = NULL;
33403355
n->cooked_default = NULL;
33413356
n->collOid = InvalidOid;
3342-
n->fdwoptions = $3;
3343-
SplitColQualList($4, &n->constraints, &n->collClause,
3357+
n->fdwoptions = $4;
3358+
SplitColQualList($5, &n->constraints, &n->collClause,
33443359
yyscanner);
33453360
n->location = @1;
33463361
$$ = (Node *)n;
@@ -3385,6 +3400,43 @@ columnOptions: ColId ColQualList
33853400
}
33863401
;
33873402

3403+
optCompressionPreserve:
3404+
PRESERVE '(' name_list ')' { $$ = $3; }
3405+
| /*EMPTY*/ { $$ = NULL; }
3406+
;
3407+
3408+
optCompressionParameters:
3409+
WITH '(' generic_option_list ')' { $$ = $3; }
3410+
| /*EMPTY*/ { $$ = NULL; }
3411+
;
3412+
3413+
compressionClause:
3414+
COMPRESSION name { $$ = pstrdup($2); }
3415+
;
3416+
3417+
optColumnCompression:
3418+
compressionClause optCompressionParameters
3419+
{
3420+
ColumnCompression *n = makeNode(ColumnCompression);
3421+
n->amname = $1;
3422+
n->options = (List *) $2;
3423+
n->preserve = NIL;
3424+
$$ = (Node *) n;
3425+
}
3426+
| /*EMPTY*/ { $$ = NULL; }
3427+
;
3428+
3429+
alterColumnCompression:
3430+
compressionClause optCompressionParameters optCompressionPreserve
3431+
{
3432+
ColumnCompression *n = makeNode(ColumnCompression);
3433+
n->amname = $1;
3434+
n->options = (List *) $2;
3435+
n->preserve = (List *) $3;
3436+
$$ = (Node *) n;
3437+
}
3438+
;
3439+
33883440
ColQualList:
33893441
ColQualList ColConstraint { $$ = lappend($1, $2); }
33903442
| /*EMPTY*/ { $$ = NIL; }
@@ -3614,6 +3666,7 @@ TableLikeOption:
36143666
| INDEXES { $$ = CREATE_TABLE_LIKE_INDEXES; }
36153667
| STATISTICS { $$ = CREATE_TABLE_LIKE_STATISTICS; }
36163668
| STORAGE { $$ = CREATE_TABLE_LIKE_STORAGE; }
3669+
| COMPRESSION { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
36173670
| ALL { $$ = CREATE_TABLE_LIKE_ALL; }
36183671
;
36193672

@@ -5312,6 +5365,7 @@ CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
53125365
am_type:
53135366
INDEX { $$ = AMTYPE_INDEX; }
53145367
| TABLE { $$ = AMTYPE_TABLE; }
5368+
| COMPRESSION { $$ = AMTYPE_COMPRESSION; }
53155369
;
53165370

53175371
/*****************************************************************************
@@ -15055,6 +15109,7 @@ unreserved_keyword:
1505515109
| COMMENTS
1505615110
| COMMIT
1505715111
| COMMITTED
15112+
| COMPRESSION
1505815113
| CONFIGURATION
1505915114
| CONFLICT
1506015115
| CONNECTION

src/include/catalog/pg_am.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef FormData_pg_am *Form_pg_am;
5454
*/
5555
#define AMTYPE_INDEX 'i' /* index access method */
5656
#define AMTYPE_TABLE 't' /* table access method */
57+
#define AMTYPE_COMPRESSION 'c' /* compression access method */
5758

5859
#endif /* EXPOSE_TO_CLIENT_CODE */
5960

src/include/nodes/nodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ typedef enum NodeTag
475475
T_PartitionBoundSpec,
476476
T_PartitionRangeDatum,
477477
T_PartitionCmd,
478+
T_ColumnCompression,
478479
T_VacuumRelation,
479480

480481
/*

src/include/nodes/parsenodes.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,20 @@ typedef struct RangeTableSample
622622
int location; /* method name location, or -1 if unknown */
623623
} RangeTableSample;
624624

625+
/*
626+
* ColumnCompression - compression parameters for some attribute
627+
*
628+
* This represents compression information defined using clause:
629+
* .. COMPRESSION <compression method> WITH (<params>) PRESERVE <compression AMs>
630+
*/
631+
typedef struct ColumnCompression
632+
{
633+
NodeTag type;
634+
char *amname;
635+
List *options;
636+
List *preserve;
637+
} ColumnCompression;
638+
625639
/*
626640
* ColumnDef - column definition (used in various creates)
627641
*
@@ -645,6 +659,7 @@ typedef struct ColumnDef
645659
NodeTag type;
646660
char *colname; /* name of column */
647661
TypeName *typeName; /* type of column */
662+
ColumnCompression *compression;
648663
int inhcount; /* number of times column is inherited */
649664
bool is_local; /* column has local (non-inherited) def'n */
650665
bool is_not_null; /* NOT NULL constraint specified? */
@@ -683,6 +698,7 @@ typedef enum TableLikeOption
683698
CREATE_TABLE_LIKE_INDEXES = 1 << 5,
684699
CREATE_TABLE_LIKE_STATISTICS = 1 << 6,
685700
CREATE_TABLE_LIKE_STORAGE = 1 << 7,
701+
CREATE_TABLE_LIKE_COMPRESSION = 1 << 8,
686702
CREATE_TABLE_LIKE_ALL = PG_INT32_MAX
687703
} TableLikeOption;
688704

@@ -1824,7 +1840,8 @@ typedef enum AlterTableType
18241840
AT_DetachPartition, /* DETACH PARTITION */
18251841
AT_AddIdentity, /* ADD IDENTITY */
18261842
AT_SetIdentity, /* SET identity column options */
1827-
AT_DropIdentity /* DROP IDENTITY */
1843+
AT_DropIdentity, /* DROP IDENTITY */
1844+
AT_SetCompression /* SET COMPRESSION */
18281845
} AlterTableType;
18291846

18301847
typedef struct ReplicaIdentityStmt

src/include/parser/kwlist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ PG_KEYWORD("comment", COMMENT, UNRESERVED_KEYWORD)
8787
PG_KEYWORD("comments", COMMENTS, UNRESERVED_KEYWORD)
8888
PG_KEYWORD("commit", COMMIT, UNRESERVED_KEYWORD)
8989
PG_KEYWORD("committed", COMMITTED, UNRESERVED_KEYWORD)
90+
PG_KEYWORD("compression", COMPRESSION, UNRESERVED_KEYWORD)
9091
PG_KEYWORD("concurrently", CONCURRENTLY, TYPE_FUNC_NAME_KEYWORD)
9192
PG_KEYWORD("configuration", CONFIGURATION, UNRESERVED_KEYWORD)
9293
PG_KEYWORD("conflict", CONFLICT, UNRESERVED_KEYWORD)

0 commit comments

Comments
 (0)