Skip to content

Commit 03659a2

Browse files
committed
Added: dynamic re-moving page from list of pages usable for shrinking
if its free-space < min_tuple_len.
1 parent 7b4426e commit 03659a2

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

src/backend/commands/vacuum.c

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.10 1996/11/28 04:37:38 vadim Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.11 1996/11/29 10:27:59 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -462,6 +462,7 @@ _vc_scanheap (VRelList curvrl, Relation onerel,
462462
{
463463
int nblocks, blkno;
464464
ItemId itemid;
465+
ItemPointer itemptr;
465466
HeapTuple htup;
466467
Buffer buf;
467468
Page page, tempPage = NULL;
@@ -611,6 +612,33 @@ DELETE_TRANSACTION_ID_VALID %d, TUPGONE %d.",
611612
tupgone);
612613
}
613614

615+
/*
616+
* It's possibly! But from where it comes ?
617+
* And should we fix it ? - vadim 11/28/96
618+
*/
619+
itemptr = &(htup->t_ctid);
620+
if ( !ItemPointerIsValid (itemptr) ||
621+
BlockIdGetBlockNumber(&(itemptr->ip_blkid)) != blkno )
622+
{
623+
elog (NOTICE, "ITEM POINTER IS INVALID: %u/%u FOR %u/%u. TUPGONE %d.",
624+
BlockIdGetBlockNumber(&(itemptr->ip_blkid)),
625+
itemptr->ip_posid, blkno, offnum, tupgone);
626+
}
627+
628+
/*
629+
* Other checks...
630+
*/
631+
if ( htup->t_len != itemid->lp_len )
632+
{
633+
elog (NOTICE, "PAGEHEADER' LEN %u IS NOT THE SAME AS HTUP' %u FOR %u/%u.TUPGONE %d.",
634+
itemid->lp_len, htup->t_len, blkno, offnum, tupgone);
635+
}
636+
if ( !OidIsValid(htup->t_oid) )
637+
{
638+
elog (NOTICE, "OID IS INVALID FOR %u/%u.TUPGONE %d.",
639+
blkno, offnum, tupgone);
640+
}
641+
614642
if (tupgone) {
615643
ItemId lpp;
616644

@@ -676,6 +704,10 @@ DELETE_TRANSACTION_ID_VALID %d, TUPGONE %d.",
676704
/* save stats in the rel list for use later */
677705
curvrl->vrl_ntups = ntups;
678706
curvrl->vrl_npages = nblocks;
707+
if ( ntups == 0 )
708+
min_tlen = max_tlen = 0;
709+
curvrl->vrl_min_tlen = min_tlen;
710+
curvrl->vrl_max_tlen = max_tlen;
679711

680712
Vvpl->vpl_nemend = nemend;
681713
Fvpl->vpl_nemend = nemend;
@@ -746,6 +778,7 @@ _vc_rpfheap (VRelList curvrl, Relation onerel,
746778
InsertIndexResult iresult;
747779
VPageListData Nvpl;
748780
VPageDescr ToVpd = NULL, Fvplast, Vvplast, vpc, *vpp;
781+
int ToVpI = 0;
749782
IndDesc *Idesc, *idcur;
750783
int Fblklast, Vblklast, i;
751784
Size tlen;
@@ -872,16 +905,40 @@ _vc_rpfheap (VRelList curvrl, Relation onerel,
872905
! _vc_enough_space (ToVpd, tlen) )
873906
{
874907
if ( ToBuf != InvalidBuffer )
908+
{
875909
WriteBuffer(ToBuf);
876-
ToBuf = InvalidBuffer;
910+
ToBuf = InvalidBuffer;
911+
/*
912+
* If no one tuple can't be added to this page -
913+
* remove page from Fvpl. - vadim 11/27/96
914+
*/
915+
if ( !_vc_enough_space (ToVpd, curvrl->vrl_min_tlen) )
916+
{
917+
if ( ToVpd != Fvplast )
918+
{
919+
Assert ( Fnpages > ToVpI + 1 );
920+
memmove (Fvpl->vpl_pgdesc + ToVpI,
921+
Fvpl->vpl_pgdesc + ToVpI + 1,
922+
sizeof (VPageDescr*) * (Fnpages - ToVpI - 1));
923+
}
924+
Assert ( Fnpages >= 1 );
925+
Fnpages--;
926+
if ( Fnpages == 0 )
927+
break;
928+
/* get prev reapped page from Fvpl */
929+
Fvplast = Fvpl->vpl_pgdesc[Fnpages - 1];
930+
Fblklast = Fvplast->vpd_blkno;
931+
}
932+
}
877933
for (i=0; i < Fnpages; i++)
878934
{
879935
if ( _vc_enough_space (Fvpl->vpl_pgdesc[i], tlen) )
880936
break;
881937
}
882938
if ( i == Fnpages )
883939
break; /* can't move item anywhere */
884-
ToVpd = Fvpl->vpl_pgdesc[i];
940+
ToVpI = i;
941+
ToVpd = Fvpl->vpl_pgdesc[ToVpI];
885942
ToBuf = ReadBuffer(onerel, ToVpd->vpd_blkno);
886943
ToPage = BufferGetPage(ToBuf);
887944
/* if this page was not used before - clean it */

0 commit comments

Comments
 (0)