Skip to content

Commit 2ca64c6

Browse files
committed
Replace LookupFuncNameTypeNames() with LookupFuncWithArgs()
The old function took function name and function argument list as separate arguments. Now that all function signatures are passed around as ObjectWithArgs structs, this is no longer necessary and can be replaced by a function that takes ObjectWithArgs directly. Similarly for aggregates and operators. Reviewed-by: Jim Nasby <Jim.Nasby@BlueTreble.com> Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
1 parent 8b6d6cf commit 2ca64c6

File tree

13 files changed

+68
-116
lines changed

13 files changed

+68
-116
lines changed

src/backend/catalog/aclchk.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,7 @@ objectNamesToOids(GrantObjectType objtype, List *objnames)
670670
ObjectWithArgs *func = (ObjectWithArgs *) lfirst(cell);
671671
Oid funcid;
672672

673-
funcid = LookupFuncNameTypeNames(func->objname,
674-
func->objargs, false);
673+
funcid = LookupFuncWithArgs(func, false);
675674
objects = lappend_oid(objects, funcid);
676675
}
677676
break;

src/backend/catalog/objectaddress.c

+12-28
Original file line numberDiff line numberDiff line change
@@ -868,36 +868,20 @@ get_object_address(ObjectType objtype, Node *object,
868868
address = get_object_address_type(objtype, castNode(TypeName, object), missing_ok);
869869
break;
870870
case OBJECT_AGGREGATE:
871-
{
872-
ObjectWithArgs *owa = castNode(ObjectWithArgs, object);
873-
address.classId = ProcedureRelationId;
874-
address.objectId =
875-
LookupAggNameTypeNames(owa->objname, owa->objargs, missing_ok);
876-
address.objectSubId = 0;
877-
break;
878-
}
871+
address.classId = ProcedureRelationId;
872+
address.objectId = LookupAggWithArgs(castNode(ObjectWithArgs, object), missing_ok);
873+
address.objectSubId = 0;
874+
break;
879875
case OBJECT_FUNCTION:
880-
{
881-
ObjectWithArgs *owa = castNode(ObjectWithArgs, object);
882-
address.classId = ProcedureRelationId;
883-
address.objectId =
884-
LookupFuncNameTypeNames(owa->objname, owa->objargs, missing_ok);
885-
address.objectSubId = 0;
886-
break;
887-
}
876+
address.classId = ProcedureRelationId;
877+
address.objectId = LookupFuncWithArgs(castNode(ObjectWithArgs, object), missing_ok);
878+
address.objectSubId = 0;
879+
break;
888880
case OBJECT_OPERATOR:
889-
{
890-
ObjectWithArgs *owa = castNode(ObjectWithArgs, object);
891-
address.classId = OperatorRelationId;
892-
Assert(list_length(owa->objargs) == 2);
893-
address.objectId =
894-
LookupOperNameTypeNames(NULL, owa->objname,
895-
castNode(TypeName, linitial(owa->objargs)),
896-
castNode(TypeName, lsecond(owa->objargs)),
897-
missing_ok, -1);
898-
address.objectSubId = 0;
899-
break;
900-
}
881+
address.classId = OperatorRelationId;
882+
address.objectId = LookupOperWithArgs(castNode(ObjectWithArgs, object), missing_ok);
883+
address.objectSubId = 0;
884+
break;
901885
case OBJECT_COLLATION:
902886
address.classId = CollationRelationId;
903887
address.objectId = get_collation_oid(castNode(List, object), missing_ok);

src/backend/commands/functioncmds.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -1181,9 +1181,7 @@ AlterFunction(ParseState *pstate, AlterFunctionStmt *stmt)
11811181

11821182
rel = heap_open(ProcedureRelationId, RowExclusiveLock);
11831183

1184-
funcOid = LookupFuncNameTypeNames(stmt->func->objname,
1185-
stmt->func->objargs,
1186-
false);
1184+
funcOid = LookupFuncWithArgs(stmt->func, false);
11871185

11881186
tup = SearchSysCacheCopy1(PROCOID, ObjectIdGetDatum(funcOid));
11891187
if (!HeapTupleIsValid(tup)) /* should not happen */
@@ -1453,9 +1451,7 @@ CreateCast(CreateCastStmt *stmt)
14531451
{
14541452
Form_pg_proc procstruct;
14551453

1456-
funcid = LookupFuncNameTypeNames(stmt->func->objname,
1457-
stmt->func->objargs,
1458-
false);
1454+
funcid = LookupFuncWithArgs(stmt->func, false);
14591455

14601456
tuple = SearchSysCache1(PROCOID, ObjectIdGetDatum(funcid));
14611457
if (!HeapTupleIsValid(tuple))
@@ -1836,7 +1832,7 @@ CreateTransform(CreateTransformStmt *stmt)
18361832
*/
18371833
if (stmt->fromsql)
18381834
{
1839-
fromsqlfuncid = LookupFuncNameTypeNames(stmt->fromsql->objname, stmt->fromsql->objargs, false);
1835+
fromsqlfuncid = LookupFuncWithArgs(stmt->fromsql, false);
18401836

18411837
if (!pg_proc_ownercheck(fromsqlfuncid, GetUserId()))
18421838
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC, NameListToString(stmt->fromsql->objname));
@@ -1862,7 +1858,7 @@ CreateTransform(CreateTransformStmt *stmt)
18621858

18631859
if (stmt->tosql)
18641860
{
1865-
tosqlfuncid = LookupFuncNameTypeNames(stmt->tosql->objname, stmt->tosql->objargs, false);
1861+
tosqlfuncid = LookupFuncWithArgs(stmt->tosql, false);
18661862

18671863
if (!pg_proc_ownercheck(tosqlfuncid, GetUserId()))
18681864
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_PROC, NameListToString(stmt->tosql->objname));

src/backend/commands/opclasscmds.c

+7-23
Original file line numberDiff line numberDiff line change
@@ -475,19 +475,12 @@ DefineOpClass(CreateOpClassStmt *stmt)
475475
errmsg("invalid operator number %d,"
476476
" must be between 1 and %d",
477477
item->number, maxOpNumber)));
478-
if (item->args != NIL)
479-
{
480-
TypeName *typeName1 = (TypeName *) linitial(item->args);
481-
TypeName *typeName2 = (TypeName *) lsecond(item->args);
482-
483-
operOid = LookupOperNameTypeNames(NULL, item->name,
484-
typeName1, typeName2,
485-
false, -1);
486-
}
478+
if (item->name->objargs != NIL)
479+
operOid = LookupOperWithArgs(item->name, false);
487480
else
488481
{
489482
/* Default to binary op on input datatype */
490-
operOid = LookupOperName(NULL, item->name,
483+
operOid = LookupOperName(NULL, item->name->objname,
491484
typeoid, typeoid,
492485
false, -1);
493486
}
@@ -526,8 +519,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
526519
errmsg("invalid procedure number %d,"
527520
" must be between 1 and %d",
528521
item->number, maxProcNumber)));
529-
funcOid = LookupFuncNameTypeNames(item->name, item->args,
530-
false);
522+
funcOid = LookupFuncWithArgs(item->name, false);
531523
#ifdef NOT_USED
532524
/* XXX this is unnecessary given the superuser check above */
533525
/* Caller must own function */
@@ -857,15 +849,8 @@ AlterOpFamilyAdd(AlterOpFamilyStmt *stmt, Oid amoid, Oid opfamilyoid,
857849
errmsg("invalid operator number %d,"
858850
" must be between 1 and %d",
859851
item->number, maxOpNumber)));
860-
if (item->args != NIL)
861-
{
862-
TypeName *typeName1 = (TypeName *) linitial(item->args);
863-
TypeName *typeName2 = (TypeName *) lsecond(item->args);
864-
865-
operOid = LookupOperNameTypeNames(NULL, item->name,
866-
typeName1, typeName2,
867-
false, -1);
868-
}
852+
if (item->name->objargs != NIL)
853+
operOid = LookupOperWithArgs(item->name, false);
869854
else
870855
{
871856
ereport(ERROR,
@@ -908,8 +893,7 @@ AlterOpFamilyAdd(AlterOpFamilyStmt *stmt, Oid amoid, Oid opfamilyoid,
908893
errmsg("invalid procedure number %d,"
909894
" must be between 1 and %d",
910895
item->number, maxProcNumber)));
911-
funcOid = LookupFuncNameTypeNames(item->name, item->args,
912-
false);
896+
funcOid = LookupFuncWithArgs(item->name, false);
913897
#ifdef NOT_USED
914898
/* XXX this is unnecessary given the superuser check above */
915899
/* Caller must own function */

src/backend/commands/operatorcmds.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,7 @@ AlterOperator(AlterOperatorStmt *stmt)
402402
Oid joinOid;
403403

404404
/* Look up the operator */
405-
oprId = LookupOperNameTypeNames(NULL, stmt->opername,
406-
(TypeName *) linitial(stmt->operargs),
407-
(TypeName *) lsecond(stmt->operargs),
408-
false, -1);
405+
oprId = LookupOperWithArgs(stmt->opername, false);
409406
catalog = heap_open(OperatorRelationId, RowExclusiveLock);
410407
tup = SearchSysCacheCopy1(OPEROID, ObjectIdGetDatum(oprId));
411408
if (tup == NULL)

src/backend/nodes/copyfuncs.c

-2
Original file line numberDiff line numberDiff line change
@@ -3314,7 +3314,6 @@ _copyAlterOperatorStmt(const AlterOperatorStmt *from)
33143314
AlterOperatorStmt *newnode = makeNode(AlterOperatorStmt);
33153315

33163316
COPY_NODE_FIELD(opername);
3317-
COPY_NODE_FIELD(operargs);
33183317
COPY_NODE_FIELD(options);
33193318

33203319
return newnode;
@@ -3487,7 +3486,6 @@ _copyCreateOpClassItem(const CreateOpClassItem *from)
34873486

34883487
COPY_SCALAR_FIELD(itemtype);
34893488
COPY_NODE_FIELD(name);
3490-
COPY_NODE_FIELD(args);
34913489
COPY_SCALAR_FIELD(number);
34923490
COPY_NODE_FIELD(order_family);
34933491
COPY_NODE_FIELD(class_args);

src/backend/nodes/equalfuncs.c

-2
Original file line numberDiff line numberDiff line change
@@ -1390,7 +1390,6 @@ static bool
13901390
_equalAlterOperatorStmt(const AlterOperatorStmt *a, const AlterOperatorStmt *b)
13911391
{
13921392
COMPARE_NODE_FIELD(opername);
1393-
COMPARE_NODE_FIELD(operargs);
13941393
COMPARE_NODE_FIELD(options);
13951394

13961395
return true;
@@ -1535,7 +1534,6 @@ _equalCreateOpClassItem(const CreateOpClassItem *a, const CreateOpClassItem *b)
15351534
{
15361535
COMPARE_SCALAR_FIELD(itemtype);
15371536
COMPARE_NODE_FIELD(name);
1538-
COMPARE_NODE_FIELD(args);
15391537
COMPARE_SCALAR_FIELD(number);
15401538
COMPARE_NODE_FIELD(order_family);
15411539
COMPARE_NODE_FIELD(class_args);

src/backend/parser/gram.y

+8-10
Original file line numberDiff line numberDiff line change
@@ -5778,9 +5778,11 @@ opclass_item:
57785778
OPERATOR Iconst any_operator opclass_purpose opt_recheck
57795779
{
57805780
CreateOpClassItem *n = makeNode(CreateOpClassItem);
5781+
ObjectWithArgs *owa = makeNode(ObjectWithArgs);
5782+
owa->objname = $3;
5783+
owa->objargs = NIL;
57815784
n->itemtype = OPCLASS_ITEM_OPERATOR;
5782-
n->name = $3;
5783-
n->args = NIL;
5785+
n->name = owa;
57845786
n->number = $2;
57855787
n->order_family = $4;
57865788
$$ = (Node *) n;
@@ -5790,8 +5792,7 @@ opclass_item:
57905792
{
57915793
CreateOpClassItem *n = makeNode(CreateOpClassItem);
57925794
n->itemtype = OPCLASS_ITEM_OPERATOR;
5793-
n->name = $3->objname;
5794-
n->args = $3->objargs;
5795+
n->name = $3;
57955796
n->number = $2;
57965797
n->order_family = $4;
57975798
$$ = (Node *) n;
@@ -5800,17 +5801,15 @@ opclass_item:
58005801
{
58015802
CreateOpClassItem *n = makeNode(CreateOpClassItem);
58025803
n->itemtype = OPCLASS_ITEM_FUNCTION;
5803-
n->name = $3->objname;
5804-
n->args = $3->objargs;
5804+
n->name = $3;
58055805
n->number = $2;
58065806
$$ = (Node *) n;
58075807
}
58085808
| FUNCTION Iconst '(' type_list ')' function_with_argtypes
58095809
{
58105810
CreateOpClassItem *n = makeNode(CreateOpClassItem);
58115811
n->itemtype = OPCLASS_ITEM_FUNCTION;
5812-
n->name = $6->objname;
5813-
n->args = $6->objargs;
5812+
n->name = $6;
58145813
n->number = $2;
58155814
n->class_args = $4;
58165815
$$ = (Node *) n;
@@ -8789,8 +8788,7 @@ AlterOperatorStmt:
87898788
ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
87908789
{
87918790
AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
8792-
n->opername = $3->objname;
8793-
n->operargs = $3->objargs;
8791+
n->opername = $3;
87948792
n->options = $6;
87958793
$$ = (Node *)n;
87968794
}

src/backend/parser/parse_func.c

+16-16
Original file line numberDiff line numberDiff line change
@@ -1932,19 +1932,19 @@ LookupFuncName(List *funcname, int nargs, const Oid *argtypes, bool noError)
19321932
}
19331933

19341934
/*
1935-
* LookupFuncNameTypeNames
1935+
* LookupFuncWithArgs
19361936
* Like LookupFuncName, but the argument types are specified by a
1937-
* list of TypeName nodes.
1937+
* ObjectWithArgs node.
19381938
*/
19391939
Oid
1940-
LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
1940+
LookupFuncWithArgs(ObjectWithArgs *func, bool noError)
19411941
{
19421942
Oid argoids[FUNC_MAX_ARGS];
19431943
int argcount;
19441944
int i;
19451945
ListCell *args_item;
19461946

1947-
argcount = list_length(argtypes);
1947+
argcount = list_length(func->objargs);
19481948
if (argcount > FUNC_MAX_ARGS)
19491949
ereport(ERROR,
19501950
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
@@ -1953,7 +1953,7 @@ LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
19531953
FUNC_MAX_ARGS,
19541954
FUNC_MAX_ARGS)));
19551955

1956-
args_item = list_head(argtypes);
1956+
args_item = list_head(func->objargs);
19571957
for (i = 0; i < argcount; i++)
19581958
{
19591959
TypeName *t = (TypeName *) lfirst(args_item);
@@ -1962,19 +1962,19 @@ LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
19621962
args_item = lnext(args_item);
19631963
}
19641964

1965-
return LookupFuncName(funcname, argcount, argoids, noError);
1965+
return LookupFuncName(func->objname, argcount, argoids, noError);
19661966
}
19671967

19681968
/*
1969-
* LookupAggNameTypeNames
1970-
* Find an aggregate function given a name and list of TypeName nodes.
1969+
* LookupAggWithArgs
1970+
* Find an aggregate function from a given ObjectWithArgs node.
19711971
*
1972-
* This is almost like LookupFuncNameTypeNames, but the error messages refer
1972+
* This is almost like LookupFuncWithArgs, but the error messages refer
19731973
* to aggregates rather than plain functions, and we verify that the found
19741974
* function really is an aggregate.
19751975
*/
19761976
Oid
1977-
LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
1977+
LookupAggWithArgs(ObjectWithArgs *agg, bool noError)
19781978
{
19791979
Oid argoids[FUNC_MAX_ARGS];
19801980
int argcount;
@@ -1984,7 +1984,7 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
19841984
HeapTuple ftup;
19851985
Form_pg_proc pform;
19861986

1987-
argcount = list_length(argtypes);
1987+
argcount = list_length(agg->objargs);
19881988
if (argcount > FUNC_MAX_ARGS)
19891989
ereport(ERROR,
19901990
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
@@ -1994,15 +1994,15 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
19941994
FUNC_MAX_ARGS)));
19951995

19961996
i = 0;
1997-
foreach(lc, argtypes)
1997+
foreach(lc, agg->objargs)
19981998
{
19991999
TypeName *t = (TypeName *) lfirst(lc);
20002000

20012001
argoids[i] = LookupTypeNameOid(NULL, t, noError);
20022002
i++;
20032003
}
20042004

2005-
oid = LookupFuncName(aggname, argcount, argoids, true);
2005+
oid = LookupFuncName(agg->objname, argcount, argoids, true);
20062006

20072007
if (!OidIsValid(oid))
20082008
{
@@ -2012,12 +2012,12 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
20122012
ereport(ERROR,
20132013
(errcode(ERRCODE_UNDEFINED_FUNCTION),
20142014
errmsg("aggregate %s(*) does not exist",
2015-
NameListToString(aggname))));
2015+
NameListToString(agg->objname))));
20162016
else
20172017
ereport(ERROR,
20182018
(errcode(ERRCODE_UNDEFINED_FUNCTION),
20192019
errmsg("aggregate %s does not exist",
2020-
func_signature_string(aggname, argcount,
2020+
func_signature_string(agg->objname, argcount,
20212021
NIL, argoids))));
20222022
}
20232023

@@ -2036,7 +2036,7 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
20362036
ereport(ERROR,
20372037
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
20382038
errmsg("function %s is not an aggregate",
2039-
func_signature_string(aggname, argcount,
2039+
func_signature_string(agg->objname, argcount,
20402040
NIL, argoids))));
20412041
}
20422042

0 commit comments

Comments
 (0)