@@ -575,27 +575,24 @@ rumbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
575
575
uint32 nlist ;
576
576
MemoryContext oldCtx ;
577
577
OffsetNumber attnum ;
578
- GenericXLogState * state ;
578
+ BlockNumber blkno ;
579
579
580
580
if (RelationGetNumberOfBlocks (index ) != 0 )
581
581
elog (ERROR , "index \"%s\" already contains data" ,
582
582
RelationGetRelationName (index ));
583
583
584
584
initRumState (& buildstate .rumstate , index );
585
+ buildstate .rumstate .isBuild = true;
585
586
buildstate .indtuples = 0 ;
586
587
memset (& buildstate .buildStats , 0 , sizeof (GinStatsData ));
587
588
588
- state = GenericXLogStart (index );
589
-
590
589
/* initialize the meta page */
591
590
MetaBuffer = RumNewBuffer (index );
592
591
/* initialize the root page */
593
592
RootBuffer = RumNewBuffer (index );
594
593
595
- RumInitMetabuffer (state , MetaBuffer );
596
- RumInitBuffer (state , RootBuffer , RUM_LEAF );
597
-
598
- GenericXLogFinish (state );
594
+ RumInitMetabuffer (NULL , MetaBuffer , buildstate .rumstate .isBuild );
595
+ RumInitBuffer (NULL , RootBuffer , RUM_LEAF , buildstate .rumstate .isBuild );
599
596
600
597
UnlockReleaseBuffer (MetaBuffer );
601
598
UnlockReleaseBuffer (RootBuffer );
@@ -651,6 +648,22 @@ rumbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
651
648
buildstate .buildStats .nTotalPages = RelationGetNumberOfBlocks (index );
652
649
rumUpdateStats (index , & buildstate .buildStats , buildstate .rumstate .isBuild );
653
650
651
+ /*
652
+ * Write index to xlog.
653
+ */
654
+ for (blkno = 0 ; blkno < buildstate .buildStats .nTotalPages ; blkno ++ )
655
+ {
656
+ Buffer buffer = ReadBuffer (index , blkno );
657
+ GenericXLogState * state = RumGenericXLogStart (index ,
658
+ buildstate .rumstate .isBuild );
659
+
660
+ RumGenericXLogRegisterBuffer (state , buffer , GENERIC_XLOG_FULL_IMAGE ,
661
+ buildstate .rumstate .isBuild );
662
+ RumGenericXLogFinish (state , buildstate .rumstate .isBuild );
663
+
664
+ ReleaseBuffer (buffer );
665
+ }
666
+
654
667
/*
655
668
* Return statistics
656
669
*/
@@ -683,8 +696,8 @@ rumbuildempty(Relation index)
683
696
LockBuffer (RootBuffer , BUFFER_LOCK_EXCLUSIVE );
684
697
685
698
/* Initialize and xlog metabuffer and root buffer. */
686
- RumInitMetabuffer (state , MetaBuffer );
687
- RumInitBuffer (state , RootBuffer , RUM_LEAF );
699
+ RumInitMetabuffer (state , MetaBuffer , false );
700
+ RumInitBuffer (state , RootBuffer , RUM_LEAF , false );
688
701
689
702
RumGenericXLogFinish (state , false);
690
703
0 commit comments