Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e8d016d

Browse files
committed
Remove deprecated COMMENT ON RULE syntax
This was only used for allowing upgrades from pre-7.3 instances, which was a long time ago.
1 parent 9e43e87 commit e8d016d

File tree

7 files changed

+53
-148
lines changed

7 files changed

+53
-148
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 49 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,95 +1325,67 @@ get_object_address_relobject(ObjectType objtype, List *objname,
13251325
Relation relation = NULL;
13261326
int nnames;
13271327
const char *depname;
1328+
List *relname;
1329+
Oid reloid;
13281330

13291331
/* Extract name of dependent object. */
13301332
depname = strVal(llast(objname));
13311333

13321334
/* Separate relation name from dependent object name. */
13331335
nnames = list_length(objname);
13341336
if (nnames < 2)
1335-
{
1336-
Oid reloid;
1337-
1338-
/*
1339-
* For compatibility with very old releases, we sometimes allow users
1340-
* to attempt to specify a rule without mentioning the relation name.
1341-
* If there's only rule by that name in the entire database, this will
1342-
* work. But objects other than rules don't get this special
1343-
* treatment.
1344-
*/
1345-
if (objtype != OBJECT_RULE)
1346-
elog(ERROR, "must specify relation and object name");
1347-
address.classId = RewriteRelationId;
1348-
address.objectId =
1349-
get_rewrite_oid_without_relid(depname, &reloid, missing_ok);
1350-
address.objectSubId = 0;
1351-
1352-
/*
1353-
* Caller is expecting to get back the relation, even though we didn't
1354-
* end up using it to find the rule.
1355-
*/
1356-
if (OidIsValid(address.objectId))
1357-
relation = heap_open(reloid, AccessShareLock);
1358-
}
1359-
else
1360-
{
1361-
List *relname;
1362-
Oid reloid;
1337+
ereport(ERROR,
1338+
(errcode(ERRCODE_SYNTAX_ERROR),
1339+
errmsg("must specify relation and object name")));
13631340

1364-
/* Extract relation name and open relation. */
1365-
relname = list_truncate(list_copy(objname), nnames - 1);
1366-
relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
1367-
AccessShareLock,
1368-
missing_ok);
1341+
/* Extract relation name and open relation. */
1342+
relname = list_truncate(list_copy(objname), nnames - 1);
1343+
relation = heap_openrv_extended(makeRangeVarFromNameList(relname),
1344+
AccessShareLock,
1345+
missing_ok);
13691346

1370-
reloid = relation ? RelationGetRelid(relation) : InvalidOid;
1347+
reloid = relation ? RelationGetRelid(relation) : InvalidOid;
13711348

1372-
switch (objtype)
1373-
{
1374-
case OBJECT_RULE:
1375-
address.classId = RewriteRelationId;
1376-
address.objectId = relation ?
1377-
get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1378-
address.objectSubId = 0;
1379-
break;
1380-
case OBJECT_TRIGGER:
1381-
address.classId = TriggerRelationId;
1382-
address.objectId = relation ?
1383-
get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1384-
address.objectSubId = 0;
1385-
break;
1386-
case OBJECT_TABCONSTRAINT:
1387-
address.classId = ConstraintRelationId;
1388-
address.objectId = relation ?
1389-
get_relation_constraint_oid(reloid, depname, missing_ok) :
1390-
InvalidOid;
1391-
address.objectSubId = 0;
1392-
break;
1393-
case OBJECT_POLICY:
1394-
address.classId = PolicyRelationId;
1395-
address.objectId = relation ?
1396-
get_relation_policy_oid(reloid, depname, missing_ok) :
1397-
InvalidOid;
1398-
address.objectSubId = 0;
1399-
break;
1400-
default:
1401-
elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1402-
/* placate compiler, which doesn't know elog won't return */
1403-
address.classId = InvalidOid;
1404-
address.objectId = InvalidOid;
1405-
address.objectSubId = 0;
1406-
}
1349+
switch (objtype)
1350+
{
1351+
case OBJECT_RULE:
1352+
address.classId = RewriteRelationId;
1353+
address.objectId = relation ?
1354+
get_rewrite_oid(reloid, depname, missing_ok) : InvalidOid;
1355+
address.objectSubId = 0;
1356+
break;
1357+
case OBJECT_TRIGGER:
1358+
address.classId = TriggerRelationId;
1359+
address.objectId = relation ?
1360+
get_trigger_oid(reloid, depname, missing_ok) : InvalidOid;
1361+
address.objectSubId = 0;
1362+
break;
1363+
case OBJECT_TABCONSTRAINT:
1364+
address.classId = ConstraintRelationId;
1365+
address.objectId = relation ?
1366+
get_relation_constraint_oid(reloid, depname, missing_ok) :
1367+
InvalidOid;
1368+
address.objectSubId = 0;
1369+
break;
1370+
case OBJECT_POLICY:
1371+
address.classId = PolicyRelationId;
1372+
address.objectId = relation ?
1373+
get_relation_policy_oid(reloid, depname, missing_ok) :
1374+
InvalidOid;
1375+
address.objectSubId = 0;
1376+
break;
1377+
default:
1378+
elog(ERROR, "unrecognized objtype: %d", (int) objtype);
1379+
}
14071380

1408-
/* Avoid relcache leak when object not found. */
1409-
if (!OidIsValid(address.objectId))
1410-
{
1411-
if (relation != NULL)
1412-
heap_close(relation, AccessShareLock);
1381+
/* Avoid relcache leak when object not found. */
1382+
if (!OidIsValid(address.objectId))
1383+
{
1384+
if (relation != NULL)
1385+
heap_close(relation, AccessShareLock);
14131386

1414-
relation = NULL; /* department of accident prevention */
1415-
return address;
1416-
}
1387+
relation = NULL; /* department of accident prevention */
1388+
return address;
14171389
}
14181390

14191391
/* Done. */

src/backend/parser/gram.y

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6283,16 +6283,6 @@ CommentStmt:
62836283
n->comment = $8;
62846284
$$ = (Node *) n;
62856285
}
6286-
| COMMENT ON RULE name IS comment_text
6287-
{
6288-
/* Obsolete syntax supported for awhile for compatibility */
6289-
CommentStmt *n = makeNode(CommentStmt);
6290-
n->objtype = OBJECT_RULE;
6291-
n->objname = list_make1(makeString($4));
6292-
n->objargs = NIL;
6293-
n->comment = $6;
6294-
$$ = (Node *) n;
6295-
}
62966286
| COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
62976287
{
62986288
CommentStmt *n = makeNode(CommentStmt);

src/backend/rewrite/rewriteSupport.c

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -114,58 +114,3 @@ get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok)
114114
ReleaseSysCache(tuple);
115115
return ruleoid;
116116
}
117-
118-
/*
119-
* Find rule oid, given only a rule name but no rel OID.
120-
*
121-
* If there's more than one, it's an error. If there aren't any, that's an
122-
* error, too. In general, this should be avoided - it is provided to support
123-
* syntax that is compatible with pre-7.3 versions of PG, where rule names
124-
* were unique across the entire database.
125-
*/
126-
Oid
127-
get_rewrite_oid_without_relid(const char *rulename,
128-
Oid *reloid, bool missing_ok)
129-
{
130-
Relation RewriteRelation;
131-
HeapScanDesc scanDesc;
132-
ScanKeyData scanKeyData;
133-
HeapTuple htup;
134-
Oid ruleoid;
135-
136-
/* Search pg_rewrite for such a rule */
137-
ScanKeyInit(&scanKeyData,
138-
Anum_pg_rewrite_rulename,
139-
BTEqualStrategyNumber, F_NAMEEQ,
140-
CStringGetDatum(rulename));
141-
142-
RewriteRelation = heap_open(RewriteRelationId, AccessShareLock);
143-
scanDesc = heap_beginscan_catalog(RewriteRelation, 1, &scanKeyData);
144-
145-
htup = heap_getnext(scanDesc, ForwardScanDirection);
146-
if (!HeapTupleIsValid(htup))
147-
{
148-
if (!missing_ok)
149-
ereport(ERROR,
150-
(errcode(ERRCODE_UNDEFINED_OBJECT),
151-
errmsg("rule \"%s\" does not exist", rulename)));
152-
ruleoid = InvalidOid;
153-
}
154-
else
155-
{
156-
ruleoid = HeapTupleGetOid(htup);
157-
if (reloid != NULL)
158-
*reloid = ((Form_pg_rewrite) GETSTRUCT(htup))->ev_class;
159-
160-
htup = heap_getnext(scanDesc, ForwardScanDirection);
161-
if (HeapTupleIsValid(htup))
162-
ereport(ERROR,
163-
(errcode(ERRCODE_DUPLICATE_OBJECT),
164-
errmsg("there are multiple rules named \"%s\"", rulename),
165-
errhint("Specify a relation name as well as a rule name.")));
166-
}
167-
heap_endscan(scanDesc);
168-
heap_close(RewriteRelation, AccessShareLock);
169-
170-
return ruleoid;
171-
}

src/include/rewrite/rewriteSupport.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,5 @@ extern bool IsDefinedRewriteRule(Oid owningRel, const char *ruleName);
2222
extern void SetRelationRuleStatus(Oid relationId, bool relHasRules);
2323

2424
extern Oid get_rewrite_oid(Oid relid, const char *rulename, bool missing_ok);
25-
extern Oid get_rewrite_oid_without_relid(const char *rulename,
26-
Oid *relid, bool missing_ok);
2725

2826
#endif /* REWRITESUPPORT_H */

src/test/modules/test_ddl_deparse/expected/comment_on.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ COMMENT ON FUNCTION c_function_test() IS 'FUNCTION test';
1919
ERROR: function c_function_test() does not exist
2020
COMMENT ON TRIGGER trigger_1 ON datatype_table IS 'TRIGGER test';
2121
NOTICE: DDL test: type simple, tag COMMENT
22-
COMMENT ON RULE rule_1 IS 'RULE test';
22+
COMMENT ON RULE rule_1 ON datatype_table IS 'RULE test';
2323
NOTICE: DDL test: type simple, tag COMMENT

src/test/modules/test_ddl_deparse/sql/comment_on.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ COMMENT ON TABLE datatype_table IS 'This table should contain all native datatyp
1111
COMMENT ON VIEW datatype_view IS 'This is a view';
1212
COMMENT ON FUNCTION c_function_test() IS 'FUNCTION test';
1313
COMMENT ON TRIGGER trigger_1 ON datatype_table IS 'TRIGGER test';
14-
COMMENT ON RULE rule_1 IS 'RULE test';
14+
COMMENT ON RULE rule_1 ON datatype_table IS 'RULE test';

src/test/regress/expected/object_address.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ WARNING: error for operator family,{addr_nsp,zwei},{}: access method "addr_nsp"
214214
WARNING: error for operator family,{addr_nsp,zwei},{integer}: access method "addr_nsp" does not exist
215215
WARNING: error for operator family,{eins,zwei,drei},{}: access method "eins" does not exist
216216
WARNING: error for operator family,{eins,zwei,drei},{integer}: access method "eins" does not exist
217-
WARNING: error for rule,{eins},{}: rule "eins" does not exist
218-
WARNING: error for rule,{eins},{integer}: rule "eins" does not exist
217+
WARNING: error for rule,{eins},{}: must specify relation and object name
218+
WARNING: error for rule,{eins},{integer}: must specify relation and object name
219219
WARNING: error for rule,{addr_nsp,zwei},{}: relation "addr_nsp" does not exist
220220
WARNING: error for rule,{addr_nsp,zwei},{integer}: relation "addr_nsp" does not exist
221221
WARNING: error for rule,{eins,zwei,drei},{}: schema "eins" does not exist

0 commit comments

Comments
 (0)