Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita332b36

Browse files
committed
Grammar object type refactoring
Unify the grammar of COMMENT, DROP, and SECURITY LABEL further. Theyall effectively just take an object address for later processing, sowe can make the grammar more generalized. Some extra checking aboutwhich object types are supported can be done later in the statementexecution.Discussion:https://www.postgresql.org/message-id/flat/163c00a5-f634-ca52-fc7c-0e53deda8735%402ndquadrant.com
1 parente78900a commita332b36

File tree

2 files changed

+122
-114
lines changed

2 files changed

+122
-114
lines changed

‎src/backend/commands/seclabel.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,75 @@ typedef struct
3333

3434
staticList*label_provider_list=NIL;
3535

36+
staticbool
37+
SecLabelSupportsObjectType(ObjectTypeobjtype)
38+
{
39+
switch (objtype)
40+
{
41+
caseOBJECT_AGGREGATE:
42+
caseOBJECT_COLUMN:
43+
caseOBJECT_DATABASE:
44+
caseOBJECT_DOMAIN:
45+
caseOBJECT_EVENT_TRIGGER:
46+
caseOBJECT_FOREIGN_TABLE:
47+
caseOBJECT_FUNCTION:
48+
caseOBJECT_LANGUAGE:
49+
caseOBJECT_LARGEOBJECT:
50+
caseOBJECT_MATVIEW:
51+
caseOBJECT_PROCEDURE:
52+
caseOBJECT_PUBLICATION:
53+
caseOBJECT_ROLE:
54+
caseOBJECT_ROUTINE:
55+
caseOBJECT_SCHEMA:
56+
caseOBJECT_SEQUENCE:
57+
caseOBJECT_SUBSCRIPTION:
58+
caseOBJECT_TABLE:
59+
caseOBJECT_TABLESPACE:
60+
caseOBJECT_TYPE:
61+
caseOBJECT_VIEW:
62+
return true;
63+
64+
caseOBJECT_ACCESS_METHOD:
65+
caseOBJECT_AMOP:
66+
caseOBJECT_AMPROC:
67+
caseOBJECT_ATTRIBUTE:
68+
caseOBJECT_CAST:
69+
caseOBJECT_COLLATION:
70+
caseOBJECT_CONVERSION:
71+
caseOBJECT_DEFAULT:
72+
caseOBJECT_DEFACL:
73+
caseOBJECT_DOMCONSTRAINT:
74+
caseOBJECT_EXTENSION:
75+
caseOBJECT_FDW:
76+
caseOBJECT_FOREIGN_SERVER:
77+
caseOBJECT_INDEX:
78+
caseOBJECT_OPCLASS:
79+
caseOBJECT_OPERATOR:
80+
caseOBJECT_OPFAMILY:
81+
caseOBJECT_POLICY:
82+
caseOBJECT_PUBLICATION_REL:
83+
caseOBJECT_RULE:
84+
caseOBJECT_STATISTIC_EXT:
85+
caseOBJECT_TABCONSTRAINT:
86+
caseOBJECT_TRANSFORM:
87+
caseOBJECT_TRIGGER:
88+
caseOBJECT_TSCONFIGURATION:
89+
caseOBJECT_TSDICTIONARY:
90+
caseOBJECT_TSPARSER:
91+
caseOBJECT_TSTEMPLATE:
92+
caseOBJECT_USER_MAPPING:
93+
return false;
94+
95+
/*
96+
* There's intentionally no default: case here; we want the
97+
* compiler to warn if a new ObjectType hasn't been handled above.
98+
*/
99+
}
100+
101+
/* Shouldn't get here, but if we do, say "no support" */
102+
return false;
103+
}
104+
36105
/*
37106
* ExecSecLabelStmt --
38107
*
@@ -83,6 +152,11 @@ ExecSecLabelStmt(SecLabelStmt *stmt)
83152
stmt->provider)));
84153
}
85154

155+
if (!SecLabelSupportsObjectType(stmt->objtype))
156+
ereport(ERROR,
157+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
158+
errmsg("security labels are not supported for this type of object")));
159+
86160
/*
87161
* Translate the parser representation which identifies this object into
88162
* an ObjectAddress. get_object_address() will throw an error if the

‎src/backend/parser/gram.y

Lines changed: 48 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
463463
%type<boolean>copy_fromopt_program
464464

465465
%type<ival>opt_columneventcursor_optionsopt_holdopt_set_data
466-
%type<objtype>drop_type_any_namedrop_type_namedrop_type_name_on_any_name
467-
comment_type_any_namecomment_type_name
468-
security_label_type_any_namesecurity_label_type_name
466+
%type<objtype>object_type_any_nameobject_type_nameobject_type_name_on_any_name
467+
drop_type_name
469468

470469
%type<node>fetch_argsselect_limit_value
471470
offset_clauseselect_offset_value
@@ -6190,7 +6189,7 @@ ReassignOwnedStmt:
61906189
*
61916190
*****************************************************************************/
61926191

6193-
DropStmt:DROPdrop_type_any_nameIF_PEXISTSany_name_listopt_drop_behavior
6192+
DropStmt:DROPobject_type_any_nameIF_PEXISTSany_name_listopt_drop_behavior
61946193
{
61956194
DropStmt *n = makeNode(DropStmt);
61966195
n->removeType =$2;
@@ -6200,7 +6199,7 @@ DropStmt:DROP drop_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
62006199
n->concurrent =false;
62016200
$$ = (Node *)n;
62026201
}
6203-
|DROPdrop_type_any_nameany_name_listopt_drop_behavior
6202+
|DROPobject_type_any_nameany_name_listopt_drop_behavior
62046203
{
62056204
DropStmt *n = makeNode(DropStmt);
62066205
n->removeType =$2;
@@ -6230,7 +6229,7 @@ DropStmt:DROP drop_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
62306229
n->concurrent =false;
62316230
$$ = (Node *)n;
62326231
}
6233-
|DROPdrop_type_name_on_any_namenameONany_nameopt_drop_behavior
6232+
|DROPobject_type_name_on_any_namenameONany_nameopt_drop_behavior
62346233
{
62356234
DropStmt *n = makeNode(DropStmt);
62366235
n->removeType =$2;
@@ -6240,7 +6239,7 @@ DropStmt:DROP drop_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
62406239
n->concurrent =false;
62416240
$$ = (Node *) n;
62426241
}
6243-
|DROPdrop_type_name_on_any_nameIF_PEXISTSnameONany_nameopt_drop_behavior
6242+
|DROPobject_type_name_on_any_nameIF_PEXISTSnameONany_nameopt_drop_behavior
62446243
{
62456244
DropStmt *n = makeNode(DropStmt);
62466245
n->removeType =$2;
@@ -6312,8 +6311,8 @@ DropStmt:DROP drop_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
63126311
}
63136312
;
63146313

6315-
/* object types taking any_name_list*/
6316-
drop_type_any_name:
6314+
/* object types takingany_name/any_name_list*/
6315+
object_type_any_name:
63176316
TABLE{$$ = OBJECT_TABLE; }
63186317
|SEQUENCE{$$ = OBJECT_SEQUENCE; }
63196318
|VIEW{$$ = OBJECT_VIEW; }
@@ -6329,7 +6328,20 @@ drop_type_any_name:
63296328
|TEXT_PSEARCHCONFIGURATION{$$ = OBJECT_TSCONFIGURATION; }
63306329
;
63316330

6332-
/* object types taking name_list*/
6331+
/*
6332+
* object types taking name/name_list
6333+
*
6334+
* DROP handles some of them separately
6335+
*/
6336+
6337+
object_type_name:
6338+
drop_type_name{$$ =$1; }
6339+
|DATABASE{$$ = OBJECT_DATABASE; }
6340+
|ROLE{$$ = OBJECT_ROLE; }
6341+
|SUBSCRIPTION{$$ = OBJECT_SUBSCRIPTION; }
6342+
|TABLESPACE{$$ = OBJECT_TABLESPACE; }
6343+
;
6344+
63336345
drop_type_name:
63346346
ACCESSMETHOD{$$ = OBJECT_ACCESS_METHOD; }
63356347
|EVENTTRIGGER{$$ = OBJECT_EVENT_TRIGGER; }
@@ -6342,7 +6354,7 @@ drop_type_name:
63426354
;
63436355

63446356
/* object types attached to a table*/
6345-
drop_type_name_on_any_name:
6357+
object_type_name_on_any_name:
63466358
POLICY{$$ = OBJECT_POLICY; }
63476359
|RULE{$$ = OBJECT_RULE; }
63486360
|TRIGGER{$$ = OBJECT_TRIGGER; }
@@ -6394,44 +6406,28 @@ opt_restart_seqs:
63946406

63956407
/*****************************************************************************
63966408
*
6397-
*The COMMENT ON statement can take different forms based upon the type of
6398-
*the object associated with the comment. The form of the statement is:
6399-
*
6400-
*COMMENT ON [ [ ACCESS METHOD | CONVERSION | COLLATION |
6401-
* DATABASE | DOMAIN |
6402-
* EXTENSION | EVENT TRIGGER | FOREIGN DATA WRAPPER |
6403-
* FOREIGN TABLE | INDEX | [PROCEDURAL] LANGUAGE |
6404-
* MATERIALIZED VIEW | POLICY | ROLE | SCHEMA | SEQUENCE |
6405-
* SERVER | STATISTICS | TABLE | TABLESPACE |
6406-
* TEXT SEARCH CONFIGURATION | TEXT SEARCH DICTIONARY |
6407-
* TEXT SEARCH PARSER | TEXT SEARCH TEMPLATE | TYPE |
6408-
* VIEW] <objname> |
6409-
* AGGREGATE <aggname> (arg1, ...) |
6410-
* CAST (<src type> AS <dst type>) |
6411-
* COLUMN <relname>.<colname> |
6412-
* CONSTRAINT <constraintname> ON <relname> |
6413-
* CONSTRAINT <constraintname> ON DOMAIN <domainname> |
6414-
* FUNCTION <funcname> (arg1, arg2, ...) |
6415-
* LARGE OBJECT <oid> |
6416-
* OPERATOR <op> (leftoperand_typ, rightoperand_typ) |
6417-
* OPERATOR CLASS <name> USING <access-method> |
6418-
* OPERATOR FAMILY <name> USING <access-method> |
6419-
* RULE <rulename> ON <relname> |
6420-
* TRIGGER <triggername> ON <relname> ]
6421-
* IS { 'text' | NULL }
6409+
* COMMENT ON <object> IS <text>
64226410
*
64236411
*****************************************************************************/
64246412

64256413
CommentStmt:
6426-
COMMENTONcomment_type_any_nameany_nameIScomment_text
6414+
COMMENTONobject_type_any_nameany_nameIScomment_text
64276415
{
64286416
CommentStmt *n = makeNode(CommentStmt);
64296417
n->objtype =$3;
64306418
n->object = (Node *)$4;
64316419
n->comment =$6;
64326420
$$ = (Node *) n;
64336421
}
6434-
|COMMENTONcomment_type_namenameIScomment_text
6422+
|COMMENTONCOLUMNany_nameIScomment_text
6423+
{
6424+
CommentStmt *n = makeNode(CommentStmt);
6425+
n->objtype = OBJECT_COLUMN;
6426+
n->object = (Node *)$4;
6427+
n->comment =$6;
6428+
$$ = (Node *) n;
6429+
}
6430+
|COMMENTONobject_type_namenameIScomment_text
64356431
{
64366432
CommentStmt *n = makeNode(CommentStmt);
64376433
n->objtype =$3;
@@ -6500,10 +6496,10 @@ CommentStmt:
65006496
n->comment =$9;
65016497
$$ = (Node *) n;
65026498
}
6503-
|COMMENTONPOLICYnameONany_nameIScomment_text
6499+
|COMMENTONobject_type_name_on_any_namenameONany_nameIScomment_text
65046500
{
65056501
CommentStmt *n = makeNode(CommentStmt);
6506-
n->objtype =OBJECT_POLICY;
6502+
n->objtype =$3;
65076503
n->object = (Node *) lappend($6, makeString($4));
65086504
n->comment =$8;
65096505
$$ = (Node *) n;
@@ -6524,14 +6520,6 @@ CommentStmt:
65246520
n->comment =$6;
65256521
$$ = (Node *) n;
65266522
}
6527-
|COMMENTONRULEnameONany_nameIScomment_text
6528-
{
6529-
CommentStmt *n = makeNode(CommentStmt);
6530-
n->objtype = OBJECT_RULE;
6531-
n->object = (Node *) lappend($6, makeString($4));
6532-
n->comment =$8;
6533-
$$ = (Node *) n;
6534-
}
65356523
|COMMENTONTRANSFORMFORTypenameLANGUAGEnameIScomment_text
65366524
{
65376525
CommentStmt *n = makeNode(CommentStmt);
@@ -6540,14 +6528,6 @@ CommentStmt:
65406528
n->comment =$9;
65416529
$$ = (Node *) n;
65426530
}
6543-
|COMMENTONTRIGGERnameONany_nameIScomment_text
6544-
{
6545-
CommentStmt *n = makeNode(CommentStmt);
6546-
n->objtype = OBJECT_TRIGGER;
6547-
n->object = (Node *) lappend($6, makeString($4));
6548-
n->comment =$8;
6549-
$$ = (Node *) n;
6550-
}
65516531
|COMMENTONOPERATORCLASSany_nameUSINGnameIScomment_text
65526532
{
65536533
CommentStmt *n = makeNode(CommentStmt);
@@ -6582,40 +6562,6 @@ CommentStmt:
65826562
}
65836563
;
65846564

6585-
/* object types taking any_name*/
6586-
comment_type_any_name:
6587-
COLUMN{$$ = OBJECT_COLUMN; }
6588-
|INDEX{$$ = OBJECT_INDEX; }
6589-
|SEQUENCE{$$ = OBJECT_SEQUENCE; }
6590-
|STATISTICS{$$ = OBJECT_STATISTIC_EXT; }
6591-
|TABLE{$$ = OBJECT_TABLE; }
6592-
|VIEW{$$ = OBJECT_VIEW; }
6593-
|MATERIALIZEDVIEW{$$ = OBJECT_MATVIEW; }
6594-
|COLLATION{$$ = OBJECT_COLLATION; }
6595-
|CONVERSION_P{$$ = OBJECT_CONVERSION; }
6596-
|FOREIGNTABLE{$$ = OBJECT_FOREIGN_TABLE; }
6597-
|TEXT_PSEARCHCONFIGURATION{$$ = OBJECT_TSCONFIGURATION; }
6598-
|TEXT_PSEARCHDICTIONARY{$$ = OBJECT_TSDICTIONARY; }
6599-
|TEXT_PSEARCHPARSER{$$ = OBJECT_TSPARSER; }
6600-
|TEXT_PSEARCHTEMPLATE{$$ = OBJECT_TSTEMPLATE; }
6601-
;
6602-
6603-
/* object types taking name*/
6604-
comment_type_name:
6605-
ACCESSMETHOD{$$ = OBJECT_ACCESS_METHOD; }
6606-
|DATABASE{$$ = OBJECT_DATABASE; }
6607-
|EVENTTRIGGER{$$ = OBJECT_EVENT_TRIGGER; }
6608-
|EXTENSION{$$ = OBJECT_EXTENSION; }
6609-
|FOREIGNDATA_PWRAPPER{$$ = OBJECT_FDW; }
6610-
|opt_proceduralLANGUAGE{$$ = OBJECT_LANGUAGE; }
6611-
|PUBLICATION{$$ = OBJECT_PUBLICATION; }
6612-
|ROLE{$$ = OBJECT_ROLE; }
6613-
|SCHEMA{$$ = OBJECT_SCHEMA; }
6614-
|SERVER{$$ = OBJECT_FOREIGN_SERVER; }
6615-
|SUBSCRIPTION{$$ = OBJECT_SUBSCRIPTION; }
6616-
|TABLESPACE{$$ = OBJECT_TABLESPACE; }
6617-
;
6618-
66196565
comment_text:
66206566
Sconst{$$ =$1; }
66216567
|NULL_P{$$ =NULL; }
@@ -6632,7 +6578,7 @@ comment_text:
66326578
*****************************************************************************/
66336579

66346580
SecLabelStmt:
6635-
SECURITYLABELopt_providerONsecurity_label_type_any_nameany_name
6581+
SECURITYLABELopt_providerONobject_type_any_nameany_name
66366582
ISsecurity_label
66376583
{
66386584
SecLabelStmt *n = makeNode(SecLabelStmt);
@@ -6642,7 +6588,17 @@ SecLabelStmt:
66426588
n->label =$8;
66436589
$$ = (Node *) n;
66446590
}
6645-
|SECURITYLABELopt_providerONsecurity_label_type_namename
6591+
|SECURITYLABELopt_providerONCOLUMNany_name
6592+
ISsecurity_label
6593+
{
6594+
SecLabelStmt *n = makeNode(SecLabelStmt);
6595+
n->provider =$3;
6596+
n->objtype = OBJECT_COLUMN;
6597+
n->object = (Node *)$6;
6598+
n->label =$8;
6599+
$$ = (Node *) n;
6600+
}
6601+
|SECURITYLABELopt_providerONobject_type_namename
66466602
ISsecurity_label
66476603
{
66486604
SecLabelStmt *n = makeNode(SecLabelStmt);
@@ -6728,28 +6684,6 @@ opt_provider:FOR NonReservedWord_or_Sconst{ $$ = $2; }
67286684
|/* empty*/{$$ =NULL; }
67296685
;
67306686

6731-
/* object types taking any_name*/
6732-
security_label_type_any_name:
6733-
COLUMN{$$ = OBJECT_COLUMN; }
6734-
|FOREIGNTABLE{$$ = OBJECT_FOREIGN_TABLE; }
6735-
|SEQUENCE{$$ = OBJECT_SEQUENCE; }
6736-
|TABLE{$$ = OBJECT_TABLE; }
6737-
|VIEW{$$ = OBJECT_VIEW; }
6738-
|MATERIALIZEDVIEW{$$ = OBJECT_MATVIEW; }
6739-
;
6740-
6741-
/* object types taking name*/
6742-
security_label_type_name:
6743-
DATABASE{$$ = OBJECT_DATABASE; }
6744-
|EVENTTRIGGER{$$ = OBJECT_EVENT_TRIGGER; }
6745-
|opt_proceduralLANGUAGE{$$ = OBJECT_LANGUAGE; }
6746-
|PUBLICATION{$$ = OBJECT_PUBLICATION; }
6747-
|ROLE{$$ = OBJECT_ROLE; }
6748-
|SCHEMA{$$ = OBJECT_SCHEMA; }
6749-
|SUBSCRIPTION{$$ = OBJECT_SUBSCRIPTION; }
6750-
|TABLESPACE{$$ = OBJECT_TABLESPACE; }
6751-
;
6752-
67536687
security_label:Sconst{$$ =$1; }
67546688
|NULL_P{$$ =NULL; }
67556689
;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp