Fold FindConversion() into FindConversionByName() and remove ACL check.

All callers of FindConversionByName() already do suitable permissions
checking already apart from this function, but this is not just dead
code removal: the unnecessary permissions check can actually lead to
spurious failures - there's no reason why inability to execute the
underlying function should prohibit renaming the conversion, for example.
(The error messages in these cases were also rather poor:
FindConversion would return InvalidOid, eventually leading to a complaint
that the conversion "did not exist", which was not correct.)

KaiGai Kohei
This commit is contained in:
Robert Haas 2010-02-02 18:52:33 +00:00
parent 4d32f6d7bf
commit d8db6a6096
3 changed files with 11 additions and 41 deletions

View File

@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.121 2010/01/02 16:57:36 momjian Exp $
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.122 2010/02/02 18:52:33 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@ -2836,7 +2836,10 @@ FindConversionByName(List *name)
{
/* use exact schema given */
namespaceId = LookupExplicitNamespace(schemaname);
return FindConversion(conversion_name, namespaceId);
return GetSysCacheOid(CONNAMENSP,
PointerGetDatum(conversion_name),
ObjectIdGetDatum(namespaceId),
0, 0);
}
else
{
@ -2850,7 +2853,10 @@ FindConversionByName(List *name)
if (namespaceId == myTempNamespace)
continue; /* do not look in temp namespace */
conoid = FindConversion(conversion_name, namespaceId);
conoid = GetSysCacheOid(CONNAMENSP,
PointerGetDatum(conversion_name),
ObjectIdGetDatum(namespaceId),
0, 0);
if (OidIsValid(conoid))
return conoid;
}

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.48 2010/01/02 16:57:36 momjian Exp $
* $PostgreSQL: pgsql/src/backend/catalog/pg_conversion.c,v 1.49 2010/02/02 18:52:33 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@ -209,38 +209,3 @@ FindDefaultConversion(Oid name_space, int32 for_encoding, int32 to_encoding)
ReleaseSysCacheList(catlist);
return proc;
}
/*
* FindConversion
*
* Find conversion by namespace and conversion name.
* Returns conversion OID.
*/
Oid
FindConversion(const char *conname, Oid connamespace)
{
HeapTuple tuple;
Oid procoid;
Oid conoid;
AclResult aclresult;
/* search pg_conversion by connamespace and conversion name */
tuple = SearchSysCache(CONNAMENSP,
PointerGetDatum(conname),
ObjectIdGetDatum(connamespace),
0, 0);
if (!HeapTupleIsValid(tuple))
return InvalidOid;
procoid = ((Form_pg_conversion) GETSTRUCT(tuple))->conproc;
conoid = HeapTupleGetOid(tuple);
ReleaseSysCache(tuple);
/* Check we have execute rights for the function */
aclresult = pg_proc_aclcheck(procoid, GetUserId(), ACL_EXECUTE);
if (aclresult != ACLCHECK_OK)
return InvalidOid;
return conoid;
}

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/catalog/pg_conversion_fn.h,v 1.5 2010/01/02 16:58:01 momjian Exp $
* $PostgreSQL: pgsql/src/include/catalog/pg_conversion_fn.h,v 1.6 2010/02/02 18:52:33 rhaas Exp $
*
*-------------------------------------------------------------------------
*/
@ -19,7 +19,6 @@ extern Oid ConversionCreate(const char *conname, Oid connamespace,
int32 conforencoding, int32 contoencoding,
Oid conproc, bool def);
extern void RemoveConversionById(Oid conversionOid);
extern Oid FindConversion(const char *conname, Oid connamespace);
extern Oid FindDefaultConversion(Oid connamespace, int32 for_encoding, int32 to_encoding);
#endif /* PG_CONVERSION_FN_H */