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

Commit3f88672

Browse files
committed
Use TypeName to represent type names in certain commands
In COMMENT, DROP, SECURITY LABEL, and the new pg_get_object_addressfunction, we were representing types as a list of names, same as otherobjects; but types are special objects that require their ownrepresentation to be totally accurate. In the original COMMENT code wehad a note about fixing it which was lost in the course ofc10575f.Change all those places to use TypeName instead, as suggested by thatcomment.Right now the original coding doesn't cause any bugs, so no backpatch.It is more problematic for proposed future code that operate with objectaddresses from the SQL interface; type details such as array-ness arelost when working with the degraded representation.Thanks to Petr Jelínek and Dimitri Fontaine for offlist help on findinga solution to a shift/reduce grammar conflict.
1 parent930fd68 commit3f88672

File tree

4 files changed

+107
-48
lines changed

4 files changed

+107
-48
lines changed

‎src/backend/catalog/objectaddress.c

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -646,13 +646,11 @@ get_object_address(ObjectType objtype, List *objname, List *objargs,
646646
break;
647647
caseOBJECT_DOMCONSTRAINT:
648648
{
649-
List*domname;
650649
ObjectAddressdomaddr;
651650
char*constrname;
652651

653-
domname=list_truncate(list_copy(objname),list_length(objname)-1);
654-
constrname=strVal(llast(objname));
655-
domaddr=get_object_address_type(OBJECT_DOMAIN,domname,missing_ok);
652+
domaddr=get_object_address_type(OBJECT_DOMAIN,objname,missing_ok);
653+
constrname=strVal(linitial(objargs));
656654

657655
address.classId=ConstraintRelationId;
658656
address.objectId=get_domain_constraint_oid(domaddr.objectId,
@@ -1291,14 +1289,13 @@ get_object_address_attrdef(ObjectType objtype, List *objname,
12911289
* Find the ObjectAddress for a type or domain
12921290
*/
12931291
staticObjectAddress
1294-
get_object_address_type(ObjectTypeobjtype,
1295-
List*objname,boolmissing_ok)
1292+
get_object_address_type(ObjectTypeobjtype,List*objname,boolmissing_ok)
12961293
{
12971294
ObjectAddressaddress;
12981295
TypeName*typename;
12991296
Typetup;
13001297

1301-
typename=makeTypeNameFromNameList(objname);
1298+
typename=(TypeName*)linitial(objname);
13021299

13031300
address.classId=TypeRelationId;
13041301
address.objectId=InvalidOid;
@@ -1428,27 +1425,8 @@ pg_get_object_address(PG_FUNCTION_ARGS)
14281425
* given object type. Most use a simple string Values list, but there
14291426
* are some exceptions.
14301427
*/
1431-
if (type==OBJECT_TYPE||type==OBJECT_DOMAIN)
1432-
{
1433-
Datum*elems;
1434-
bool*nulls;
1435-
intnelems;
1436-
TypeName*typname;
1437-
1438-
deconstruct_array(namearr,TEXTOID,-1, false,'i',
1439-
&elems,&nulls,&nelems);
1440-
if (nelems!=1)
1441-
ereport(ERROR,
1442-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1443-
errmsg("name list length must be exactly %d",1)));
1444-
if (nulls[0])
1445-
ereport(ERROR,
1446-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1447-
errmsg("name or argument lists may not contain nulls")));
1448-
typname=typeStringToTypeName(TextDatumGetCString(elems[0]));
1449-
name=typname->names;
1450-
}
1451-
elseif (type==OBJECT_CAST)
1428+
if (type==OBJECT_TYPE||type==OBJECT_DOMAIN||type==OBJECT_CAST||
1429+
type==OBJECT_DOMCONSTRAINT)
14521430
{
14531431
Datum*elems;
14541432
bool*nulls;
@@ -1533,18 +1511,13 @@ pg_get_object_address(PG_FUNCTION_ARGS)
15331511
*/
15341512
switch (type)
15351513
{
1536-
caseOBJECT_DOMCONSTRAINT:
1537-
if (list_length(name)<2)
1538-
ereport(ERROR,
1539-
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1540-
errmsg("name list length must be at least %d",2)));
1541-
break;
15421514
caseOBJECT_LARGEOBJECT:
15431515
if (list_length(name)!=1)
15441516
ereport(ERROR,
15451517
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1546-
errmsg("name list length must be %d",1)));
1518+
errmsg("name list length must beexactly%d",1)));
15471519
break;
1520+
caseOBJECT_DOMCONSTRAINT:
15481521
caseOBJECT_OPCLASS:
15491522
caseOBJECT_OPFAMILY:
15501523
caseOBJECT_CAST:

‎src/backend/commands/dropcmds.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,14 @@ does_not_exist_skipping(ObjectType objtype, List *objname, List *objargs)
264264
{
265265
caseOBJECT_TYPE:
266266
caseOBJECT_DOMAIN:
267-
if (!schema_does_not_exist_skipping(objname,&msg,&name))
268267
{
269-
msg=gettext_noop("type \"%s\" does not exist, skipping");
270-
name=TypeNameToString(makeTypeNameFromNameList(objname));
268+
TypeName*typ=linitial(objname);
269+
270+
if (!schema_does_not_exist_skipping(typ->names,&msg,&name))
271+
{
272+
msg=gettext_noop("type \"%s\" does not exist, skipping");
273+
name=TypeNameToString(typ);
274+
}
271275
}
272276
break;
273277
caseOBJECT_COLLATION:

‎src/backend/parser/gram.y

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
351351
opt_column_listcolumnListopt_name_list
352352
sort_clauseopt_sort_clausesortby_listindex_params
353353
name_listrole_listfrom_clausefrom_listopt_array_bounds
354-
qualified_name_listany_nameany_name_list
354+
qualified_name_listany_nameany_name_listtype_name_list
355355
any_operatorexpr_listattrs
356356
target_listopt_target_listinsert_column_listset_target_list
357357
set_clause_listset_clausemultiple_set_clause
@@ -5471,6 +5471,46 @@ DropStmt:DROP drop_type IF_P EXISTS any_name_list opt_drop_behavior
54715471
n->concurrent =false;
54725472
$$ = (Node *)n;
54735473
}
5474+
|DROPTYPE_Ptype_name_listopt_drop_behavior
5475+
{
5476+
DropStmt *n = makeNode(DropStmt);
5477+
n->removeType = OBJECT_TYPE;
5478+
n->missing_ok =FALSE;
5479+
n->objects =$3;
5480+
n->behavior =$4;
5481+
n->concurrent =false;
5482+
$$ = (Node *) n;
5483+
}
5484+
|DROPTYPE_PIF_PEXISTStype_name_listopt_drop_behavior
5485+
{
5486+
DropStmt *n = makeNode(DropStmt);
5487+
n->removeType = OBJECT_TYPE;
5488+
n->missing_ok =TRUE;
5489+
n->objects =$5;
5490+
n->behavior =$6;
5491+
n->concurrent =false;
5492+
$$ = (Node *) n;
5493+
}
5494+
|DROPDOMAIN_Ptype_name_listopt_drop_behavior
5495+
{
5496+
DropStmt *n = makeNode(DropStmt);
5497+
n->removeType = OBJECT_DOMAIN;
5498+
n->missing_ok =FALSE;
5499+
n->objects =$3;
5500+
n->behavior =$4;
5501+
n->concurrent =false;
5502+
$$ = (Node *) n;
5503+
}
5504+
|DROPDOMAIN_PIF_PEXISTStype_name_listopt_drop_behavior
5505+
{
5506+
DropStmt *n = makeNode(DropStmt);
5507+
n->removeType = OBJECT_DOMAIN;
5508+
n->missing_ok =TRUE;
5509+
n->objects =$5;
5510+
n->behavior =$6;
5511+
n->concurrent =false;
5512+
$$ = (Node *) n;
5513+
}
54745514
|DROPINDEXCONCURRENTLYany_name_listopt_drop_behavior
54755515
{
54765516
DropStmt *n = makeNode(DropStmt);
@@ -5503,8 +5543,6 @@ drop_type:TABLE{ $$ = OBJECT_TABLE; }
55035543
|INDEX{$$ = OBJECT_INDEX; }
55045544
|FOREIGNTABLE{$$ = OBJECT_FOREIGN_TABLE; }
55055545
|EVENTTRIGGER {$$ = OBJECT_EVENT_TRIGGER; }
5506-
|TYPE_P{$$ = OBJECT_TYPE; }
5507-
|DOMAIN_P{$$ = OBJECT_DOMAIN; }
55085546
|COLLATION{$$ = OBJECT_COLLATION; }
55095547
|CONVERSION_P{$$ = OBJECT_CONVERSION; }
55105548
|SCHEMA{$$ = OBJECT_SCHEMA; }
@@ -5530,6 +5568,9 @@ attrs:'.' attr_name
55305568
{$$ = lappend($1, makeString($3)); }
55315569
;
55325570

5571+
type_name_list:
5572+
Typename{$$ = list_make1(list_make1($1)); }
5573+
|type_name_list','Typename{$$ = lappend($1, list_make1($3)); }
55335574

55345575
/*****************************************************************************
55355576
*
@@ -5594,6 +5635,24 @@ CommentStmt:
55945635
n->comment =$6;
55955636
$$ = (Node *) n;
55965637
}
5638+
|COMMENTONTYPE_PTypenameIScomment_text
5639+
{
5640+
CommentStmt *n = makeNode(CommentStmt);
5641+
n->objtype = OBJECT_TYPE;
5642+
n->objname = list_make1($4);
5643+
n->objargs = NIL;
5644+
n->comment =$6;
5645+
$$ = (Node *) n;
5646+
}
5647+
|COMMENTONDOMAIN_PTypenameIScomment_text
5648+
{
5649+
CommentStmt *n = makeNode(CommentStmt);
5650+
n->objtype = OBJECT_DOMAIN;
5651+
n->objname = list_make1($4);
5652+
n->objargs = NIL;
5653+
n->comment =$6;
5654+
$$ = (Node *) n;
5655+
}
55975656
|COMMENTONAGGREGATEfunc_nameaggr_argsIScomment_text
55985657
{
55995658
CommentStmt *n = makeNode(CommentStmt);
@@ -5634,8 +5693,13 @@ CommentStmt:
56345693
{
56355694
CommentStmt *n = makeNode(CommentStmt);
56365695
n->objtype = OBJECT_DOMCONSTRAINT;
5637-
n->objname = lappend($7, makeString($4));
5638-
n->objargs = NIL;
5696+
/*
5697+
* should use Typename not any_name in the production, but
5698+
* there's a shift/reduce conflict if we do that, so fix it
5699+
* up here.
5700+
*/
5701+
n->objname = list_make1(makeTypeNameFromNameList($7));
5702+
n->objargs = list_make1(makeString($4));
56395703
n->comment =$9;
56405704
$$ = (Node *) n;
56415705
}
@@ -5730,8 +5794,6 @@ comment_type:
57305794
|INDEX{$$ = OBJECT_INDEX; }
57315795
|SEQUENCE{$$ = OBJECT_SEQUENCE; }
57325796
|TABLE{$$ = OBJECT_TABLE; }
5733-
|DOMAIN_P{$$ = OBJECT_DOMAIN; }
5734-
|TYPE_P{$$ = OBJECT_TYPE; }
57355797
|VIEW{$$ = OBJECT_VIEW; }
57365798
|MATERIALIZEDVIEW{$$ = OBJECT_MATVIEW; }
57375799
|COLLATION{$$ = OBJECT_COLLATION; }
@@ -5776,6 +5838,28 @@ SecLabelStmt:
57765838
n->label =$8;
57775839
$$ = (Node *) n;
57785840
}
5841+
|SECURITYLABELopt_providerONTYPE_PTypename
5842+
ISsecurity_label
5843+
{
5844+
SecLabelStmt *n = makeNode(SecLabelStmt);
5845+
n->provider =$3;
5846+
n->objtype = OBJECT_TYPE;
5847+
n->objname = list_make1($6);
5848+
n->objargs = NIL;
5849+
n->label =$8;
5850+
$$ = (Node *) n;
5851+
}
5852+
|SECURITYLABELopt_providerONDOMAIN_PTypename
5853+
ISsecurity_label
5854+
{
5855+
SecLabelStmt *n = makeNode(SecLabelStmt);
5856+
n->provider =$3;
5857+
n->objtype = OBJECT_TYPE;
5858+
n->objname = list_make1($6);
5859+
n->objargs = NIL;
5860+
n->label =$8;
5861+
$$ = (Node *) n;
5862+
}
57795863
|SECURITYLABELopt_providerONAGGREGATEfunc_nameaggr_args
57805864
ISsecurity_label
57815865
{
@@ -5834,10 +5918,8 @@ security_label_type:
58345918
|SCHEMA{$$ = OBJECT_SCHEMA; }
58355919
|SEQUENCE{$$ = OBJECT_SEQUENCE; }
58365920
|TABLE{$$ = OBJECT_TABLE; }
5837-
|DOMAIN_P{$$ = OBJECT_TYPE; }
58385921
|ROLE{$$ = OBJECT_ROLE; }
58395922
|TABLESPACE{$$ = OBJECT_TABLESPACE; }
5840-
|TYPE_P{$$ = OBJECT_TYPE; }
58415923
|VIEW{$$ = OBJECT_VIEW; }
58425924
|MATERIALIZEDVIEW{$$ = OBJECT_MATVIEW; }
58435925
;

‎src/test/regress/sql/object_address.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ WITH objects (type, name, args) AS (VALUES
132132
('cast','{int8}','{int4}'),
133133
('collation','{default}','{}'),
134134
('table constraint','{addr_nsp, gentable, a_chk}','{}'),
135-
('domain constraint','{addr_nsp,gendomain, domconstr}','{}'),
135+
('domain constraint','{addr_nsp.gendomain}','{domconstr}'),
136136
('conversion','{pg_catalog, ascii_to_mic}','{}'),
137137
('default value','{addr_nsp, gentable, b}','{}'),
138138
('language','{plpgsql}','{}'),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp