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

Skip to content

Commit ab02896

Browse files
committed
Provide CatalogTupleDelete() as a wrapper around simple_heap_delete().
This extends the work done in commit 2f5c9d9 to provide a more nearly complete abstraction layer hiding the details of index updating for catalog changes. That commit only invented abstractions for catalog inserts and updates, leaving nearby code for catalog deletes still calling the heap-level routines directly. That seems rather ugly from here, and it does little to help if we ever want to shift to a storage system in which indexing work is needed at delete time. Hence, create a wrapper function CatalogTupleDelete(), and replace calls of simple_heap_delete() on catalog tuples with it. There are now very few direct calls of [simple_]heap_delete remaining in the tree. Discussion: https://postgr.es/m/[email protected]
1 parent bbd8550 commit ab02896

40 files changed

+101
-83
lines changed

src/backend/catalog/aclchk.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ RemoveDefaultACLById(Oid defaclOid)
14701470
if (!HeapTupleIsValid(tuple))
14711471
elog(ERROR, "could not find tuple for default ACL %u", defaclOid);
14721472

1473-
simple_heap_delete(rel, &tuple->t_self);
1473+
CatalogTupleDelete(rel, &tuple->t_self);
14741474

14751475
systable_endscan(scan);
14761476
heap_close(rel, RowExclusiveLock);
@@ -5718,8 +5718,10 @@ recordExtensionInitPrivWorker(Oid objoid, Oid classoid, int objsubid, Acl *new_a
57185718
CatalogTupleUpdate(relation, &oldtuple->t_self, oldtuple);
57195719
}
57205720
else
5721+
{
57215722
/* new_acl is NULL, so delete the entry we found. */
5722-
simple_heap_delete(relation, &oldtuple->t_self);
5723+
CatalogTupleDelete(relation, &oldtuple->t_self);
5724+
}
57235725
}
57245726
else
57255727
{

src/backend/catalog/dependency.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ deleteOneObject(const ObjectAddress *object, Relation *depRel, int flags)
10621062

10631063
while (HeapTupleIsValid(tup = systable_getnext(scan)))
10641064
{
1065-
simple_heap_delete(*depRel, &tup->t_self);
1065+
CatalogTupleDelete(*depRel, &tup->t_self);
10661066
}
10671067

10681068
systable_endscan(scan);
@@ -2467,7 +2467,7 @@ DeleteInitPrivs(const ObjectAddress *object)
24672467
NULL, 3, key);
24682468

24692469
while (HeapTupleIsValid(oldtuple = systable_getnext(scan)))
2470-
simple_heap_delete(relation, &oldtuple->t_self);
2470+
CatalogTupleDelete(relation, &oldtuple->t_self);
24712471

24722472
systable_endscan(scan);
24732473

src/backend/catalog/heap.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ RelationRemoveInheritance(Oid relid)
14171417
NULL, 1, &key);
14181418

14191419
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
1420-
simple_heap_delete(catalogRelation, &tuple->t_self);
1420+
CatalogTupleDelete(catalogRelation, &tuple->t_self);
14211421

14221422
systable_endscan(scan);
14231423
heap_close(catalogRelation, RowExclusiveLock);
@@ -1445,7 +1445,7 @@ DeleteRelationTuple(Oid relid)
14451445
elog(ERROR, "cache lookup failed for relation %u", relid);
14461446

14471447
/* delete the relation tuple from pg_class, and finish up */
1448-
simple_heap_delete(pg_class_desc, &tup->t_self);
1448+
CatalogTupleDelete(pg_class_desc, &tup->t_self);
14491449

14501450
ReleaseSysCache(tup);
14511451

@@ -1482,7 +1482,7 @@ DeleteAttributeTuples(Oid relid)
14821482

14831483
/* Delete all the matching tuples */
14841484
while ((atttup = systable_getnext(scan)) != NULL)
1485-
simple_heap_delete(attrel, &atttup->t_self);
1485+
CatalogTupleDelete(attrel, &atttup->t_self);
14861486

14871487
/* Clean up after the scan */
14881488
systable_endscan(scan);
@@ -1523,7 +1523,7 @@ DeleteSystemAttributeTuples(Oid relid)
15231523

15241524
/* Delete all the matching tuples */
15251525
while ((atttup = systable_getnext(scan)) != NULL)
1526-
simple_heap_delete(attrel, &atttup->t_self);
1526+
CatalogTupleDelete(attrel, &atttup->t_self);
15271527

15281528
/* Clean up after the scan */
15291529
systable_endscan(scan);
@@ -1570,7 +1570,7 @@ RemoveAttributeById(Oid relid, AttrNumber attnum)
15701570
{
15711571
/* System attribute (probably OID) ... just delete the row */
15721572

1573-
simple_heap_delete(attr_rel, &tuple->t_self);
1573+
CatalogTupleDelete(attr_rel, &tuple->t_self);
15741574
}
15751575
else
15761576
{
@@ -1715,7 +1715,7 @@ RemoveAttrDefaultById(Oid attrdefId)
17151715
myrel = relation_open(myrelid, AccessExclusiveLock);
17161716

17171717
/* Now we can delete the pg_attrdef row */
1718-
simple_heap_delete(attrdef_rel, &tuple->t_self);
1718+
CatalogTupleDelete(attrdef_rel, &tuple->t_self);
17191719

17201720
systable_endscan(scan);
17211721
heap_close(attrdef_rel, RowExclusiveLock);
@@ -1809,7 +1809,7 @@ heap_drop_with_catalog(Oid relid)
18091809
if (!HeapTupleIsValid(tuple))
18101810
elog(ERROR, "cache lookup failed for foreign table %u", relid);
18111811

1812-
simple_heap_delete(rel, &tuple->t_self);
1812+
CatalogTupleDelete(rel, &tuple->t_self);
18131813

18141814
ReleaseSysCache(tuple);
18151815
heap_close(rel, RowExclusiveLock);
@@ -2764,7 +2764,7 @@ RemoveStatistics(Oid relid, AttrNumber attnum)
27642764

27652765
/* we must loop even when attnum != 0, in case of inherited stats */
27662766
while (HeapTupleIsValid(tuple = systable_getnext(scan)))
2767-
simple_heap_delete(pgstatistic, &tuple->t_self);
2767+
CatalogTupleDelete(pgstatistic, &tuple->t_self);
27682768

27692769
systable_endscan(scan);
27702770

@@ -3196,7 +3196,7 @@ RemovePartitionKeyByRelId(Oid relid)
31963196
elog(ERROR, "cache lookup failed for partition key of relation %u",
31973197
relid);
31983198

3199-
simple_heap_delete(rel, &tuple->t_self);
3199+
CatalogTupleDelete(rel, &tuple->t_self);
32003200

32013201
ReleaseSysCache(tuple);
32023202
heap_close(rel, RowExclusiveLock);

src/backend/catalog/index.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,7 @@ index_drop(Oid indexId, bool concurrent)
15731573

15741574
hasexprs = !heap_attisnull(tuple, Anum_pg_index_indexprs);
15751575

1576-
simple_heap_delete(indexRelation, &tuple->t_self);
1576+
CatalogTupleDelete(indexRelation, &tuple->t_self);
15771577

15781578
ReleaseSysCache(tuple);
15791579
heap_close(indexRelation, RowExclusiveLock);

src/backend/catalog/indexing.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,19 @@ CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
192192
CatalogIndexInsert(indstate, tup);
193193
CatalogCloseIndexes(indstate);
194194
}
195+
196+
/*
197+
* CatalogTupleDelete - do heap and indexing work for deleting a catalog tuple
198+
*
199+
* Delete the tuple identified by tid in the specified catalog.
200+
*
201+
* With Postgres heaps, there is no index work to do at deletion time;
202+
* cleanup will be done later by VACUUM. However, callers of this function
203+
* shouldn't have to know that; we'd like a uniform abstraction for all
204+
* catalog tuple changes. Hence, provide this currently-trivial wrapper.
205+
*/
206+
void
207+
CatalogTupleDelete(Relation heapRel, ItemPointer tid)
208+
{
209+
simple_heap_delete(heapRel, tid);
210+
}

src/backend/catalog/pg_collation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ RemoveCollationById(Oid collationOid)
191191
tuple = systable_getnext(scandesc);
192192

193193
if (HeapTupleIsValid(tuple))
194-
simple_heap_delete(rel, &tuple->t_self);
194+
CatalogTupleDelete(rel, &tuple->t_self);
195195
else
196196
elog(ERROR, "could not find tuple for collation %u", collationOid);
197197

src/backend/catalog/pg_constraint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ RemoveConstraintById(Oid conId)
604604
elog(ERROR, "constraint %u is not of a known type", conId);
605605

606606
/* Fry the constraint itself */
607-
simple_heap_delete(conDesc, &tup->t_self);
607+
CatalogTupleDelete(conDesc, &tup->t_self);
608608

609609
/* Clean up */
610610
ReleaseSysCache(tup);

src/backend/catalog/pg_conversion.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ RemoveConversionById(Oid conversionOid)
165165

166166
/* search for the target tuple */
167167
if (HeapTupleIsValid(tuple = heap_getnext(scan, ForwardScanDirection)))
168-
simple_heap_delete(rel, &tuple->t_self);
168+
CatalogTupleDelete(rel, &tuple->t_self);
169169
else
170170
elog(ERROR, "could not find tuple for conversion %u", conversionOid);
171171
heap_endscan(scan);

src/backend/catalog/pg_db_role_setting.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
9191
CatalogTupleUpdate(rel, &tuple->t_self, newtuple);
9292
}
9393
else
94-
simple_heap_delete(rel, &tuple->t_self);
94+
CatalogTupleDelete(rel, &tuple->t_self);
9595
}
9696
}
9797
else if (HeapTupleIsValid(tuple))
@@ -129,7 +129,7 @@ AlterSetting(Oid databaseid, Oid roleid, VariableSetStmt *setstmt)
129129
CatalogTupleUpdate(rel, &tuple->t_self, newtuple);
130130
}
131131
else
132-
simple_heap_delete(rel, &tuple->t_self);
132+
CatalogTupleDelete(rel, &tuple->t_self);
133133
}
134134
else if (valuestr)
135135
{
@@ -199,7 +199,7 @@ DropSetting(Oid databaseid, Oid roleid)
199199
scan = heap_beginscan_catalog(relsetting, numkeys, keys);
200200
while (HeapTupleIsValid(tup = heap_getnext(scan, ForwardScanDirection)))
201201
{
202-
simple_heap_delete(relsetting, &tup->t_self);
202+
CatalogTupleDelete(relsetting, &tup->t_self);
203203
}
204204
heap_endscan(scan);
205205

src/backend/catalog/pg_depend.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ deleteDependencyRecordsFor(Oid classId, Oid objectId,
219219
((Form_pg_depend) GETSTRUCT(tup))->deptype == DEPENDENCY_EXTENSION)
220220
continue;
221221

222-
simple_heap_delete(depRel, &tup->t_self);
222+
CatalogTupleDelete(depRel, &tup->t_self);
223223
count++;
224224
}
225225

@@ -269,7 +269,7 @@ deleteDependencyRecordsForClass(Oid classId, Oid objectId,
269269

270270
if (depform->refclassid == refclassId && depform->deptype == deptype)
271271
{
272-
simple_heap_delete(depRel, &tup->t_self);
272+
CatalogTupleDelete(depRel, &tup->t_self);
273273
count++;
274274
}
275275
}
@@ -353,7 +353,7 @@ changeDependencyFor(Oid classId, Oid objectId,
353353
depform->refobjid == oldRefObjectId)
354354
{
355355
if (newIsPinned)
356-
simple_heap_delete(depRel, &tup->t_self);
356+
CatalogTupleDelete(depRel, &tup->t_self);
357357
else
358358
{
359359
/* make a modifiable copy */

0 commit comments

Comments
 (0)