Commit fd1843ff authored by Robert Haas's avatar Robert Haas

Standardize get_whatever_oid functions for other object types.

- Rename TSParserGetPrsid to get_ts_parser_oid.
- Rename TSDictionaryGetDictid to get_ts_dict_oid.
- Rename TSTemplateGetTmplid to get_ts_template_oid.
- Rename TSConfigGetCfgid to get_ts_config_oid.
- Rename FindConversionByName to get_conversion_oid.
- Rename GetConstraintName to get_constraint_oid.
- Add new functions get_opclass_oid, get_opfamily_oid, get_rewrite_oid,
  get_rewrite_oid_without_relid, get_trigger_oid, and get_cast_oid.

The name of each function matches the corresponding catalog.

Thanks to KaiGai Kohei for the review.
parent 2a6ef344
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.c,v 1.12 2010/02/08 20:39:51 tgl Exp $ * $PostgreSQL: pgsql/contrib/tsearch2/tsearch2.c,v 1.13 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -190,7 +190,7 @@ tsa_set_curdict_byname(PG_FUNCTION_ARGS) ...@@ -190,7 +190,7 @@ tsa_set_curdict_byname(PG_FUNCTION_ARGS)
text *name = PG_GETARG_TEXT_PP(0); text *name = PG_GETARG_TEXT_PP(0);
Oid dict_oid; Oid dict_oid;
dict_oid = TSDictionaryGetDictid(stringToQualifiedNameList(text_to_cstring(name)), false); dict_oid = get_ts_dict_oid(stringToQualifiedNameList(text_to_cstring(name)), false);
current_dictionary_oid = dict_oid; current_dictionary_oid = dict_oid;
...@@ -229,7 +229,7 @@ tsa_set_curprs_byname(PG_FUNCTION_ARGS) ...@@ -229,7 +229,7 @@ tsa_set_curprs_byname(PG_FUNCTION_ARGS)
text *name = PG_GETARG_TEXT_PP(0); text *name = PG_GETARG_TEXT_PP(0);
Oid parser_oid; Oid parser_oid;
parser_oid = TSParserGetPrsid(stringToQualifiedNameList(text_to_cstring(name)), false); parser_oid = get_ts_parser_oid(stringToQualifiedNameList(text_to_cstring(name)), false);
current_parser_oid = parser_oid; current_parser_oid = parser_oid;
...@@ -562,6 +562,6 @@ static Oid ...@@ -562,6 +562,6 @@ static Oid
GetCurrentParser(void) GetCurrentParser(void)
{ {
if (current_parser_oid == InvalidOid) if (current_parser_oid == InvalidOid)
current_parser_oid = TSParserGetPrsid(stringToQualifiedNameList("pg_catalog.default"), false); current_parser_oid = get_ts_parser_oid(stringToQualifiedNameList("pg_catalog.default"), false);
return current_parser_oid; return current_parser_oid;
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Copyright (c) 2009-2010, PostgreSQL Global Development Group * Copyright (c) 2009-2010, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.5 2010/02/26 02:00:32 momjian Exp $ * $PostgreSQL: pgsql/contrib/unaccent/unaccent.c,v 1.6 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -279,7 +279,7 @@ unaccent_dict(PG_FUNCTION_ARGS) ...@@ -279,7 +279,7 @@ unaccent_dict(PG_FUNCTION_ARGS)
if (PG_NARGS() == 1) if (PG_NARGS() == 1)
{ {
dictOid = TSDictionaryGetDictid(stringToQualifiedNameList("unaccent"), false); dictOid = get_ts_dict_oid(stringToQualifiedNameList("unaccent"), false);
strArg = 0; strArg = 0;
} }
else else
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.126 2010/08/05 14:44:58 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/catalog/namespace.c,v 1.127 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1692,12 +1692,12 @@ ConversionIsVisible(Oid conid) ...@@ -1692,12 +1692,12 @@ ConversionIsVisible(Oid conid)
} }
/* /*
* TSParserGetPrsid - find a TS parser by possibly qualified name * get_ts_parser_oid - find a TS parser by possibly qualified name
* *
* If not found, returns InvalidOid if failOK, else throws error * If not found, returns InvalidOid if missing_ok, else throws error
*/ */
Oid Oid
TSParserGetPrsid(List *names, bool failOK) get_ts_parser_oid(List *names, bool missing_ok)
{ {
char *schemaname; char *schemaname;
char *parser_name; char *parser_name;
...@@ -1736,7 +1736,7 @@ TSParserGetPrsid(List *names, bool failOK) ...@@ -1736,7 +1736,7 @@ TSParserGetPrsid(List *names, bool failOK)
} }
} }
if (!OidIsValid(prsoid) && !failOK) if (!OidIsValid(prsoid) && !missing_ok)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT), (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("text search parser \"%s\" does not exist", errmsg("text search parser \"%s\" does not exist",
...@@ -1815,12 +1815,12 @@ TSParserIsVisible(Oid prsId) ...@@ -1815,12 +1815,12 @@ TSParserIsVisible(Oid prsId)
} }
/* /*
* TSDictionaryGetDictid - find a TS dictionary by possibly qualified name * get_ts_dict_oid - find a TS dictionary by possibly qualified name
* *
* If not found, returns InvalidOid if failOK, else throws error * If not found, returns InvalidOid if failOK, else throws error
*/ */
Oid Oid
TSDictionaryGetDictid(List *names, bool failOK) get_ts_dict_oid(List *names, bool missing_ok)
{ {
char *schemaname; char *schemaname;
char *dict_name; char *dict_name;
...@@ -1859,7 +1859,7 @@ TSDictionaryGetDictid(List *names, bool failOK) ...@@ -1859,7 +1859,7 @@ TSDictionaryGetDictid(List *names, bool failOK)
} }
} }
if (!OidIsValid(dictoid) && !failOK) if (!OidIsValid(dictoid) && !missing_ok)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT), (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("text search dictionary \"%s\" does not exist", errmsg("text search dictionary \"%s\" does not exist",
...@@ -1939,12 +1939,12 @@ TSDictionaryIsVisible(Oid dictId) ...@@ -1939,12 +1939,12 @@ TSDictionaryIsVisible(Oid dictId)
} }
/* /*
* TSTemplateGetTmplid - find a TS template by possibly qualified name * get_ts_template_oid - find a TS template by possibly qualified name
* *
* If not found, returns InvalidOid if failOK, else throws error * If not found, returns InvalidOid if missing_ok, else throws error
*/ */
Oid Oid
TSTemplateGetTmplid(List *names, bool failOK) get_ts_template_oid(List *names, bool missing_ok)
{ {
char *schemaname; char *schemaname;
char *template_name; char *template_name;
...@@ -1983,7 +1983,7 @@ TSTemplateGetTmplid(List *names, bool failOK) ...@@ -1983,7 +1983,7 @@ TSTemplateGetTmplid(List *names, bool failOK)
} }
} }
if (!OidIsValid(tmploid) && !failOK) if (!OidIsValid(tmploid) && !missing_ok)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT), (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("text search template \"%s\" does not exist", errmsg("text search template \"%s\" does not exist",
...@@ -2062,12 +2062,12 @@ TSTemplateIsVisible(Oid tmplId) ...@@ -2062,12 +2062,12 @@ TSTemplateIsVisible(Oid tmplId)
} }
/* /*
* TSConfigGetCfgid - find a TS config by possibly qualified name * get_ts_config_oid - find a TS config by possibly qualified name
* *
* If not found, returns InvalidOid if failOK, else throws error * If not found, returns InvalidOid if missing_ok, else throws error
*/ */
Oid Oid
TSConfigGetCfgid(List *names, bool failOK) get_ts_config_oid(List *names, bool missing_ok)
{ {
char *schemaname; char *schemaname;
char *config_name; char *config_name;
...@@ -2106,7 +2106,7 @@ TSConfigGetCfgid(List *names, bool failOK) ...@@ -2106,7 +2106,7 @@ TSConfigGetCfgid(List *names, bool failOK)
} }
} }
if (!OidIsValid(cfgoid) && !failOK) if (!OidIsValid(cfgoid) && !missing_ok)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT), (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("text search configuration \"%s\" does not exist", errmsg("text search configuration \"%s\" does not exist",
...@@ -2766,15 +2766,15 @@ PopOverrideSearchPath(void) ...@@ -2766,15 +2766,15 @@ PopOverrideSearchPath(void)
/* /*
* FindConversionByName - find a conversion by possibly qualified name * get_conversion_oid - find a conversion by possibly qualified name
*/ */
Oid Oid
FindConversionByName(List *name) get_conversion_oid(List *name, bool missing_ok)
{ {
char *schemaname; char *schemaname;
char *conversion_name; char *conversion_name;
Oid namespaceId; Oid namespaceId;
Oid conoid; Oid conoid = InvalidOid;
ListCell *l; ListCell *l;
/* deconstruct the name list */ /* deconstruct the name list */
...@@ -2784,9 +2784,9 @@ FindConversionByName(List *name) ...@@ -2784,9 +2784,9 @@ FindConversionByName(List *name)
{ {
/* use exact schema given */ /* use exact schema given */
namespaceId = LookupExplicitNamespace(schemaname); namespaceId = LookupExplicitNamespace(schemaname);
return GetSysCacheOid2(CONNAMENSP, conoid = GetSysCacheOid2(CONNAMENSP,
PointerGetDatum(conversion_name), PointerGetDatum(conversion_name),
ObjectIdGetDatum(namespaceId)); ObjectIdGetDatum(namespaceId));
} }
else else
{ {
...@@ -2809,7 +2809,12 @@ FindConversionByName(List *name) ...@@ -2809,7 +2809,12 @@ FindConversionByName(List *name)
} }
/* Not found in path */ /* Not found in path */
return InvalidOid; if (!OidIsValid(conoid) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("conversion \"%s\" does not exist",
NameListToString(name))));
return conoid;
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.53 2010/02/26 02:00:37 momjian Exp $ * $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.54 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -727,12 +727,12 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, ...@@ -727,12 +727,12 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
} }
/* /*
* GetConstraintByName * get_constraint_oid
* Find a constraint on the specified relation with the specified name. * Find a constraint on the specified relation with the specified name.
* Returns constraint's OID. * Returns constraint's OID.
*/ */
Oid Oid
GetConstraintByName(Oid relid, const char *conname) get_constraint_oid(Oid relid, const char *conname, bool missing_ok)
{ {
Relation pg_constraint; Relation pg_constraint;
HeapTuple tuple; HeapTuple tuple;
...@@ -773,7 +773,7 @@ GetConstraintByName(Oid relid, const char *conname) ...@@ -773,7 +773,7 @@ GetConstraintByName(Oid relid, const char *conname)
systable_endscan(scan); systable_endscan(scan);
/* If no such constraint exists, complain */ /* If no such constraint exists, complain */
if (!OidIsValid(conOid)) if (!OidIsValid(conOid) && !missing_ok)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT), (errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("constraint \"%s\" for table \"%s\" does not exist", errmsg("constraint \"%s\" for table \"%s\" does not exist",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1996-2010, PostgreSQL Global Development Group * Copyright (c) 1996-2010, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.116 2010/08/05 14:44:58 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.117 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -45,12 +45,14 @@ ...@@ -45,12 +45,14 @@
#include "commands/defrem.h" #include "commands/defrem.h"
#include "commands/proclang.h" #include "commands/proclang.h"
#include "commands/tablespace.h" #include "commands/tablespace.h"
#include "commands/trigger.h"
#include "libpq/be-fsstubs.h" #include "libpq/be-fsstubs.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "parser/parse_oper.h" #include "parser/parse_oper.h"
#include "parser/parse_type.h" #include "parser/parse_type.h"
#include "rewrite/rewriteSupport.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/fmgroids.h" #include "utils/fmgroids.h"
...@@ -826,7 +828,6 @@ CommentRule(List *qualname, char *comment) ...@@ -826,7 +828,6 @@ CommentRule(List *qualname, char *comment)
char *rulename; char *rulename;
RangeVar *rel; RangeVar *rel;
Relation relation; Relation relation;
HeapTuple tuple;
Oid reloid; Oid reloid;
Oid ruleoid; Oid ruleoid;
...@@ -834,46 +835,8 @@ CommentRule(List *qualname, char *comment) ...@@ -834,46 +835,8 @@ CommentRule(List *qualname, char *comment)
nnames = list_length(qualname); nnames = list_length(qualname);
if (nnames == 1) if (nnames == 1)
{ {
/* Old-style: only a rule name is given */
Relation RewriteRelation;
HeapScanDesc scanDesc;
ScanKeyData scanKeyData;
rulename = strVal(linitial(qualname)); rulename = strVal(linitial(qualname));
ruleoid = get_rewrite_oid_without_relid(rulename, &reloid);
/* Search pg_rewrite for such a rule */
ScanKeyInit(&scanKeyData,
Anum_pg_rewrite_rulename,
BTEqualStrategyNumber, F_NAMEEQ,
PointerGetDatum(rulename));
RewriteRelation = heap_open(RewriteRelationId, AccessShareLock);
scanDesc = heap_beginscan(RewriteRelation, SnapshotNow,
1, &scanKeyData);
tuple = heap_getnext(scanDesc, ForwardScanDirection);
if (HeapTupleIsValid(tuple))
{
reloid = ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class;
ruleoid = HeapTupleGetOid(tuple);
}
else
{
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" does not exist", rulename)));
reloid = ruleoid = 0; /* keep compiler quiet */
}
if (HeapTupleIsValid(tuple = heap_getnext(scanDesc,
ForwardScanDirection)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("there are multiple rules named \"%s\"", rulename),
errhint("Specify a relation name as well as a rule name.")));
heap_endscan(scanDesc);
heap_close(RewriteRelation, AccessShareLock);
/* Open the owning relation to ensure it won't go away meanwhile */ /* Open the owning relation to ensure it won't go away meanwhile */
relation = heap_open(reloid, AccessShareLock); relation = heap_open(reloid, AccessShareLock);
...@@ -891,17 +854,7 @@ CommentRule(List *qualname, char *comment) ...@@ -891,17 +854,7 @@ CommentRule(List *qualname, char *comment)
reloid = RelationGetRelid(relation); reloid = RelationGetRelid(relation);
/* Find the rule's pg_rewrite tuple, get its OID */ /* Find the rule's pg_rewrite tuple, get its OID */
tuple = SearchSysCache2(RULERELNAME, ruleoid = get_rewrite_oid(reloid, rulename, false);
ObjectIdGetDatum(reloid),
PointerGetDatum(rulename));
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" for relation \"%s\" does not exist",
rulename, RelationGetRelationName(relation))));
Assert(reloid == ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class);
ruleoid = HeapTupleGetOid(tuple);
ReleaseSysCache(tuple);
} }
/* Check object security */ /* Check object security */
...@@ -1046,11 +999,7 @@ CommentTrigger(List *qualname, char *comment) ...@@ -1046,11 +999,7 @@ CommentTrigger(List *qualname, char *comment)
List *relname; List *relname;
char *trigname; char *trigname;
RangeVar *rel; RangeVar *rel;
Relation pg_trigger, Relation relation;
relation;
HeapTuple triggertuple;
SysScanDesc scan;
ScanKeyData entry[2];
Oid oid; Oid oid;
/* Separate relname and trig name */ /* Separate relname and trig name */
...@@ -1065,46 +1014,16 @@ CommentTrigger(List *qualname, char *comment) ...@@ -1065,46 +1014,16 @@ CommentTrigger(List *qualname, char *comment)
relation = heap_openrv(rel, AccessShareLock); relation = heap_openrv(rel, AccessShareLock);
/* Check object security */ /* Check object security */
if (!pg_class_ownercheck(RelationGetRelid(relation), GetUserId())) if (!pg_class_ownercheck(RelationGetRelid(relation), GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
RelationGetRelationName(relation)); RelationGetRelationName(relation));
/* oid = get_trigger_oid(RelationGetRelid(relation), trigname, false);
* Fetch the trigger tuple from pg_trigger. There can be only one because
* of the unique index.
*/
pg_trigger = heap_open(TriggerRelationId, AccessShareLock);
ScanKeyInit(&entry[0],
Anum_pg_trigger_tgrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(RelationGetRelid(relation)));
ScanKeyInit(&entry[1],
Anum_pg_trigger_tgname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(trigname));
scan = systable_beginscan(pg_trigger, TriggerRelidNameIndexId, true,
SnapshotNow, 2, entry);
triggertuple = systable_getnext(scan);
/* If no trigger exists for the relation specified, notify user */
if (!HeapTupleIsValid(triggertuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("trigger \"%s\" for table \"%s\" does not exist",
trigname, RelationGetRelationName(relation))));
oid = HeapTupleGetOid(triggertuple);
systable_endscan(scan);
/* Call CreateComments() to create/drop the comments */ /* Call CreateComments() to create/drop the comments */
CreateComments(oid, TriggerRelationId, 0, comment); CreateComments(oid, TriggerRelationId, 0, comment);
/* Done, but hold lock on relation */ /* Done, but hold lock on relation */
heap_close(pg_trigger, AccessShareLock);
heap_close(relation, NoLock); heap_close(relation, NoLock);
} }
...@@ -1143,7 +1062,7 @@ CommentConstraint(List *qualname, char *comment) ...@@ -1143,7 +1062,7 @@ CommentConstraint(List *qualname, char *comment)
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
RelationGetRelationName(relation)); RelationGetRelationName(relation));
conOid = GetConstraintByName(RelationGetRelid(relation), conName); conOid = get_constraint_oid(RelationGetRelid(relation), conName, false);
/* Call CreateComments() to create/drop the comments */ /* Call CreateComments() to create/drop the comments */
CreateComments(conOid, ConstraintRelationId, 0, comment); CreateComments(conOid, ConstraintRelationId, 0, comment);
...@@ -1166,12 +1085,7 @@ CommentConversion(List *qualname, char *comment) ...@@ -1166,12 +1085,7 @@ CommentConversion(List *qualname, char *comment)
{ {
Oid conversionOid; Oid conversionOid;
conversionOid = FindConversionByName(qualname); conversionOid = get_conversion_oid(qualname, false);
if (!OidIsValid(conversionOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("conversion \"%s\" does not exist",
NameListToString(qualname))));
/* Check object security */ /* Check object security */
if (!pg_conversion_ownercheck(conversionOid, GetUserId())) if (!pg_conversion_ownercheck(conversionOid, GetUserId()))
...@@ -1228,65 +1142,23 @@ static void ...@@ -1228,65 +1142,23 @@ static void
CommentOpClass(List *qualname, List *arguments, char *comment) CommentOpClass(List *qualname, List *arguments, char *comment)
{ {
char *amname; char *amname;
char *schemaname;
char *opcname;
Oid amID; Oid amID;
Oid opcID; Oid opcID;
HeapTuple tuple;
Assert(list_length(arguments) == 1); Assert(list_length(arguments) == 1);
amname = strVal(linitial(arguments)); amname = strVal(linitial(arguments));
/* /*
* Get the access method's OID. * Get the operator class OID.
*/ */
amID = get_am_oid(amname, false); amID = get_am_oid(amname, false);
opcID = get_opclass_oid(amID, qualname, false);
/*
* Look up the opclass.
*/
/* deconstruct the name list */
DeconstructQualifiedName(qualname, &schemaname, &opcname);
if (schemaname)
{
/* Look in specific schema only */
Oid namespaceId;
namespaceId = LookupExplicitNamespace(schemaname);
tuple = SearchSysCache3(CLAAMNAMENSP,
ObjectIdGetDatum(amID),
PointerGetDatum(opcname),
ObjectIdGetDatum(namespaceId));
}
else
{
/* Unqualified opclass name, so search the search path */
opcID = OpclassnameGetOpcid(amID, opcname);
if (!OidIsValid(opcID))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
opcname, amname)));
tuple = SearchSysCache1(CLAOID, ObjectIdGetDatum(opcID));
}
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
NameListToString(qualname), amname)));
opcID = HeapTupleGetOid(tuple);
/* Permission check: must own opclass */ /* Permission check: must own opclass */
if (!pg_opclass_ownercheck(opcID, GetUserId())) if (!pg_opclass_ownercheck(opcID, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPCLASS, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPCLASS,
NameListToString(qualname)); NameListToString(qualname));
ReleaseSysCache(tuple);
/* Call CreateComments() to create/drop the comments */ /* Call CreateComments() to create/drop the comments */
CreateComments(opcID, OperatorClassRelationId, 0, comment); CreateComments(opcID, OperatorClassRelationId, 0, comment);
} }
...@@ -1304,65 +1176,21 @@ static void ...@@ -1304,65 +1176,21 @@ static void
CommentOpFamily(List *qualname, List *arguments, char *comment) CommentOpFamily(List *qualname, List *arguments, char *comment)
{ {
char *amname; char *amname;
char *schemaname;
char *opfname;
Oid amID; Oid amID;
Oid opfID; Oid opfID;
HeapTuple tuple;
Assert(list_length(arguments) == 1); Assert(list_length(arguments) == 1);
amname = strVal(linitial(arguments)); amname = strVal(linitial(arguments));
/* /* Get the opfamily OID. */
* Get the access method's OID.
*/
amID = get_am_oid(amname, false); amID = get_am_oid(amname, false);
opfID = get_opfamily_oid(amID, qualname, false);
/*
* Look up the opfamily.
*/
/* deconstruct the name list */
DeconstructQualifiedName(qualname, &schemaname, &opfname);
if (schemaname)
{
/* Look in specific schema only */
Oid namespaceId;
namespaceId = LookupExplicitNamespace(schemaname);
tuple = SearchSysCache3(OPFAMILYAMNAMENSP,
ObjectIdGetDatum(amID),
PointerGetDatum(opfname),
ObjectIdGetDatum(namespaceId));
}
else
{
/* Unqualified opfamily name, so search the search path */
opfID = OpfamilynameGetOpfid(amID, opfname);
if (!OidIsValid(opfID))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator family \"%s\" does not exist for access method \"%s\"",
opfname, amname)));
tuple = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfID));
}
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator family \"%s\" does not exist for access method \"%s\"",
NameListToString(qualname), amname)));
opfID = HeapTupleGetOid(tuple);
/* Permission check: must own opfamily */ /* Permission check: must own opfamily */
if (!pg_opfamily_ownercheck(opfID, GetUserId())) if (!pg_opfamily_ownercheck(opfID, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPFAMILY, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_OPFAMILY,
NameListToString(qualname)); NameListToString(qualname));
ReleaseSysCache(tuple);
/* Call CreateComments() to create/drop the comments */ /* Call CreateComments() to create/drop the comments */
CreateComments(opfID, OperatorFamilyRelationId, 0, comment); CreateComments(opfID, OperatorFamilyRelationId, 0, comment);
} }
...@@ -1423,7 +1251,6 @@ CommentCast(List *qualname, List *arguments, char *comment) ...@@ -1423,7 +1251,6 @@ CommentCast(List *qualname, List *arguments, char *comment)
TypeName *targettype; TypeName *targettype;
Oid sourcetypeid; Oid sourcetypeid;
Oid targettypeid; Oid targettypeid;
HeapTuple tuple;
Oid castOid; Oid castOid;
Assert(list_length(qualname) == 1); Assert(list_length(qualname) == 1);
...@@ -1436,18 +1263,8 @@ CommentCast(List *qualname, List *arguments, char *comment) ...@@ -1436,18 +1263,8 @@ CommentCast(List *qualname, List *arguments, char *comment)
sourcetypeid = typenameTypeId(NULL, sourcetype, NULL); sourcetypeid = typenameTypeId(NULL, sourcetype, NULL);
targettypeid = typenameTypeId(NULL, targettype, NULL); targettypeid = typenameTypeId(NULL, targettype, NULL);
tuple = SearchSysCache2(CASTSOURCETARGET,
ObjectIdGetDatum(sourcetypeid),
ObjectIdGetDatum(targettypeid));
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("cast from type %s to type %s does not exist",
format_type_be(sourcetypeid),
format_type_be(targettypeid))));
/* Get the OID of the cast */ /* Get the OID of the cast */
castOid = HeapTupleGetOid(tuple); castOid = get_cast_oid(sourcetypeid, targettypeid, false);
/* Permission check */ /* Permission check */
if (!pg_type_ownercheck(sourcetypeid, GetUserId()) if (!pg_type_ownercheck(sourcetypeid, GetUserId())
...@@ -1458,8 +1275,6 @@ CommentCast(List *qualname, List *arguments, char *comment) ...@@ -1458,8 +1275,6 @@ CommentCast(List *qualname, List *arguments, char *comment)
format_type_be(sourcetypeid), format_type_be(sourcetypeid),
format_type_be(targettypeid)))); format_type_be(targettypeid))));
ReleaseSysCache(tuple);
/* Call CreateComments() to create/drop the comments */ /* Call CreateComments() to create/drop the comments */
CreateComments(castOid, CastRelationId, 0, comment); CreateComments(castOid, CastRelationId, 0, comment);
} }
...@@ -1469,7 +1284,7 @@ CommentTSParser(List *qualname, char *comment) ...@@ -1469,7 +1284,7 @@ CommentTSParser(List *qualname, char *comment)
{ {
Oid prsId; Oid prsId;
prsId = TSParserGetPrsid(qualname, false); prsId = get_ts_parser_oid(qualname, false);
if (!superuser()) if (!superuser())
ereport(ERROR, ereport(ERROR,
...@@ -1484,7 +1299,7 @@ CommentTSDictionary(List *qualname, char *comment) ...@@ -1484,7 +1299,7 @@ CommentTSDictionary(List *qualname, char *comment)
{ {
Oid dictId; Oid dictId;
dictId = TSDictionaryGetDictid(qualname, false); dictId = get_ts_dict_oid(qualname, false);
if (!pg_ts_dict_ownercheck(dictId, GetUserId())) if (!pg_ts_dict_ownercheck(dictId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSDICTIONARY,
...@@ -1498,7 +1313,7 @@ CommentTSTemplate(List *qualname, char *comment) ...@@ -1498,7 +1313,7 @@ CommentTSTemplate(List *qualname, char *comment)
{ {
Oid tmplId; Oid tmplId;
tmplId = TSTemplateGetTmplid(qualname, false); tmplId = get_ts_template_oid(qualname, false);
if (!superuser()) if (!superuser())
ereport(ERROR, ereport(ERROR,
...@@ -1513,7 +1328,7 @@ CommentTSConfiguration(List *qualname, char *comment) ...@@ -1513,7 +1328,7 @@ CommentTSConfiguration(List *qualname, char *comment)
{ {
Oid cfgId; Oid cfgId;
cfgId = TSConfigGetCfgid(qualname, false); cfgId = get_ts_config_oid(qualname, false);
if (!pg_ts_config_ownercheck(cfgId, GetUserId())) if (!pg_ts_config_ownercheck(cfgId, GetUserId()))
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_TSCONFIGURATION,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.41 2010/02/14 18:42:14 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/commands/conversioncmds.c,v 1.42 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -142,23 +142,13 @@ DropConversionsCommand(DropStmt *drop) ...@@ -142,23 +142,13 @@ DropConversionsCommand(DropStmt *drop)
Form_pg_conversion con; Form_pg_conversion con;
ObjectAddress object; ObjectAddress object;
conversionOid = FindConversionByName(name); conversionOid = get_conversion_oid(name, drop->missing_ok);
if (!OidIsValid(conversionOid)) if (!OidIsValid(conversionOid))
{ {
if (!drop->missing_ok) ereport(NOTICE,
{ (errmsg("conversion \"%s\" does not exist, skipping",
ereport(ERROR, NameListToString(name))));
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("conversion \"%s\" does not exist",
NameListToString(name))));
}
else
{
ereport(NOTICE,
(errmsg("conversion \"%s\" does not exist, skipping",
NameListToString(name))));
}
continue; continue;
} }
...@@ -202,12 +192,7 @@ RenameConversion(List *name, const char *newname) ...@@ -202,12 +192,7 @@ RenameConversion(List *name, const char *newname)
rel = heap_open(ConversionRelationId, RowExclusiveLock); rel = heap_open(ConversionRelationId, RowExclusiveLock);
conversionOid = FindConversionByName(name); conversionOid = get_conversion_oid(name, false);
if (!OidIsValid(conversionOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("conversion \"%s\" does not exist",
NameListToString(name))));
tup = SearchSysCacheCopy1(CONVOID, ObjectIdGetDatum(conversionOid)); tup = SearchSysCacheCopy1(CONVOID, ObjectIdGetDatum(conversionOid));
if (!HeapTupleIsValid(tup)) /* should not happen */ if (!HeapTupleIsValid(tup)) /* should not happen */
...@@ -255,12 +240,7 @@ AlterConversionOwner(List *name, Oid newOwnerId) ...@@ -255,12 +240,7 @@ AlterConversionOwner(List *name, Oid newOwnerId)
rel = heap_open(ConversionRelationId, RowExclusiveLock); rel = heap_open(ConversionRelationId, RowExclusiveLock);
conversionOid = FindConversionByName(name); conversionOid = get_conversion_oid(name, false);
if (!OidIsValid(conversionOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("conversion \"%s\" does not exist",
NameListToString(name))));
AlterConversionOwner_internal(rel, conversionOid, newOwnerId); AlterConversionOwner_internal(rel, conversionOid, newOwnerId);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.118 2010/02/26 02:00:39 momjian Exp $ * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.119 2010/08/05 15:25:35 rhaas Exp $
* *
* DESCRIPTION * DESCRIPTION
* These routines take the parse tree and pick out the * These routines take the parse tree and pick out the
...@@ -1759,30 +1759,23 @@ DropCast(DropCastStmt *stmt) ...@@ -1759,30 +1759,23 @@ DropCast(DropCastStmt *stmt)
{ {
Oid sourcetypeid; Oid sourcetypeid;
Oid targettypeid; Oid targettypeid;
HeapTuple tuple;
ObjectAddress object; ObjectAddress object;
/* when dropping a cast, the types must exist even if you use IF EXISTS */ /* when dropping a cast, the types must exist even if you use IF EXISTS */
sourcetypeid = typenameTypeId(NULL, stmt->sourcetype, NULL); sourcetypeid = typenameTypeId(NULL, stmt->sourcetype, NULL);
targettypeid = typenameTypeId(NULL, stmt->targettype, NULL); targettypeid = typenameTypeId(NULL, stmt->targettype, NULL);
tuple = SearchSysCache2(CASTSOURCETARGET, object.classId = CastRelationId;
ObjectIdGetDatum(sourcetypeid), object.objectId = get_cast_oid(sourcetypeid, targettypeid,
ObjectIdGetDatum(targettypeid)); stmt->missing_ok);
if (!HeapTupleIsValid(tuple)) object.objectSubId = 0;
if (!OidIsValid(object.objectId))
{ {
if (!stmt->missing_ok) ereport(NOTICE,
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("cast from type %s to type %s does not exist",
format_type_be(sourcetypeid),
format_type_be(targettypeid))));
else
ereport(NOTICE,
(errmsg("cast from type %s to type %s does not exist, skipping", (errmsg("cast from type %s to type %s does not exist, skipping",
format_type_be(sourcetypeid), format_type_be(sourcetypeid),
format_type_be(targettypeid)))); format_type_be(targettypeid))));
return; return;
} }
...@@ -1798,15 +1791,31 @@ DropCast(DropCastStmt *stmt) ...@@ -1798,15 +1791,31 @@ DropCast(DropCastStmt *stmt)
/* /*
* Do the deletion * Do the deletion
*/ */
object.classId = CastRelationId;
object.objectId = HeapTupleGetOid(tuple);
object.objectSubId = 0;
ReleaseSysCache(tuple);
performDeletion(&object, stmt->behavior); performDeletion(&object, stmt->behavior);
} }
/*
* get_cast_oid - given two type OIDs, look up a cast OID
*
* If missing_ok is false, throw an error if the cast is not found. If
* true, just return InvalidOid.
*/
Oid
get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok)
{
Oid oid;
oid = GetSysCacheOid2(CASTSOURCETARGET,
ObjectIdGetDatum(sourcetypeid),
ObjectIdGetDatum(targettypeid));
if (!OidIsValid(oid) && !missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("cast from type %s to type %s does not exist",
format_type_be(sourcetypeid),
format_type_be(targettypeid))));
return oid;
}
void void
DropCastById(Oid castOid) DropCastById(Oid castOid)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.70 2010/08/05 14:45:01 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.71 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -90,10 +90,11 @@ static void AlterOpFamilyOwner_internal(Relation rel, HeapTuple tuple, ...@@ -90,10 +90,11 @@ static void AlterOpFamilyOwner_internal(Relation rel, HeapTuple tuple,
* Returns a syscache tuple reference, or NULL if not found. * Returns a syscache tuple reference, or NULL if not found.
*/ */
static HeapTuple static HeapTuple
OpFamilyCacheLookup(Oid amID, List *opfamilyname) OpFamilyCacheLookup(Oid amID, List *opfamilyname, bool missing_ok)
{ {
char *schemaname; char *schemaname;
char *opfname; char *opfname;
HeapTuple htup;
/* deconstruct the name list */ /* deconstruct the name list */
DeconstructQualifiedName(opfamilyname, &schemaname, &opfname); DeconstructQualifiedName(opfamilyname, &schemaname, &opfname);
...@@ -104,7 +105,7 @@ OpFamilyCacheLookup(Oid amID, List *opfamilyname) ...@@ -104,7 +105,7 @@ OpFamilyCacheLookup(Oid amID, List *opfamilyname)
Oid namespaceId; Oid namespaceId;
namespaceId = LookupExplicitNamespace(schemaname); namespaceId = LookupExplicitNamespace(schemaname);
return SearchSysCache3(OPFAMILYAMNAMENSP, htup = SearchSysCache3(OPFAMILYAMNAMENSP,
ObjectIdGetDatum(amID), ObjectIdGetDatum(amID),
PointerGetDatum(opfname), PointerGetDatum(opfname),
ObjectIdGetDatum(namespaceId)); ObjectIdGetDatum(namespaceId));
...@@ -115,9 +116,47 @@ OpFamilyCacheLookup(Oid amID, List *opfamilyname) ...@@ -115,9 +116,47 @@ OpFamilyCacheLookup(Oid amID, List *opfamilyname)
Oid opfID = OpfamilynameGetOpfid(amID, opfname); Oid opfID = OpfamilynameGetOpfid(amID, opfname);
if (!OidIsValid(opfID)) if (!OidIsValid(opfID))
return NULL; htup = NULL;
return SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfID)); else
htup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfID));
}
if (!HeapTupleIsValid(htup) && !missing_ok)
{
HeapTuple amtup;
amtup = SearchSysCache1(AMOID, ObjectIdGetDatum(amID));
if (!HeapTupleIsValid(amtup))
elog(ERROR, "cache lookup failed for access method %u", amID);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator family \"%s\" does not exist for access method \"%s\"",
NameListToString(opfamilyname),
NameStr(((Form_pg_am) GETSTRUCT(amtup))->amname))));
} }
return htup;
}
/*
* get_opfamily_oid
* find an opfamily OID by possibly qualified name
*
* If not found, returns InvalidOid if missing_ok, else throws error.
*/
Oid
get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok)
{
HeapTuple htup;
Oid opfID;
htup = OpFamilyCacheLookup(amID, opfamilyname, missing_ok);
if (!HeapTupleIsValid(htup))
return InvalidOid;
opfID = HeapTupleGetOid(htup);
ReleaseSysCache(htup);
return opfID;
} }
/* /*
...@@ -127,10 +166,11 @@ OpFamilyCacheLookup(Oid amID, List *opfamilyname) ...@@ -127,10 +166,11 @@ OpFamilyCacheLookup(Oid amID, List *opfamilyname)
* Returns a syscache tuple reference, or NULL if not found. * Returns a syscache tuple reference, or NULL if not found.
*/ */
static HeapTuple static HeapTuple
OpClassCacheLookup(Oid amID, List *opclassname) OpClassCacheLookup(Oid amID, List *opclassname, bool missing_ok)
{ {
char *schemaname; char *schemaname;
char *opcname; char *opcname;
HeapTuple htup;
/* deconstruct the name list */ /* deconstruct the name list */
DeconstructQualifiedName(opclassname, &schemaname, &opcname); DeconstructQualifiedName(opclassname, &schemaname, &opcname);
...@@ -141,7 +181,7 @@ OpClassCacheLookup(Oid amID, List *opclassname) ...@@ -141,7 +181,7 @@ OpClassCacheLookup(Oid amID, List *opclassname)
Oid namespaceId; Oid namespaceId;
namespaceId = LookupExplicitNamespace(schemaname); namespaceId = LookupExplicitNamespace(schemaname);
return SearchSysCache3(CLAAMNAMENSP, htup = SearchSysCache3(CLAAMNAMENSP,
ObjectIdGetDatum(amID), ObjectIdGetDatum(amID),
PointerGetDatum(opcname), PointerGetDatum(opcname),
ObjectIdGetDatum(namespaceId)); ObjectIdGetDatum(namespaceId));
...@@ -152,9 +192,47 @@ OpClassCacheLookup(Oid amID, List *opclassname) ...@@ -152,9 +192,47 @@ OpClassCacheLookup(Oid amID, List *opclassname)
Oid opcID = OpclassnameGetOpcid(amID, opcname); Oid opcID = OpclassnameGetOpcid(amID, opcname);
if (!OidIsValid(opcID)) if (!OidIsValid(opcID))
return NULL; htup = NULL;
return SearchSysCache1(CLAOID, ObjectIdGetDatum(opcID)); else
htup = SearchSysCache1(CLAOID, ObjectIdGetDatum(opcID));
}
if (!HeapTupleIsValid(htup) && !missing_ok)
{
HeapTuple amtup;
amtup = SearchSysCache1(AMOID, ObjectIdGetDatum(amID));
if (!HeapTupleIsValid(amtup))
elog(ERROR, "cache lookup failed for access method %u", amID);
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
NameListToString(opclassname),
NameStr(((Form_pg_am) GETSTRUCT(amtup))->amname))));
} }
return htup;
}
/*
* get_opclass_oid
* find an opclass OID by possibly qualified name
*
* If not found, returns InvalidOid if missing_ok, else throws error.
*/
Oid
get_opclass_oid(Oid amID, List *opclassname, bool missing_ok)
{
HeapTuple htup;
Oid opcID;
htup = OpClassCacheLookup(amID, opclassname, missing_ok);
if (!HeapTupleIsValid(htup))
return InvalidOid;
opcID = HeapTupleGetOid(htup);
ReleaseSysCache(htup);
return opcID;
} }
/* /*
...@@ -336,19 +414,7 @@ DefineOpClass(CreateOpClassStmt *stmt) ...@@ -336,19 +414,7 @@ DefineOpClass(CreateOpClassStmt *stmt)
*/ */
if (stmt->opfamilyname) if (stmt->opfamilyname)
{ {
tup = OpFamilyCacheLookup(amoid, stmt->opfamilyname); opfamilyoid = get_opfamily_oid(amoid, stmt->opfamilyname, false);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator family \"%s\" does not exist for access method \"%s\"",
NameListToString(stmt->opfamilyname), stmt->amname)));
opfamilyoid = HeapTupleGetOid(tup);
/*
* XXX given the superuser check above, there's no need for an
* ownership check here
*/
ReleaseSysCache(tup);
} }
else else
{ {
...@@ -711,14 +777,7 @@ AlterOpFamily(AlterOpFamilyStmt *stmt) ...@@ -711,14 +777,7 @@ AlterOpFamily(AlterOpFamilyStmt *stmt)
ReleaseSysCache(tup); ReleaseSysCache(tup);
/* Look up the opfamily */ /* Look up the opfamily */
tup = OpFamilyCacheLookup(amoid, stmt->opfamilyname); opfamilyoid = get_opfamily_oid(amoid, stmt->opfamilyname, false);
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator family \"%s\" does not exist for access method \"%s\"",
NameListToString(stmt->opfamilyname), stmt->amname)));
opfamilyoid = HeapTupleGetOid(tup);
ReleaseSysCache(tup);
/* /*
* Currently, we require superuser privileges to alter an opfamily. * Currently, we require superuser privileges to alter an opfamily.
...@@ -1414,26 +1473,16 @@ RemoveOpClass(RemoveOpClassStmt *stmt) ...@@ -1414,26 +1473,16 @@ RemoveOpClass(RemoveOpClassStmt *stmt)
HeapTuple tuple; HeapTuple tuple;
ObjectAddress object; ObjectAddress object;
/* /* Get the access method's OID. */
* Get the access method's OID.
*/
amID = get_am_oid(stmt->amname, false); amID = get_am_oid(stmt->amname, false);
/* /* Look up the opclass. */
* Look up the opclass. tuple = OpClassCacheLookup(amID, stmt->opclassname, stmt->missing_ok);
*/
tuple = OpClassCacheLookup(amID, stmt->opclassname);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
if (!stmt->missing_ok) ereport(NOTICE,
ereport(ERROR, (errmsg("operator class \"%s\" does not exist for access method \"%s\"",
(errcode(ERRCODE_UNDEFINED_OBJECT), NameListToString(stmt->opclassname), stmt->amname)));
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
NameListToString(stmt->opclassname), stmt->amname)));
else
ereport(NOTICE,
(errmsg("operator class \"%s\" does not exist for access method \"%s\"",
NameListToString(stmt->opclassname), stmt->amname)));
return; return;
} }
...@@ -1478,18 +1527,13 @@ RemoveOpFamily(RemoveOpFamilyStmt *stmt) ...@@ -1478,18 +1527,13 @@ RemoveOpFamily(RemoveOpFamilyStmt *stmt)
/* /*
* Look up the opfamily. * Look up the opfamily.
*/ */
tuple = OpFamilyCacheLookup(amID, stmt->opfamilyname); tuple = OpFamilyCacheLookup(amID, stmt->opfamilyname, stmt->missing_ok);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ {
if (!stmt->missing_ok) ereport(ERROR,
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_OBJECT),
(errcode(ERRCODE_UNDEFINED_OBJECT), errmsg("operator family \"%s\" does not exist for access method \"%s\"",
errmsg("operator family \"%s\" does not exist for access method \"%s\"", NameListToString(stmt->opfamilyname), stmt->amname)));
NameListToString(stmt->opfamilyname), stmt->amname)));
else
ereport(NOTICE,
(errmsg("operator family \"%s\" does not exist for access method \"%s\"",
NameListToString(stmt->opfamilyname), stmt->amname)));
return; return;
} }
...@@ -1624,8 +1668,7 @@ RenameOpClass(List *name, const char *access_method, const char *newname) ...@@ -1624,8 +1668,7 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
Oid opcOid; Oid opcOid;
Oid amOid; Oid amOid;
Oid namespaceOid; Oid namespaceOid;
char *schemaname; HeapTuple origtup;
char *opcname;
HeapTuple tup; HeapTuple tup;
Relation rel; Relation rel;
AclResult aclresult; AclResult aclresult;
...@@ -1634,42 +1677,12 @@ RenameOpClass(List *name, const char *access_method, const char *newname) ...@@ -1634,42 +1677,12 @@ RenameOpClass(List *name, const char *access_method, const char *newname)
rel = heap_open(OperatorClassRelationId, RowExclusiveLock); rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
/* /* Look up the opclass. */
* Look up the opclass origtup = OpClassCacheLookup(amOid, name, false);
*/ tup = heap_copytuple(origtup);
DeconstructQualifiedName(name, &schemaname, &opcname); ReleaseSysCache(origtup);
opcOid = HeapTupleGetOid(tup);
if (schemaname) namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
{
namespaceOid = LookupExplicitNamespace(schemaname);
tup = SearchSysCacheCopy3(CLAAMNAMENSP,
ObjectIdGetDatum(amOid),
PointerGetDatum(opcname),
ObjectIdGetDatum(namespaceOid));
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
opcname, access_method)));
opcOid = HeapTupleGetOid(tup);
}
else
{
opcOid = OpclassnameGetOpcid(amOid, opcname);
if (!OidIsValid(opcOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
opcname, access_method)));
tup = SearchSysCacheCopy1(CLAOID, ObjectIdGetDatum(opcOid));
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for opclass %u", opcOid);
namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
}
/* make sure the new name doesn't exist */ /* make sure the new name doesn't exist */
if (SearchSysCacheExists3(CLAAMNAMENSP, if (SearchSysCacheExists3(CLAAMNAMENSP,
...@@ -1802,49 +1815,16 @@ AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId) ...@@ -1802,49 +1815,16 @@ AlterOpClassOwner(List *name, const char *access_method, Oid newOwnerId)
Oid amOid; Oid amOid;
Relation rel; Relation rel;
HeapTuple tup; HeapTuple tup;
char *opcname; HeapTuple origtup;
char *schemaname;
amOid = get_am_oid(access_method, false); amOid = get_am_oid(access_method, false);
rel = heap_open(OperatorClassRelationId, RowExclusiveLock); rel = heap_open(OperatorClassRelationId, RowExclusiveLock);
/* /* Look up the opclass. */
* Look up the opclass origtup = OpClassCacheLookup(amOid, name, false);
*/ tup = heap_copytuple(origtup);
DeconstructQualifiedName(name, &schemaname, &opcname); ReleaseSysCache(origtup);
if (schemaname)
{
Oid namespaceOid;
namespaceOid = LookupExplicitNamespace(schemaname);
tup = SearchSysCacheCopy3(CLAAMNAMENSP,
ObjectIdGetDatum(amOid),
PointerGetDatum(opcname),
ObjectIdGetDatum(namespaceOid));
if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
opcname, access_method)));
}
else
{
Oid opcOid;
opcOid = OpclassnameGetOpcid(amOid, opcname);
if (!OidIsValid(opcOid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("operator class \"%s\" does not exist for access method \"%s\"",
opcname, access_method)));
tup = SearchSysCacheCopy1(CLAOID, ObjectIdGetDatum(opcOid));
if (!HeapTupleIsValid(tup)) /* should not happen */
elog(ERROR, "cache lookup failed for opclass %u", opcOid);
}
AlterOpClassOwner_internal(rel, tup, newOwnerId); AlterOpClassOwner_internal(rel, tup, newOwnerId);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.263 2010/07/28 05:22:24 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.264 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -967,46 +967,17 @@ void ...@@ -967,46 +967,17 @@ void
DropTrigger(Oid relid, const char *trigname, DropBehavior behavior, DropTrigger(Oid relid, const char *trigname, DropBehavior behavior,
bool missing_ok) bool missing_ok)
{ {
Relation tgrel;
ScanKeyData skey[2];
SysScanDesc tgscan;
HeapTuple tup;
ObjectAddress object; ObjectAddress object;
/* object.classId = TriggerRelationId;
* Find the trigger, verify permissions, set up object address object.objectId = get_trigger_oid(relid, trigname, missing_ok);
*/ object.objectSubId = 0;
tgrel = heap_open(TriggerRelationId, AccessShareLock);
ScanKeyInit(&skey[0],
Anum_pg_trigger_tgrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(relid));
ScanKeyInit(&skey[1],
Anum_pg_trigger_tgname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(trigname));
tgscan = systable_beginscan(tgrel, TriggerRelidNameIndexId, true,
SnapshotNow, 2, skey);
tup = systable_getnext(tgscan);
if (!HeapTupleIsValid(tup)) if (!OidIsValid(object.objectId))
{ {
if (!missing_ok) ereport(NOTICE,
ereport(ERROR, (errmsg("trigger \"%s\" for table \"%s\" does not exist, skipping",
(errcode(ERRCODE_UNDEFINED_OBJECT), trigname, get_rel_name(relid))));
errmsg("trigger \"%s\" for table \"%s\" does not exist",
trigname, get_rel_name(relid))));
else
ereport(NOTICE,
(errmsg("trigger \"%s\" for table \"%s\" does not exist, skipping",
trigname, get_rel_name(relid))));
/* cleanup */
systable_endscan(tgscan);
heap_close(tgrel, AccessShareLock);
return; return;
} }
...@@ -1014,13 +985,6 @@ DropTrigger(Oid relid, const char *trigname, DropBehavior behavior, ...@@ -1014,13 +985,6 @@ DropTrigger(Oid relid, const char *trigname, DropBehavior behavior,
aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS, aclcheck_error(ACLCHECK_NOT_OWNER, ACL_KIND_CLASS,
get_rel_name(relid)); get_rel_name(relid));
object.classId = TriggerRelationId;
object.objectId = HeapTupleGetOid(tup);
object.objectSubId = 0;
systable_endscan(tgscan);
heap_close(tgrel, AccessShareLock);
/* /*
* Do the deletion * Do the deletion
*/ */
...@@ -1102,6 +1066,59 @@ RemoveTriggerById(Oid trigOid) ...@@ -1102,6 +1066,59 @@ RemoveTriggerById(Oid trigOid)
heap_close(rel, NoLock); heap_close(rel, NoLock);
} }
/*
* get_trigger_oid - Look up a trigger by name to find its OID.
*
* If missing_ok is false, throw an error if trigger not found. If
* true, just return InvalidOid.
*/
Oid
get_trigger_oid(Oid relid, const char *trigname, bool missing_ok)
{
Relation tgrel;
ScanKeyData skey[2];
SysScanDesc tgscan;
HeapTuple tup;
Oid oid;
/*
* Find the trigger, verify permissions, set up object address
*/
tgrel = heap_open(TriggerRelationId, AccessShareLock);
ScanKeyInit(&skey[0],
Anum_pg_trigger_tgrelid,
BTEqualStrategyNumber, F_OIDEQ,
ObjectIdGetDatum(relid));
ScanKeyInit(&skey[1],
Anum_pg_trigger_tgname,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(trigname));
tgscan = systable_beginscan(tgrel, TriggerRelidNameIndexId, true,
SnapshotNow, 2, skey);
tup = systable_getnext(tgscan);
if (!HeapTupleIsValid(tup))
{
if (!missing_ok)
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("trigger \"%s\" for table \"%s\" does not exist",
trigname, get_rel_name(relid))));
oid = InvalidOid;
}
else
{
oid = HeapTupleGetOid(tup);
}
systable_endscan(tgscan);
heap_close(tgrel, AccessShareLock);
return oid;
}
/* /*
* renametrig - changes the name of a trigger on a relation * renametrig - changes the name of a trigger on a relation
* *
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.20 2010/02/14 18:42:14 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/commands/tsearchcmds.c,v 1.21 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -295,7 +295,7 @@ RemoveTSParsers(DropStmt *drop) ...@@ -295,7 +295,7 @@ RemoveTSParsers(DropStmt *drop)
Oid prsOid; Oid prsOid;
ObjectAddress object; ObjectAddress object;
prsOid = TSParserGetPrsid(names, true); prsOid = get_ts_parser_oid(names, true);
if (!OidIsValid(prsOid)) if (!OidIsValid(prsOid))
{ {
...@@ -368,7 +368,7 @@ RenameTSParser(List *oldname, const char *newname) ...@@ -368,7 +368,7 @@ RenameTSParser(List *oldname, const char *newname)
rel = heap_open(TSParserRelationId, RowExclusiveLock); rel = heap_open(TSParserRelationId, RowExclusiveLock);
prsId = TSParserGetPrsid(oldname, false); prsId = get_ts_parser_oid(oldname, false);
tup = SearchSysCacheCopy1(TSPARSEROID, ObjectIdGetDatum(prsId)); tup = SearchSysCacheCopy1(TSPARSEROID, ObjectIdGetDatum(prsId));
...@@ -517,7 +517,7 @@ DefineTSDictionary(List *names, List *parameters) ...@@ -517,7 +517,7 @@ DefineTSDictionary(List *names, List *parameters)
if (pg_strcasecmp(defel->defname, "template") == 0) if (pg_strcasecmp(defel->defname, "template") == 0)
{ {
templId = TSTemplateGetTmplid(defGetQualifiedName(defel), false); templId = get_ts_template_oid(defGetQualifiedName(defel), false);
} }
else else
{ {
...@@ -582,7 +582,7 @@ RenameTSDictionary(List *oldname, const char *newname) ...@@ -582,7 +582,7 @@ RenameTSDictionary(List *oldname, const char *newname)
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock); rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
dictId = TSDictionaryGetDictid(oldname, false); dictId = get_ts_dict_oid(oldname, false);
tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId)); tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
...@@ -643,7 +643,7 @@ RemoveTSDictionaries(DropStmt *drop) ...@@ -643,7 +643,7 @@ RemoveTSDictionaries(DropStmt *drop)
HeapTuple tup; HeapTuple tup;
Oid namespaceId; Oid namespaceId;
dictOid = TSDictionaryGetDictid(names, true); dictOid = get_ts_dict_oid(names, true);
if (!OidIsValid(dictOid)) if (!OidIsValid(dictOid))
{ {
...@@ -731,7 +731,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt) ...@@ -731,7 +731,7 @@ AlterTSDictionary(AlterTSDictionaryStmt *stmt)
bool repl_null[Natts_pg_ts_dict]; bool repl_null[Natts_pg_ts_dict];
bool repl_repl[Natts_pg_ts_dict]; bool repl_repl[Natts_pg_ts_dict];
dictId = TSDictionaryGetDictid(stmt->dictname, false); dictId = get_ts_dict_oid(stmt->dictname, false);
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock); rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
...@@ -841,7 +841,7 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId) ...@@ -841,7 +841,7 @@ AlterTSDictionaryOwner(List *name, Oid newOwnerId)
rel = heap_open(TSDictionaryRelationId, RowExclusiveLock); rel = heap_open(TSDictionaryRelationId, RowExclusiveLock);
dictId = TSDictionaryGetDictid(name, false); dictId = get_ts_dict_oid(name, false);
tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId)); tup = SearchSysCacheCopy1(TSDICTOID, ObjectIdGetDatum(dictId));
...@@ -1073,7 +1073,7 @@ RenameTSTemplate(List *oldname, const char *newname) ...@@ -1073,7 +1073,7 @@ RenameTSTemplate(List *oldname, const char *newname)
rel = heap_open(TSTemplateRelationId, RowExclusiveLock); rel = heap_open(TSTemplateRelationId, RowExclusiveLock);
tmplId = TSTemplateGetTmplid(oldname, false); tmplId = get_ts_template_oid(oldname, false);
tup = SearchSysCacheCopy1(TSTEMPLATEOID, ObjectIdGetDatum(tmplId)); tup = SearchSysCacheCopy1(TSTEMPLATEOID, ObjectIdGetDatum(tmplId));
...@@ -1126,7 +1126,7 @@ RemoveTSTemplates(DropStmt *drop) ...@@ -1126,7 +1126,7 @@ RemoveTSTemplates(DropStmt *drop)
Oid tmplOid; Oid tmplOid;
ObjectAddress object; ObjectAddress object;
tmplOid = TSTemplateGetTmplid(names, true); tmplOid = get_ts_template_oid(names, true);
if (!OidIsValid(tmplOid)) if (!OidIsValid(tmplOid))
{ {
...@@ -1194,7 +1194,7 @@ GetTSConfigTuple(List *names) ...@@ -1194,7 +1194,7 @@ GetTSConfigTuple(List *names)
HeapTuple tup; HeapTuple tup;
Oid cfgId; Oid cfgId;
cfgId = TSConfigGetCfgid(names, true); cfgId = get_ts_config_oid(names, true);
if (!OidIsValid(cfgId)) if (!OidIsValid(cfgId))
return NULL; return NULL;
...@@ -1329,9 +1329,9 @@ DefineTSConfiguration(List *names, List *parameters) ...@@ -1329,9 +1329,9 @@ DefineTSConfiguration(List *names, List *parameters)
DefElem *defel = (DefElem *) lfirst(pl); DefElem *defel = (DefElem *) lfirst(pl);
if (pg_strcasecmp(defel->defname, "parser") == 0) if (pg_strcasecmp(defel->defname, "parser") == 0)
prsOid = TSParserGetPrsid(defGetQualifiedName(defel), false); prsOid = get_ts_parser_oid(defGetQualifiedName(defel), false);
else if (pg_strcasecmp(defel->defname, "copy") == 0) else if (pg_strcasecmp(defel->defname, "copy") == 0)
sourceOid = TSConfigGetCfgid(defGetQualifiedName(defel), false); sourceOid = get_ts_config_oid(defGetQualifiedName(defel), false);
else else
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR), (errcode(ERRCODE_SYNTAX_ERROR),
...@@ -1461,7 +1461,7 @@ RenameTSConfiguration(List *oldname, const char *newname) ...@@ -1461,7 +1461,7 @@ RenameTSConfiguration(List *oldname, const char *newname)
rel = heap_open(TSConfigRelationId, RowExclusiveLock); rel = heap_open(TSConfigRelationId, RowExclusiveLock);
cfgId = TSConfigGetCfgid(oldname, false); cfgId = get_ts_config_oid(oldname, false);
tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId)); tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
...@@ -1626,7 +1626,7 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId) ...@@ -1626,7 +1626,7 @@ AlterTSConfigurationOwner(List *name, Oid newOwnerId)
rel = heap_open(TSConfigRelationId, RowExclusiveLock); rel = heap_open(TSConfigRelationId, RowExclusiveLock);
cfgId = TSConfigGetCfgid(name, false); cfgId = get_ts_config_oid(name, false);
tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId)); tup = SearchSysCacheCopy1(TSCONFIGOID, ObjectIdGetDatum(cfgId));
...@@ -1828,7 +1828,7 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt, ...@@ -1828,7 +1828,7 @@ MakeConfigurationMapping(AlterTSConfigurationStmt *stmt,
{ {
List *names = (List *) lfirst(c); List *names = (List *) lfirst(c);
dictIds[i] = TSDictionaryGetDictid(names, false); dictIds[i] = get_ts_dict_oid(names, false);
i++; i++;
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.41 2010/07/28 05:22:24 sriggs Exp $ * $PostgreSQL: pgsql/src/backend/parser/parse_utilcmd.c,v 2.42 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -713,8 +713,8 @@ transformInhRelation(ParseState *pstate, CreateStmtContext *cxt, ...@@ -713,8 +713,8 @@ transformInhRelation(ParseState *pstate, CreateStmtContext *cxt,
/* Copy comment on constraint */ /* Copy comment on constraint */
if ((inhRelation->options & CREATE_TABLE_LIKE_COMMENTS) && if ((inhRelation->options & CREATE_TABLE_LIKE_COMMENTS) &&
(comment = GetComment(GetConstraintByName(RelationGetRelid(relation), (comment = GetComment(get_constraint_oid(RelationGetRelid(relation),
n->conname), n->conname, false),
ConstraintRelationId, ConstraintRelationId,
0)) != NULL) 0)) != NULL)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteSupport.c,v 1.69 2010/02/14 18:42:15 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteSupport.c,v 1.70 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,9 +17,14 @@ ...@@ -17,9 +17,14 @@
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/pg_class.h" #include "catalog/pg_class.h"
#include "catalog/pg_rewrite.h"
#include "rewrite/rewriteSupport.h" #include "rewrite/rewriteSupport.h"
#include "utils/fmgroids.h"
#include "utils/inval.h" #include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/tqual.h"
/* /*
...@@ -86,3 +91,82 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules, ...@@ -86,3 +91,82 @@ SetRelationRuleStatus(Oid relationId, bool relHasRules,
heap_freetuple(tuple); heap_freetuple(tuple);
heap_close(relationRelation, RowExclusiveLock); heap_close(relationRelation, RowExclusiveLock);
} }
/*
* Find rule oid.
*
* If missing_ok is false, throw an error if rule name not found. If
* true, just return InvalidOid.
*/
Oid
get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
{
HeapTuple tuple;
Oid ruleoid;
/* Find the rule's pg_rewrite tuple, get its OID */
tuple = SearchSysCache2(RULERELNAME,
ObjectIdGetDatum(relid),
PointerGetDatum(rulename));
if (!HeapTupleIsValid(tuple))
{
if (missing_ok)
return InvalidOid;
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" for relation \"%s\" does not exist",
rulename, get_rel_name(relid))));
}
Assert(relid == ((Form_pg_rewrite) GETSTRUCT(tuple))->ev_class);
ruleoid = HeapTupleGetOid(tuple);
ReleaseSysCache(tuple);
return ruleoid;
}
/*
* Find rule oid, given only a rule name but no rel OID.
*
* If there's more than one, it's an error. If there aren't any, that's an
* error, too. In general, this should be avoided - it is provided to support
* syntax that is compatible with pre-7.3 versions of PG, where rule names
* were unique across the entire database.
*/
Oid
get_rewrite_oid_without_relid(const char *rulename, Oid *reloid)
{
Relation RewriteRelation;
HeapScanDesc scanDesc;
ScanKeyData scanKeyData;
HeapTuple htup;
Oid ruleoid;
/* Search pg_rewrite for such a rule */
ScanKeyInit(&scanKeyData,
Anum_pg_rewrite_rulename,
BTEqualStrategyNumber, F_NAMEEQ,
CStringGetDatum(rulename));
RewriteRelation = heap_open(RewriteRelationId, AccessShareLock);
scanDesc = heap_beginscan(RewriteRelation, SnapshotNow, 1, &scanKeyData);
htup = heap_getnext(scanDesc, ForwardScanDirection);
if (!HeapTupleIsValid(htup))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("rule \"%s\" does not exist", rulename)));
ruleoid = HeapTupleGetOid(htup);
if (reloid != NULL)
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
if (HeapTupleIsValid(htup = heap_getnext(scanDesc, ForwardScanDirection)))
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("there are multiple rules named \"%s\"", rulename),
errhint("Specify a relation name as well as a rule name.")));
heap_endscan(scanDesc);
heap_close(RewriteRelation, AccessShareLock);
return ruleoid;
}
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tsearch/dict_thesaurus.c,v 1.16 2010/01/02 16:57:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/tsearch/dict_thesaurus.c,v 1.17 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -642,7 +642,7 @@ thesaurus_init(PG_FUNCTION_ARGS) ...@@ -642,7 +642,7 @@ thesaurus_init(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("missing Dictionary parameter"))); errmsg("missing Dictionary parameter")));
d->subdictOid = TSDictionaryGetDictid(stringToQualifiedNameList(subdictname), false); d->subdictOid = get_ts_dict_oid(stringToQualifiedNameList(subdictname), false);
d->subdict = lookup_ts_dictionary_cache(d->subdictOid); d->subdict = lookup_ts_dictionary_cache(d->subdictOid);
compileTheLexeme(d); compileTheLexeme(d);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/tsearch/wparser.c,v 1.12 2010/01/02 16:57:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/tsearch/wparser.c,v 1.13 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -134,7 +134,7 @@ ts_token_type_byname(PG_FUNCTION_ARGS) ...@@ -134,7 +134,7 @@ ts_token_type_byname(PG_FUNCTION_ARGS)
Oid prsId; Oid prsId;
funcctx = SRF_FIRSTCALL_INIT(); funcctx = SRF_FIRSTCALL_INIT();
prsId = TSParserGetPrsid(textToQualifiedNameList(prsname), false); prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
tt_setup_firstcall(funcctx, prsId); tt_setup_firstcall(funcctx, prsId);
} }
...@@ -282,7 +282,7 @@ ts_parse_byname(PG_FUNCTION_ARGS) ...@@ -282,7 +282,7 @@ ts_parse_byname(PG_FUNCTION_ARGS)
Oid prsId; Oid prsId;
funcctx = SRF_FIRSTCALL_INIT(); funcctx = SRF_FIRSTCALL_INIT();
prsId = TSParserGetPrsid(textToQualifiedNameList(prsname), false); prsId = get_ts_parser_oid(textToQualifiedNameList(prsname), false);
prs_setup_firstcall(funcctx, prsId, txt); prs_setup_firstcall(funcctx, prsId, txt);
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.113 2010/02/14 18:42:16 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/regproc.c,v 1.114 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1096,7 +1096,7 @@ regconfigin(PG_FUNCTION_ARGS) ...@@ -1096,7 +1096,7 @@ regconfigin(PG_FUNCTION_ARGS)
*/ */
names = stringToQualifiedNameList(cfg_name_or_oid); names = stringToQualifiedNameList(cfg_name_or_oid);
result = TSConfigGetCfgid(names, false); result = get_ts_config_oid(names, false);
PG_RETURN_OID(result); PG_RETURN_OID(result);
} }
...@@ -1206,7 +1206,7 @@ regdictionaryin(PG_FUNCTION_ARGS) ...@@ -1206,7 +1206,7 @@ regdictionaryin(PG_FUNCTION_ARGS)
*/ */
names = stringToQualifiedNameList(dict_name_or_oid); names = stringToQualifiedNameList(dict_name_or_oid);
result = TSDictionaryGetDictid(names, false); result = get_ts_dict_oid(names, false);
PG_RETURN_OID(result); PG_RETURN_OID(result);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.26 2010/01/02 16:57:55 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/tsvector_op.c,v 1.27 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1326,7 +1326,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column) ...@@ -1326,7 +1326,7 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE), (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("text search configuration name \"%s\" must be schema-qualified", errmsg("text search configuration name \"%s\" must be schema-qualified",
trigger->tgargs[1]))); trigger->tgargs[1])));
cfgId = TSConfigGetCfgid(names, false); cfgId = get_ts_config_oid(names, false);
} }
/* initialize parse state */ /* initialize parse state */
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* Copyright (c) 2006-2010, PostgreSQL Global Development Group * Copyright (c) 2006-2010, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/cache/ts_cache.c,v 1.12 2010/02/14 18:42:17 rhaas Exp $ * $PostgreSQL: pgsql/src/backend/utils/cache/ts_cache.c,v 1.13 2010/08/05 15:25:35 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -581,7 +581,7 @@ getTSCurrentConfig(bool emitError) ...@@ -581,7 +581,7 @@ getTSCurrentConfig(bool emitError)
/* Look up the config */ /* Look up the config */
TSCurrentConfigCache = TSCurrentConfigCache =
TSConfigGetCfgid(stringToQualifiedNameList(TSCurrentConfig), get_ts_config_oid(stringToQualifiedNameList(TSCurrentConfig),
!emitError); !emitError);
return TSCurrentConfigCache; return TSCurrentConfigCache;
...@@ -601,7 +601,7 @@ assignTSCurrentConfig(const char *newval, bool doit, GucSource source) ...@@ -601,7 +601,7 @@ assignTSCurrentConfig(const char *newval, bool doit, GucSource source)
Form_pg_ts_config cfg; Form_pg_ts_config cfg;
char *buf; char *buf;
cfgId = TSConfigGetCfgid(stringToQualifiedNameList(newval), true); cfgId = get_ts_config_oid(stringToQualifiedNameList(newval), true);
if (!OidIsValid(cfgId)) if (!OidIsValid(cfgId))
return NULL; return NULL;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.63 2010/08/05 14:45:06 rhaas Exp $ * $PostgreSQL: pgsql/src/include/catalog/namespace.h,v 1.64 2010/08/05 15:25:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -74,16 +74,16 @@ extern bool OpfamilyIsVisible(Oid opfid); ...@@ -74,16 +74,16 @@ extern bool OpfamilyIsVisible(Oid opfid);
extern Oid ConversionGetConid(const char *conname); extern Oid ConversionGetConid(const char *conname);
extern bool ConversionIsVisible(Oid conid); extern bool ConversionIsVisible(Oid conid);
extern Oid TSParserGetPrsid(List *names, bool failOK); extern Oid get_ts_parser_oid(List *names, bool missing_ok);
extern bool TSParserIsVisible(Oid prsId); extern bool TSParserIsVisible(Oid prsId);
extern Oid TSDictionaryGetDictid(List *names, bool failOK); extern Oid get_ts_dict_oid(List *names, bool missing_ok);
extern bool TSDictionaryIsVisible(Oid dictId); extern bool TSDictionaryIsVisible(Oid dictId);
extern Oid TSTemplateGetTmplid(List *names, bool failOK); extern Oid get_ts_template_oid(List *names, bool missing_ok);
extern bool TSTemplateIsVisible(Oid tmplId); extern bool TSTemplateIsVisible(Oid tmplId);
extern Oid TSConfigGetCfgid(List *names, bool failOK); extern Oid get_ts_config_oid(List *names, bool missing_ok);
extern bool TSConfigIsVisible(Oid cfgid); extern bool TSConfigIsVisible(Oid cfgid);
extern void DeconstructQualifiedName(List *names, extern void DeconstructQualifiedName(List *names,
...@@ -112,7 +112,7 @@ extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context); ...@@ -112,7 +112,7 @@ extern OverrideSearchPath *GetOverrideSearchPath(MemoryContext context);
extern void PushOverrideSearchPath(OverrideSearchPath *newpath); extern void PushOverrideSearchPath(OverrideSearchPath *newpath);
extern void PopOverrideSearchPath(void); extern void PopOverrideSearchPath(void);
extern Oid FindConversionByName(List *conname); extern Oid get_conversion_oid(List *conname, bool missing_ok);
extern Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding); extern Oid FindDefaultConversionProc(int4 for_encoding, int4 to_encoding);
/* initialization & transaction cleanup code */ /* initialization & transaction cleanup code */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/pg_constraint.h,v 1.39 2010/03/11 03:36:22 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/pg_constraint.h,v 1.40 2010/08/05 15:25:36 rhaas Exp $
* *
* NOTES * NOTES
* the genbki.pl script reads this file and generates .bki * the genbki.pl script reads this file and generates .bki
...@@ -237,6 +237,6 @@ extern char *ChooseConstraintName(const char *name1, const char *name2, ...@@ -237,6 +237,6 @@ extern char *ChooseConstraintName(const char *name1, const char *name2,
extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId, extern void AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
Oid newNspId, bool isType); Oid newNspId, bool isType);
extern Oid GetConstraintByName(Oid relid, const char *conname); extern Oid get_constraint_oid(Oid relid, const char *conname, bool missing_ok);
#endif /* PG_CONSTRAINT_H */ #endif /* PG_CONSTRAINT_H */
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.103 2010/08/05 14:45:07 rhaas Exp $ * $PostgreSQL: pgsql/src/include/commands/defrem.h,v 1.104 2010/08/05 15:25:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -67,6 +67,7 @@ extern void DropCastById(Oid castOid); ...@@ -67,6 +67,7 @@ extern void DropCastById(Oid castOid);
extern void AlterFunctionNamespace(List *name, List *argtypes, bool isagg, extern void AlterFunctionNamespace(List *name, List *argtypes, bool isagg,
const char *newschema); const char *newschema);
extern void ExecuteDoStmt(DoStmt *stmt); extern void ExecuteDoStmt(DoStmt *stmt);
extern Oid get_cast_oid(Oid sourcetypeid, Oid targettypeid, bool missing_ok);
/* commands/operatorcmds.c */ /* commands/operatorcmds.c */
extern void DefineOperator(List *names, List *parameters); extern void DefineOperator(List *names, List *parameters);
...@@ -75,6 +76,8 @@ extern void RemoveOperatorById(Oid operOid); ...@@ -75,6 +76,8 @@ extern void RemoveOperatorById(Oid operOid);
extern void AlterOperatorOwner(List *name, TypeName *typeName1, extern void AlterOperatorOwner(List *name, TypeName *typeName1,
TypeName *typename2, Oid newOwnerId); TypeName *typename2, Oid newOwnerId);
extern void AlterOperatorOwner_oid(Oid operOid, Oid newOwnerId); extern void AlterOperatorOwner_oid(Oid operOid, Oid newOwnerId);
extern Oid get_opclass_oid(Oid amID, List *opclassname, bool missing_ok);
extern Oid get_opfamily_oid(Oid amID, List *opfamilyname, bool missing_ok);
/* commands/aggregatecmds.c */ /* commands/aggregatecmds.c */
extern void DefineAggregate(List *name, List *args, bool oldstyle, extern void DefineAggregate(List *name, List *args, bool oldstyle,
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.80 2010/01/17 22:56:23 tgl Exp $ * $PostgreSQL: pgsql/src/include/commands/trigger.h,v 1.81 2010/08/05 15:25:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -111,6 +111,7 @@ extern Oid CreateTrigger(CreateTrigStmt *stmt, const char *queryString, ...@@ -111,6 +111,7 @@ extern Oid CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
extern void DropTrigger(Oid relid, const char *trigname, extern void DropTrigger(Oid relid, const char *trigname,
DropBehavior behavior, bool missing_ok); DropBehavior behavior, bool missing_ok);
extern void RemoveTriggerById(Oid trigOid); extern void RemoveTriggerById(Oid trigOid);
extern Oid get_trigger_oid(Oid relid, const char *name, bool missing_ok);
extern void renametrig(Oid relid, const char *oldname, const char *newname); extern void renametrig(Oid relid, const char *oldname, const char *newname);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/rewrite/rewriteSupport.h,v 1.32 2010/01/02 16:58:08 momjian Exp $ * $PostgreSQL: pgsql/src/include/rewrite/rewriteSupport.h,v 1.33 2010/08/05 15:25:36 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,4 +22,7 @@ extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName); ...@@ -22,4 +22,7 @@ extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName);
extern void SetRelationRuleStatus(Oid relationId, bool relHasRules, extern void SetRelationRuleStatus(Oid relationId, bool relHasRules,
bool relIsBecomingView); bool relIsBecomingView);
extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok);
extern Oid get_rewrite_oid_without_relid(const char *rulename, Oid *relid);
#endif /* REWRITESUPPORT_H */ #endif /* REWRITESUPPORT_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment