Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3567034

Browse files
committed
Refactor typenameTypeId()
Split the old typenameTypeId() into two functions: A new typenameTypeId() that returns only a type OID, and typenameTypeIdAndMod() that returns type OID and typmod. This isolates call sites better that actually care about the typmod.
1 parent c6873ea commit 3567034

File tree

16 files changed

+70
-52
lines changed

16 files changed

+70
-52
lines changed

src/backend/access/common/tupdesc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ BuildDescForRelation(List *schema)
536536
attnum++;
537537

538538
attname = entry->colname;
539-
atttypid = typenameTypeId(NULL, entry->typeName, &atttypmod);
539+
typenameTypeIdAndMod(NULL, entry->typeName, &atttypid, &atttypmod);
540540
attdim = list_length(entry->typeName->arrayBounds);
541541

542542
if (entry->typeName->setof)

src/backend/catalog/objectaddress.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ get_object_address(ObjectType objtype, List *objname, List *objargs,
137137
case OBJECT_TYPE:
138138
address.classId = TypeRelationId;
139139
address.objectId =
140-
typenameTypeId(NULL, makeTypeNameFromNameList(objname), NULL);
140+
typenameTypeId(NULL, makeTypeNameFromNameList(objname));
141141
address.objectSubId = 0;
142142
break;
143143
case OBJECT_AGGREGATE:
@@ -184,8 +184,8 @@ get_object_address(ObjectType objtype, List *objname, List *objargs,
184184
{
185185
TypeName *sourcetype = (TypeName *) linitial(objname);
186186
TypeName *targettype = (TypeName *) linitial(objargs);
187-
Oid sourcetypeid = typenameTypeId(NULL, sourcetype, NULL);
188-
Oid targettypeid = typenameTypeId(NULL, targettype, NULL);
187+
Oid sourcetypeid = typenameTypeId(NULL, sourcetype);
188+
Oid targettypeid = typenameTypeId(NULL, targettype);
189189

190190
address.classId = CastRelationId;
191191
address.objectId =

src/backend/commands/aggregatecmds.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
142142
{
143143
numArgs = 1;
144144
aggArgTypes = (Oid *) palloc(sizeof(Oid));
145-
aggArgTypes[0] = typenameTypeId(NULL, baseType, NULL);
145+
aggArgTypes[0] = typenameTypeId(NULL, baseType);
146146
}
147147
}
148148
else
@@ -164,7 +164,7 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
164164
{
165165
TypeName *curTypeName = (TypeName *) lfirst(lc);
166166

167-
aggArgTypes[i++] = typenameTypeId(NULL, curTypeName, NULL);
167+
aggArgTypes[i++] = typenameTypeId(NULL, curTypeName);
168168
}
169169
}
170170

@@ -179,7 +179,7 @@ DefineAggregate(List *name, List *args, bool oldstyle, List *parameters)
179179
* worse) by connecting up incompatible internal-using functions in an
180180
* aggregate.
181181
*/
182-
transTypeId = typenameTypeId(NULL, transType, NULL);
182+
transTypeId = typenameTypeId(NULL, transType);
183183
if (get_typtype(transTypeId) == TYPTYPE_PSEUDO &&
184184
!IsPolymorphicType(transTypeId))
185185
{

src/backend/commands/comment.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -607,8 +607,8 @@ CheckCastComment(List *qualname, List *arguments)
607607
targettype = (TypeName *) linitial(arguments);
608608
Assert(IsA(targettype, TypeName));
609609

610-
sourcetypeid = typenameTypeId(NULL, sourcetype, NULL);
611-
targettypeid = typenameTypeId(NULL, targettype, NULL);
610+
sourcetypeid = typenameTypeId(NULL, sourcetype);
611+
targettypeid = typenameTypeId(NULL, targettype);
612612

613613
/* Permission check */
614614
if (!pg_type_ownercheck(sourcetypeid, GetUserId())

src/backend/commands/functioncmds.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1496,8 +1496,8 @@ CreateCast(CreateCastStmt *stmt)
14961496
ObjectAddress myself,
14971497
referenced;
14981498

1499-
sourcetypeid = typenameTypeId(NULL, stmt->sourcetype, NULL);
1500-
targettypeid = typenameTypeId(NULL, stmt->targettype, NULL);
1499+
sourcetypeid = typenameTypeId(NULL, stmt->sourcetype);
1500+
targettypeid = typenameTypeId(NULL, stmt->targettype);
15011501
sourcetyptype = get_typtype(sourcetypeid);
15021502
targettyptype = get_typtype(targettypeid);
15031503

@@ -1779,8 +1779,8 @@ DropCast(DropCastStmt *stmt)
17791779
ObjectAddress object;
17801780

17811781
/* when dropping a cast, the types must exist even if you use IF EXISTS */
1782-
sourcetypeid = typenameTypeId(NULL, stmt->sourcetype, NULL);
1783-
targettypeid = typenameTypeId(NULL, stmt->targettype, NULL);
1782+
sourcetypeid = typenameTypeId(NULL, stmt->sourcetype);
1783+
targettypeid = typenameTypeId(NULL, stmt->targettype);
17841784

17851785
object.classId = CastRelationId;
17861786
object.objectId = get_cast_oid(sourcetypeid, targettypeid,

src/backend/commands/opclasscmds.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
398398
errmsg("must be superuser to create an operator class")));
399399

400400
/* Look up the datatype */
401-
typeoid = typenameTypeId(NULL, stmt->datatype, NULL);
401+
typeoid = typenameTypeId(NULL, stmt->datatype);
402402

403403
#ifdef NOT_USED
404404
/* XXX this is unnecessary given the superuser check above */
@@ -540,7 +540,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
540540
ereport(ERROR,
541541
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
542542
errmsg("storage type specified more than once")));
543-
storageoid = typenameTypeId(NULL, item->storedtype, NULL);
543+
storageoid = typenameTypeId(NULL, item->storedtype);
544544

545545
#ifdef NOT_USED
546546
/* XXX this is unnecessary given the superuser check above */
@@ -1009,12 +1009,12 @@ processTypesSpec(List *args, Oid *lefttype, Oid *righttype)
10091009
Assert(args != NIL);
10101010

10111011
typeName = (TypeName *) linitial(args);
1012-
*lefttype = typenameTypeId(NULL, typeName, NULL);
1012+
*lefttype = typenameTypeId(NULL, typeName);
10131013

10141014
if (list_length(args) > 1)
10151015
{
10161016
typeName = (TypeName *) lsecond(args);
1017-
*righttype = typenameTypeId(NULL, typeName, NULL);
1017+
*righttype = typenameTypeId(NULL, typeName);
10181018
}
10191019
else
10201020
*righttype = *lefttype;

src/backend/commands/operatorcmds.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ DefineOperator(List *names, List *parameters)
167167

168168
/* Transform type names to type OIDs */
169169
if (typeName1)
170-
typeId1 = typenameTypeId(NULL, typeName1, NULL);
170+
typeId1 = typenameTypeId(NULL, typeName1);
171171
if (typeName2)
172-
typeId2 = typenameTypeId(NULL, typeName2, NULL);
172+
typeId2 = typenameTypeId(NULL, typeName2);
173173

174174
if (!OidIsValid(typeId1) && !OidIsValid(typeId2))
175175
ereport(ERROR,

src/backend/commands/prepare.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ PrepareQuery(PrepareStmt *stmt, const char *queryString)
9090
foreach(l, stmt->argtypes)
9191
{
9292
TypeName *tn = lfirst(l);
93-
Oid toid = typenameTypeId(pstate, tn, NULL);
93+
Oid toid = typenameTypeId(pstate, tn);
9494

9595
argtypes[i++] = toid;
9696
}

src/backend/commands/tablecmds.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId)
464464
(void) heap_reloptions(relkind, reloptions, true);
465465

466466
if (stmt->ofTypename)
467-
ofTypeId = typenameTypeId(NULL, stmt->ofTypename, NULL);
467+
ofTypeId = typenameTypeId(NULL, stmt->ofTypename);
468468
else
469469
ofTypeId = InvalidOid;
470470

@@ -1399,7 +1399,7 @@ MergeAttributes(List *schema, List *supers, bool istemp,
13991399
(errmsg("merging multiple inherited definitions of column \"%s\"",
14001400
attributeName)));
14011401
def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1);
1402-
defTypeId = typenameTypeId(NULL, def->typeName, &deftypmod);
1402+
typenameTypeIdAndMod(NULL, def->typeName, &defTypeId, &deftypmod);
14031403
if (defTypeId != attribute->atttypid ||
14041404
deftypmod != attribute->atttypmod)
14051405
ereport(ERROR,
@@ -1571,8 +1571,8 @@ MergeAttributes(List *schema, List *supers, bool istemp,
15711571
(errmsg("merging column \"%s\" with inherited definition",
15721572
attributeName)));
15731573
def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1);
1574-
defTypeId = typenameTypeId(NULL, def->typeName, &deftypmod);
1575-
newTypeId = typenameTypeId(NULL, newdef->typeName, &newtypmod);
1574+
typenameTypeIdAndMod(NULL, def->typeName, &defTypeId, &deftypmod);
1575+
typenameTypeIdAndMod(NULL, newdef->typeName, &newTypeId, &newtypmod);
15761576
if (defTypeId != newTypeId || deftypmod != newtypmod)
15771577
ereport(ERROR,
15781578
(errcode(ERRCODE_DATATYPE_MISMATCH),
@@ -3910,7 +3910,7 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel,
39103910
int32 ctypmod;
39113911

39123912
/* Child column must match by type */
3913-
ctypeId = typenameTypeId(NULL, colDef->typeName, &ctypmod);
3913+
typenameTypeIdAndMod(NULL, colDef->typeName, &ctypeId, &ctypmod);
39143914
if (ctypeId != childatt->atttypid ||
39153915
ctypmod != childatt->atttypmod)
39163916
ereport(ERROR,
@@ -6100,7 +6100,7 @@ ATPrepAlterColumnType(List **wqueue,
61006100
colName)));
61016101

61026102
/* Look up the target type */
6103-
targettype = typenameTypeId(NULL, typeName, &targettypmod);
6103+
typenameTypeIdAndMod(NULL, typeName, &targettype, &targettypmod);
61046104

61056105
/* make sure datatype is legal for a column */
61066106
CheckAttributeType(colName, targettype, false);

src/backend/commands/typecmds.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ DefineType(List *names, List *parameters)
333333
}
334334
if (elemTypeEl)
335335
{
336-
elemType = typenameTypeId(NULL, defGetTypeName(elemTypeEl), NULL);
336+
elemType = typenameTypeId(NULL, defGetTypeName(elemTypeEl));
337337
/* disallow arrays of pseudotypes */
338338
if (get_typtype(elemType) == TYPTYPE_PSEUDO)
339339
ereport(ERROR,
@@ -1205,7 +1205,7 @@ AlterEnum(AlterEnumStmt *stmt)
12051205

12061206
/* Make a TypeName so we can use standard type lookup machinery */
12071207
typename = makeTypeNameFromNameList(stmt->typeName);
1208-
enum_type_oid = typenameTypeId(NULL, typename, NULL);
1208+
enum_type_oid = typenameTypeId(NULL, typename);
12091209

12101210
tup = SearchSysCache1(TYPEOID, ObjectIdGetDatum(enum_type_oid));
12111211
if (!HeapTupleIsValid(tup))
@@ -1620,7 +1620,7 @@ AlterDomainDefault(List *names, Node *defaultRaw)
16201620

16211621
/* Make a TypeName so we can use standard type lookup machinery */
16221622
typename = makeTypeNameFromNameList(names);
1623-
domainoid = typenameTypeId(NULL, typename, NULL);
1623+
domainoid = typenameTypeId(NULL, typename);
16241624

16251625
/* Look up the domain in the type table */
16261626
rel = heap_open(TypeRelationId, RowExclusiveLock);
@@ -1746,7 +1746,7 @@ AlterDomainNotNull(List *names, bool notNull)
17461746

17471747
/* Make a TypeName so we can use standard type lookup machinery */
17481748
typename = makeTypeNameFromNameList(names);
1749-
domainoid = typenameTypeId(NULL, typename, NULL);
1749+
domainoid = typenameTypeId(NULL, typename);
17501750

17511751
/* Look up the domain in the type table */
17521752
typrel = heap_open(TypeRelationId, RowExclusiveLock);
@@ -1846,7 +1846,7 @@ AlterDomainDropConstraint(List *names, const char *constrName,
18461846

18471847
/* Make a TypeName so we can use standard type lookup machinery */
18481848
typename = makeTypeNameFromNameList(names);
1849-
domainoid = typenameTypeId(NULL, typename, NULL);
1849+
domainoid = typenameTypeId(NULL, typename);
18501850

18511851
/* Look up the domain in the type table */
18521852
rel = heap_open(TypeRelationId, RowExclusiveLock);
@@ -1919,7 +1919,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint)
19191919

19201920
/* Make a TypeName so we can use standard type lookup machinery */
19211921
typename = makeTypeNameFromNameList(names);
1922-
domainoid = typenameTypeId(NULL, typename, NULL);
1922+
domainoid = typenameTypeId(NULL, typename);
19231923

19241924
/* Look up the domain in the type table */
19251925
typrel = heap_open(TypeRelationId, RowExclusiveLock);
@@ -2540,7 +2540,7 @@ RenameType(List *names, const char *newTypeName)
25402540

25412541
/* Make a TypeName so we can use standard type lookup machinery */
25422542
typename = makeTypeNameFromNameList(names);
2543-
typeOid = typenameTypeId(NULL, typename, NULL);
2543+
typeOid = typenameTypeId(NULL, typename);
25442544

25452545
/* Look up the type in the type table */
25462546
rel = heap_open(TypeRelationId, RowExclusiveLock);
@@ -2769,7 +2769,7 @@ AlterTypeNamespace(List *names, const char *newschema)
27692769

27702770
/* Make a TypeName so we can use standard type lookup machinery */
27712771
typename = makeTypeNameFromNameList(names);
2772-
typeOid = typenameTypeId(NULL, typename, NULL);
2772+
typeOid = typenameTypeId(NULL, typename);
27732773

27742774
/* check permissions on type */
27752775
if (!pg_type_ownercheck(typeOid, GetUserId()))

src/backend/parser/parse_expr.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ transformExpr(ParseState *pstate, Node *expr)
159159
Oid elementType;
160160
int32 targetTypmod;
161161

162-
targetType = typenameTypeId(pstate, tc->typeName,
163-
&targetTypmod);
162+
typenameTypeIdAndMod(pstate, tc->typeName,
163+
&targetType, &targetTypmod);
164164
/*
165165
* If target is a domain over array, work with the base
166166
* array type here. transformTypeCast below will cast the
@@ -1031,7 +1031,7 @@ transformAExprOf(ParseState *pstate, A_Expr *a)
10311031
ltype = exprType(lexpr);
10321032
foreach(telem, (List *) a->rexpr)
10331033
{
1034-
rtype = typenameTypeId(pstate, lfirst(telem), NULL);
1034+
rtype = typenameTypeId(pstate, lfirst(telem));
10351035
matched = (rtype == ltype);
10361036
if (matched)
10371037
break;
@@ -1889,7 +1889,7 @@ transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
18891889
XMLOID,
18901890
"XMLSERIALIZE"));
18911891

1892-
targetType = typenameTypeId(pstate, xs->typeName, &targetTypmod);
1892+
typenameTypeIdAndMod(pstate, xs->typeName, &targetType, &targetTypmod);
18931893

18941894
xexpr->xmloption = xs->xmloption;
18951895
xexpr->location = xs->location;
@@ -2052,7 +2052,7 @@ transformTypeCast(ParseState *pstate, TypeCast *tc)
20522052
int32 targetTypmod;
20532053
int location;
20542054

2055-
targetType = typenameTypeId(pstate, tc->typeName, &targetTypmod);
2055+
typenameTypeIdAndMod(pstate, tc->typeName, &targetType, &targetTypmod);
20562056

20572057
if (inputType == InvalidOid)
20582058
return expr; /* do nothing if NULL input */

src/backend/parser/parse_oper.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ LookupOperNameTypeNames(ParseState *pstate, List *opername,
148148
if (oprleft == NULL)
149149
leftoid = InvalidOid;
150150
else
151-
leftoid = typenameTypeId(pstate, oprleft, NULL);
151+
leftoid = typenameTypeId(pstate, oprleft);
152152

153153
if (oprright == NULL)
154154
rightoid = InvalidOid;
155155
else
156-
rightoid = typenameTypeId(pstate, oprright, NULL);
156+
rightoid = typenameTypeId(pstate, oprright);
157157

158158
return LookupOperName(pstate, opername, leftoid, rightoid,
159159
noError, location);

src/backend/parser/parse_relation.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ addRangeTableEntryForFunction(ParseState *pstate,
11651165
errmsg("column \"%s\" cannot be declared SETOF",
11661166
attrname),
11671167
parser_errposition(pstate, n->typeName->location)));
1168-
attrtype = typenameTypeId(pstate, n->typeName, &attrtypmod);
1168+
typenameTypeIdAndMod(pstate, n->typeName, &attrtype, &attrtypmod);
11691169
eref->colnames = lappend(eref->colnames, makeString(attrname));
11701170
rte->funccoltypes = lappend_oid(rte->funccoltypes, attrtype);
11711171
rte->funccoltypmods = lappend_int(rte->funccoltypmods, attrtypmod);

src/backend/parser/parse_type.c

+23-6
Original file line numberDiff line numberDiff line change
@@ -206,24 +206,41 @@ typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
206206
}
207207

208208
/*
209-
* typenameTypeId - given a TypeName, return the type's OID and typmod
209+
* typenameTypeId - given a TypeName, return the type's OID
210210
*
211-
* This is equivalent to typenameType, but we only hand back the type OID
211+
* This is similar to typenameType, but we only hand back the type OID
212212
* not the syscache entry.
213213
*/
214214
Oid
215-
typenameTypeId(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
215+
typenameTypeId(ParseState *pstate, const TypeName *typeName)
216216
{
217217
Oid typoid;
218218
Type tup;
219219

220-
tup = typenameType(pstate, typeName, typmod_p);
220+
tup = typenameType(pstate, typeName, NULL);
221221
typoid = HeapTupleGetOid(tup);
222222
ReleaseSysCache(tup);
223223

224224
return typoid;
225225
}
226226

227+
/*
228+
* typenameTypeIdAndMod - given a TypeName, return the type's OID and typmod
229+
*
230+
* This is equivalent to typenameType, but we only hand back the type OID
231+
* and typmod, not the syscache entry.
232+
*/
233+
void
234+
typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName,
235+
Oid *typeid_p, int32 *typmod_p)
236+
{
237+
Type tup;
238+
239+
tup = typenameType(pstate, typeName, typmod_p);
240+
*typeid_p = HeapTupleGetOid(tup);
241+
ReleaseSysCache(tup);
242+
}
243+
227244
/*
228245
* typenameTypeMod - given a TypeName, return the internal typmod value
229246
*
@@ -561,7 +578,7 @@ pts_error_callback(void *arg)
561578
* the string and convert it to a type OID and type modifier.
562579
*/
563580
void
564-
parseTypeString(const char *str, Oid *type_id, int32 *typmod_p)
581+
parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p)
565582
{
566583
StringInfoData buf;
567584
List *raw_parsetree_list;
@@ -635,7 +652,7 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod_p)
635652
if (typeName->setof)
636653
goto fail;
637654

638-
*type_id = typenameTypeId(NULL, typeName, typmod_p);
655+
typenameTypeIdAndMod(NULL, typeName, typeid_p, typmod_p);
639656

640657
pfree(buf.data);
641658

src/backend/utils/misc/guc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5621,7 +5621,7 @@ flatten_set_variable_args(const char *name, List *args)
56215621
Datum interval;
56225622
char *intervalout;
56235623

5624-
typoid = typenameTypeId(NULL, typeName, &typmod);
5624+
typenameTypeIdAndMod(NULL, typeName, &typoid, &typmod);
56255625
Assert(typoid == INTERVALOID);
56265626

56275627
interval =

0 commit comments

Comments
 (0)