1111 *
1212 *
1313 * IDENTIFICATION
14- * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.71 2004/05/31 03:48:06 tgl Exp $
14+ * $PostgreSQL: pgsql/src/backend/storage/smgr/smgr.c,v 1.72 2004/05/31 20:31:33 tgl Exp $
1515 *
1616 *-------------------------------------------------------------------------
1717 */
@@ -40,13 +40,14 @@ typedef struct f_smgr
4040 bool (* smgr_create ) (SMgrRelation reln , bool isRedo );
4141 bool (* smgr_unlink ) (RelFileNode rnode , bool isRedo );
4242 bool (* smgr_extend ) (SMgrRelation reln , BlockNumber blocknum ,
43- char * buffer );
43+ char * buffer , bool isTemp );
4444 bool (* smgr_read ) (SMgrRelation reln , BlockNumber blocknum ,
45- char * buffer );
45+ char * buffer );
4646 bool (* smgr_write ) (SMgrRelation reln , BlockNumber blocknum ,
47- char * buffer );
47+ char * buffer , bool isTemp );
4848 BlockNumber (* smgr_nblocks ) (SMgrRelation reln );
49- BlockNumber (* smgr_truncate ) (SMgrRelation reln , BlockNumber nblocks );
49+ BlockNumber (* smgr_truncate ) (SMgrRelation reln , BlockNumber nblocks ,
50+ bool isTemp );
5051 bool (* smgr_commit ) (void ); /* may be NULL */
5152 bool (* smgr_abort ) (void ); /* may be NULL */
5253 bool (* smgr_sync ) (void ); /* may be NULL */
@@ -438,9 +439,10 @@ smgr_internal_unlink(RelFileNode rnode, int which, bool isTemp, bool isRedo)
438439 * failure we clean up by truncating.
439440 */
440441void
441- smgrextend (SMgrRelation reln , BlockNumber blocknum , char * buffer )
442+ smgrextend (SMgrRelation reln , BlockNumber blocknum , char * buffer , bool isTemp )
442443{
443- if (! (* (smgrsw [reln -> smgr_which ].smgr_extend )) (reln , blocknum , buffer ))
444+ if (! (* (smgrsw [reln -> smgr_which ].smgr_extend )) (reln , blocknum , buffer ,
445+ isTemp ))
444446 ereport (ERROR ,
445447 (errcode_for_file_access (),
446448 errmsg ("could not extend relation %u/%u: %m" ,
@@ -473,12 +475,18 @@ smgrread(SMgrRelation reln, BlockNumber blocknum, char *buffer)
473475 * smgrwrite() -- Write the supplied buffer out.
474476 *
475477 * This is not a synchronous write -- the block is not necessarily
476- * on disk at return, only dumped out to the kernel.
478+ * on disk at return, only dumped out to the kernel. However,
479+ * provisions will be made to fsync the write before the next checkpoint.
480+ *
481+ * isTemp indicates that the relation is a temp table (ie, is managed
482+ * by the local-buffer manager). In this case no provisions need be
483+ * made to fsync the write before checkpointing.
477484 */
478485void
479- smgrwrite (SMgrRelation reln , BlockNumber blocknum , char * buffer )
486+ smgrwrite (SMgrRelation reln , BlockNumber blocknum , char * buffer , bool isTemp )
480487{
481- if (! (* (smgrsw [reln -> smgr_which ].smgr_write )) (reln , blocknum , buffer ))
488+ if (! (* (smgrsw [reln -> smgr_which ].smgr_write )) (reln , blocknum , buffer ,
489+ isTemp ))
482490 ereport (ERROR ,
483491 (errcode_for_file_access (),
484492 errmsg ("could not write block %u of relation %u/%u: %m" ,
@@ -525,12 +533,9 @@ smgrnblocks(SMgrRelation reln)
525533 * transaction on failure.
526534 */
527535BlockNumber
528- smgrtruncate (SMgrRelation reln , BlockNumber nblocks )
536+ smgrtruncate (SMgrRelation reln , BlockNumber nblocks , bool isTemp )
529537{
530538 BlockNumber newblks ;
531- XLogRecPtr lsn ;
532- XLogRecData rdata ;
533- xl_smgr_truncate xlrec ;
534539
535540 /*
536541 * Tell the free space map to forget anything it may have stored
@@ -540,7 +545,8 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks)
540545 FreeSpaceMapTruncateRel (& reln -> smgr_rnode , nblocks );
541546
542547 /* Do the truncation */
543- newblks = (* (smgrsw [reln -> smgr_which ].smgr_truncate )) (reln , nblocks );
548+ newblks = (* (smgrsw [reln -> smgr_which ].smgr_truncate )) (reln , nblocks ,
549+ isTemp );
544550 if (newblks == InvalidBlockNumber )
545551 ereport (ERROR ,
546552 (errcode_for_file_access (),
@@ -549,20 +555,29 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks)
549555 reln -> smgr_rnode .relNode ,
550556 nblocks )));
551557
552- /*
553- * Make a non-transactional XLOG entry showing the file truncation. It's
554- * non-transactional because we should replay it whether the transaction
555- * commits or not; the underlying file change is certainly not reversible.
556- */
557- xlrec .blkno = newblks ;
558- xlrec .rnode = reln -> smgr_rnode ;
558+ if (!isTemp )
559+ {
560+ /*
561+ * Make a non-transactional XLOG entry showing the file truncation.
562+ * It's non-transactional because we should replay it whether the
563+ * transaction commits or not; the underlying file change is certainly
564+ * not reversible.
565+ */
566+ XLogRecPtr lsn ;
567+ XLogRecData rdata ;
568+ xl_smgr_truncate xlrec ;
559569
560- rdata .buffer = InvalidBuffer ;
561- rdata .data = (char * ) & xlrec ;
562- rdata .len = sizeof (xlrec );
563- rdata .next = NULL ;
570+ xlrec .blkno = newblks ;
571+ xlrec .rnode = reln -> smgr_rnode ;
564572
565- lsn = XLogInsert (RM_SMGR_ID , XLOG_SMGR_TRUNCATE | XLOG_NO_TRAN , & rdata );
573+ rdata .buffer = InvalidBuffer ;
574+ rdata .data = (char * ) & xlrec ;
575+ rdata .len = sizeof (xlrec );
576+ rdata .next = NULL ;
577+
578+ lsn = XLogInsert (RM_SMGR_ID , XLOG_SMGR_TRUNCATE | XLOG_NO_TRAN ,
579+ & rdata );
580+ }
566581
567582 return newblks ;
568583}
@@ -725,7 +740,8 @@ smgr_redo(XLogRecPtr lsn, XLogRecord *record)
725740
726741 /* Do the truncation */
727742 newblks = (* (smgrsw [reln -> smgr_which ].smgr_truncate )) (reln ,
728- xlrec -> blkno );
743+ xlrec -> blkno ,
744+ false);
729745 if (newblks == InvalidBlockNumber )
730746 ereport (WARNING ,
731747 (errcode_for_file_access (),
0 commit comments