@@ -329,7 +329,64 @@ smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
329329}
330330
331331/*
332- *smgrdounlink() -- Immediately unlink a relation.
332+ *smgrdounlink() -- Immediately unlink all forks of a relation.
333+ *
334+ *All forks of the relation are removed from the store. This should
335+ *not be used during transactional operations, since it can't be undone.
336+ *
337+ *If isRedo is true, it is okay for the underlying file(s) to be gone
338+ *already.
339+ *
340+ *This is equivalent to calling smgrdounlinkfork for each fork, but
341+ *it's significantly quicker so should be preferred when possible.
342+ */
343+ void
344+ smgrdounlink (SMgrRelation reln ,bool isRedo )
345+ {
346+ RelFileNodeBackend rnode = reln -> smgr_rnode ;
347+ int which = reln -> smgr_which ;
348+ ForkNumber forknum ;
349+
350+ /* Close the forks at smgr level */
351+ for (forknum = 0 ;forknum <=MAX_FORKNUM ;forknum ++ )
352+ (* (smgrsw [which ].smgr_close )) (reln ,forknum );
353+
354+ /*
355+ * Get rid of any remaining buffers for the relation. bufmgr will just
356+ * drop them without bothering to write the contents.
357+ */
358+ DropRelFileNodeAllBuffers (rnode );
359+
360+ /*
361+ * It'd be nice to tell the stats collector to forget it immediately, too.
362+ * But we can't because we don't know the OID (and in cases involving
363+ * relfilenode swaps, it's not always clear which table OID to forget,
364+ * anyway).
365+ */
366+
367+ /*
368+ * Send a shared-inval message to force other backends to close any
369+ * dangling smgr references they may have for this rel. We should do this
370+ * before starting the actual unlinking, in case we fail partway through
371+ * that step. Note that the sinval message will eventually come back to
372+ * this backend, too, and thereby provide a backstop that we closed our
373+ * own smgr rel.
374+ */
375+ CacheInvalidateSmgr (rnode );
376+
377+ /*
378+ * Delete the physical file(s).
379+ *
380+ * Note: smgr_unlink must treat deletion failure as a WARNING, not an
381+ * ERROR, because we've already decided to commit or abort the current
382+ * xact.
383+ */
384+ for (forknum = 0 ;forknum <=MAX_FORKNUM ;forknum ++ )
385+ (* (smgrsw [which ].smgr_unlink )) (rnode ,forknum ,isRedo );
386+ }
387+
388+ /*
389+ *smgrdounlinkfork() -- Immediately unlink one fork of a relation.
333390 *
334391 *The specified fork of the relation is removed from the store. This
335392 *should not be used during transactional operations, since it can't be
@@ -339,16 +396,16 @@ smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
339396 *already.
340397 */
341398void
342- smgrdounlink (SMgrRelation reln ,ForkNumber forknum ,bool isRedo )
399+ smgrdounlinkfork (SMgrRelation reln ,ForkNumber forknum ,bool isRedo )
343400{
344401RelFileNodeBackend rnode = reln -> smgr_rnode ;
345402int which = reln -> smgr_which ;
346403
347- /* Close the fork */
404+ /* Close the forkat smgr level */
348405(* (smgrsw [which ].smgr_close )) (reln ,forknum );
349406
350407/*
351- * Get rid of any remaining buffers for therelation . bufmgr will just
408+ * Get rid of any remaining buffers for thefork . bufmgr will just
352409 * drop them without bothering to write the contents.
353410 */
354411DropRelFileNodeBuffers (rnode ,forknum ,0 );