11
11
*
12
12
*
13
13
* 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 $
15
15
*
16
16
*-------------------------------------------------------------------------
17
17
*/
@@ -40,13 +40,14 @@ typedef struct f_smgr
40
40
bool (* smgr_create ) (SMgrRelation reln , bool isRedo );
41
41
bool (* smgr_unlink ) (RelFileNode rnode , bool isRedo );
42
42
bool (* smgr_extend ) (SMgrRelation reln , BlockNumber blocknum ,
43
- char * buffer );
43
+ char * buffer , bool isTemp );
44
44
bool (* smgr_read ) (SMgrRelation reln , BlockNumber blocknum ,
45
- char * buffer );
45
+ char * buffer );
46
46
bool (* smgr_write ) (SMgrRelation reln , BlockNumber blocknum ,
47
- char * buffer );
47
+ char * buffer , bool isTemp );
48
48
BlockNumber (* smgr_nblocks ) (SMgrRelation reln );
49
- BlockNumber (* smgr_truncate ) (SMgrRelation reln , BlockNumber nblocks );
49
+ BlockNumber (* smgr_truncate ) (SMgrRelation reln , BlockNumber nblocks ,
50
+ bool isTemp );
50
51
bool (* smgr_commit ) (void ); /* may be NULL */
51
52
bool (* smgr_abort ) (void ); /* may be NULL */
52
53
bool (* smgr_sync ) (void ); /* may be NULL */
@@ -438,9 +439,10 @@ smgr_internal_unlink(RelFileNode rnode, int which, bool isTemp, bool isRedo)
438
439
* failure we clean up by truncating.
439
440
*/
440
441
void
441
- smgrextend (SMgrRelation reln , BlockNumber blocknum , char * buffer )
442
+ smgrextend (SMgrRelation reln , BlockNumber blocknum , char * buffer , bool isTemp )
442
443
{
443
- if (! (* (smgrsw [reln -> smgr_which ].smgr_extend )) (reln , blocknum , buffer ))
444
+ if (! (* (smgrsw [reln -> smgr_which ].smgr_extend )) (reln , blocknum , buffer ,
445
+ isTemp ))
444
446
ereport (ERROR ,
445
447
(errcode_for_file_access (),
446
448
errmsg ("could not extend relation %u/%u: %m" ,
@@ -473,12 +475,18 @@ smgrread(SMgrRelation reln, BlockNumber blocknum, char *buffer)
473
475
* smgrwrite() -- Write the supplied buffer out.
474
476
*
475
477
* 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.
477
484
*/
478
485
void
479
- smgrwrite (SMgrRelation reln , BlockNumber blocknum , char * buffer )
486
+ smgrwrite (SMgrRelation reln , BlockNumber blocknum , char * buffer , bool isTemp )
480
487
{
481
- if (! (* (smgrsw [reln -> smgr_which ].smgr_write )) (reln , blocknum , buffer ))
488
+ if (! (* (smgrsw [reln -> smgr_which ].smgr_write )) (reln , blocknum , buffer ,
489
+ isTemp ))
482
490
ereport (ERROR ,
483
491
(errcode_for_file_access (),
484
492
errmsg ("could not write block %u of relation %u/%u: %m" ,
@@ -525,12 +533,9 @@ smgrnblocks(SMgrRelation reln)
525
533
* transaction on failure.
526
534
*/
527
535
BlockNumber
528
- smgrtruncate (SMgrRelation reln , BlockNumber nblocks )
536
+ smgrtruncate (SMgrRelation reln , BlockNumber nblocks , bool isTemp )
529
537
{
530
538
BlockNumber newblks ;
531
- XLogRecPtr lsn ;
532
- XLogRecData rdata ;
533
- xl_smgr_truncate xlrec ;
534
539
535
540
/*
536
541
* Tell the free space map to forget anything it may have stored
@@ -540,7 +545,8 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks)
540
545
FreeSpaceMapTruncateRel (& reln -> smgr_rnode , nblocks );
541
546
542
547
/* 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 );
544
550
if (newblks == InvalidBlockNumber )
545
551
ereport (ERROR ,
546
552
(errcode_for_file_access (),
@@ -549,20 +555,29 @@ smgrtruncate(SMgrRelation reln, BlockNumber nblocks)
549
555
reln -> smgr_rnode .relNode ,
550
556
nblocks )));
551
557
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 ;
559
569
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 ;
564
572
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
+ }
566
581
567
582
return newblks ;
568
583
}
@@ -725,7 +740,8 @@ smgr_redo(XLogRecPtr lsn, XLogRecord *record)
725
740
726
741
/* Do the truncation */
727
742
newblks = (* (smgrsw [reln -> smgr_which ].smgr_truncate )) (reln ,
728
- xlrec -> blkno );
743
+ xlrec -> blkno ,
744
+ false);
729
745
if (newblks == InvalidBlockNumber )
730
746
ereport (WARNING ,
731
747
(errcode_for_file_access (),
0 commit comments