@@ -166,6 +166,8 @@ typedef enum/* behavior for mdopen & _mdfd_getseg */
166166}ExtensionBehavior ;
167167
168168/* local routines */
169+ static void mdunlinkfork (RelFileNodeBackend rnode ,ForkNumber forkNum ,
170+ bool isRedo );
169171static MdfdVec * mdopen (SMgrRelation reln ,ForkNumber forknum ,
170172ExtensionBehavior behavior );
171173static void register_dirty_segment (SMgrRelation reln ,ForkNumber forknum ,
@@ -308,6 +310,9 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
308310 * Note that we're passed a RelFileNodeBackend --- by the time this is called,
309311 * there won't be an SMgrRelation hashtable entry anymore.
310312 *
313+ * forkNum can be a fork number to delete a specific fork, or InvalidForkNumber
314+ * to delete all forks.
315+ *
311316 * For regular relations, we don't unlink the first segment file of the rel,
312317 * but just truncate it to zero length, and record a request to unlink it after
313318 * the next checkpoint. Additional segments can be unlinked immediately,
@@ -349,17 +354,32 @@ mdcreate(SMgrRelation reln, ForkNumber forkNum, bool isRedo)
349354void
350355mdunlink (RelFileNodeBackend rnode ,ForkNumber forkNum ,bool isRedo )
351356{
352- char * path ;
353- int ret ;
354-
355357/*
356358 * We have to clean out any pending fsync requests for the doomed
357359 * relation, else the next mdsync() will fail. There can't be any such
358- * requests for a temp relation, though.
360+ * requests for a temp relation, though. We can send just one request
361+ * even when deleting multiple forks, since the fsync queuing code accepts
362+ * the "InvalidForkNumber = all forks" convention.
359363 */
360364if (!RelFileNodeBackendIsTemp (rnode ))
361365ForgetRelationFsyncRequests (rnode .node ,forkNum );
362366
367+ /* Now do the per-fork work */
368+ if (forkNum == InvalidForkNumber )
369+ {
370+ for (forkNum = 0 ;forkNum <=MAX_FORKNUM ;forkNum ++ )
371+ mdunlinkfork (rnode ,forkNum ,isRedo );
372+ }
373+ else
374+ mdunlinkfork (rnode ,forkNum ,isRedo );
375+ }
376+
377+ static void
378+ mdunlinkfork (RelFileNodeBackend rnode ,ForkNumber forkNum ,bool isRedo )
379+ {
380+ char * path ;
381+ int ret ;
382+
363383path = relpath (rnode ,forkNum );
364384
365385/*
@@ -1340,7 +1360,8 @@ register_unlink(RelFileNodeBackend rnode)
13401360 * The range of possible segment numbers is way less than the range of
13411361 * BlockNumber, so we can reserve high values of segno for special purposes.
13421362 * We define three:
1343- * - FORGET_RELATION_FSYNC means to cancel pending fsyncs for a relation
1363+ * - FORGET_RELATION_FSYNC means to cancel pending fsyncs for a relation,
1364+ * either for one fork, or all forks if forknum is InvalidForkNumber
13441365 * - FORGET_DATABASE_FSYNC means to cancel pending fsyncs for a whole database
13451366 * - UNLINK_RELATION_REQUEST is a request to delete the file after the next
13461367 * checkpoint.
@@ -1356,15 +1377,16 @@ RememberFsyncRequest(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
13561377
13571378if (segno == FORGET_RELATION_FSYNC )
13581379{
1359- /* Remove any pending requests for theentire relation */
1380+ /* Remove any pending requests for the relation (one or all forks) */
13601381HASH_SEQ_STATUS hstat ;
13611382PendingOperationEntry * entry ;
13621383
13631384hash_seq_init (& hstat ,pendingOpsTable );
13641385while ((entry = (PendingOperationEntry * )hash_seq_search (& hstat ))!= NULL )
13651386{
13661387if (RelFileNodeEquals (entry -> tag .rnode ,rnode )&&
1367- entry -> tag .forknum == forknum )
1388+ (entry -> tag .forknum == forknum ||
1389+ forknum == InvalidForkNumber ))
13681390{
13691391/* Okay, cancel this entry */
13701392entry -> canceled = true;
@@ -1466,6 +1488,9 @@ RememberFsyncRequest(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
14661488
14671489/*
14681490 * ForgetRelationFsyncRequests -- forget any fsyncs for a relation fork
1491+ *
1492+ * forknum == InvalidForkNumber means all forks, although this code doesn't
1493+ * actually know that, since it's just forwarding the request elsewhere.
14691494 */
14701495void
14711496ForgetRelationFsyncRequests (RelFileNode rnode ,ForkNumber forknum )