Fold FindConversion() into FindConversionByName() and remove ACL check.
authorRobert Haas <robertmhaas@gmail.com>
Tue, 2 Feb 2010 18:52:33 +0000 (18:52 +0000)
committerRobert Haas <robertmhaas@gmail.com>
Tue, 2 Feb 2010 18:52:33 +0000 (18:52 +0000)
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

src/backend/catalog/namespace.c
src/backend/catalog/pg_conversion.c
src/include/catalog/pg_conversion_fn.h

index 36e2a8b0ede185a59f81bdaba3df87236abed17f..54de01d117980969781519efa3322adc17ef36fe 100644 (file)
@@ -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;
        }
index 0eba48695d73bbd240348ba87a01731e119f2aa2..d26addaaeadbae3d1083d4978209b62ceabe7283 100644 (file)
@@ -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;
-}
index bb38ff71dd005e81c615fa2eba6b57a3d4b6cd43..d40dea62a589fe9f8a54ae20a8a69a62ab67a499 100644 (file)
@@ -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 */