Basically replaces (*a).b with a->b as it is everywhere else in
Postgres.

Servus
 Manfred
diff -Ncr ../base/src/backend/storage/page/bufpage.c src/backend/storage/page/bufpage.c
*** ../base/src/backend/storage/page/bufpage.c  Sat Nov 29 20:51:57 2003
--- src/backend/storage/page/bufpage.c  Wed Jun  2 22:26:12 2004
***************
*** 151,158 ****
                        if (offsetNumber < limit)
                        {
                                itemId = PageGetItemId(phdr, offsetNumber);
!                               if (((*itemId).lp_flags & LP_USED) ||
!                                       ((*itemId).lp_len != 0))
                                {
                                        elog(WARNING, "will not overwrite a used 
ItemId");
                                        return InvalidOffsetNumber;
--- 151,158 ----
                        if (offsetNumber < limit)
                        {
                                itemId = PageGetItemId(phdr, offsetNumber);
!                               if ((itemId->lp_flags & LP_USED) ||
!                                       (itemId->lp_len != 0))
                                {
                                        elog(WARNING, "will not overwrite a used 
ItemId");
                                        return InvalidOffsetNumber;
***************
*** 172,179 ****
                for (offsetNumber = 1; offsetNumber < limit; offsetNumber++)
                {
                        itemId = PageGetItemId(phdr, offsetNumber);
!                       if ((((*itemId).lp_flags & LP_USED) == 0) &&
!                               ((*itemId).lp_len == 0))
                                break;
                }
                /* if no free slot, we'll put it at limit (1st open slot) */
--- 172,179 ----
                for (offsetNumber = 1; offsetNumber < limit; offsetNumber++)
                {
                        itemId = PageGetItemId(phdr, offsetNumber);
!                       if (((itemId->lp_flags & LP_USED) == 0) &&
!                               (itemId->lp_len == 0))
                                break;
                }
                /* if no free slot, we'll put it at limit (1st open slot) */
***************
*** 214,222 ****
                                (limit - offsetNumber) * sizeof(ItemIdData));
  
        /* set the item pointer */
!       (*itemId).lp_off = upper;
!       (*itemId).lp_len = size;
!       (*itemId).lp_flags = flags;
  
        /* copy the item's data onto the page */
        memcpy((char *) page + upper, item, size);
--- 214,222 ----
                                (limit - offsetNumber) * sizeof(ItemIdData));
  
        /* set the item pointer */
!       itemId->lp_off = upper;
!       itemId->lp_len = size;
!       itemId->lp_flags = flags;
  
        /* copy the item's data onto the page */
        memcpy((char *) page + upper, item, size);
***************
*** 278,296 ****
  /*
   * sorting support for PageRepairFragmentation
   */
! struct itemIdSortData
  {
        int                     offsetindex;    /* linp array index */
        int                     itemoff;                /* page offset of item data */
        Size            alignedlen;             /* MAXALIGN(item data len) */
! };
  
  static int
  itemoffcompare(const void *itemidp1, const void *itemidp2)
  {
        /* Sort in decreasing itemoff order */
!       return ((struct itemIdSortData *) itemidp2)->itemoff -
!               ((struct itemIdSortData *) itemidp1)->itemoff;
  }
  
  /*
--- 278,297 ----
  /*
   * sorting support for PageRepairFragmentation
   */
! typedef struct itemIdSortData
  {
        int                     offsetindex;    /* linp array index */
        int                     itemoff;                /* page offset of item data */
        Size            alignedlen;             /* MAXALIGN(item data len) */
! } itemIdSortData;
! typedef itemIdSortData *itemIdSort;
  
  static int
  itemoffcompare(const void *itemidp1, const void *itemidp2)
  {
        /* Sort in decreasing itemoff order */
!       return ((itemIdSort) itemidp2)->itemoff -
!                  ((itemIdSort) itemidp1)->itemoff;
  }
  
  /*
***************
*** 309,316 ****
        Offset          pd_lower = ((PageHeader) page)->pd_lower;
        Offset          pd_upper = ((PageHeader) page)->pd_upper;
        Offset          pd_special = ((PageHeader) page)->pd_special;
!       struct itemIdSortData *itemidbase,
!                          *itemidptr;
        ItemId          lp;
        int                     nline,
                                nused;
--- 310,317 ----
        Offset          pd_lower = ((PageHeader) page)->pd_lower;
        Offset          pd_upper = ((PageHeader) page)->pd_upper;
        Offset          pd_special = ((PageHeader) page)->pd_special;
!       itemIdSort      itemidbase,
!                               itemidptr;
        ItemId          lp;
        int                     nline,
                                nused;
***************
*** 340,348 ****
        for (i = 0; i < nline; i++)
        {
                lp = PageGetItemId(page, i + 1);
!               if ((*lp).lp_flags & LP_DELETE) /* marked for deletion */
!                       (*lp).lp_flags &= ~(LP_USED | LP_DELETE);
!               if ((*lp).lp_flags & LP_USED)
                        nused++;
                else if (unused)
                        unused[i - nused] = (OffsetNumber) i;
--- 341,349 ----
        for (i = 0; i < nline; i++)
        {
                lp = PageGetItemId(page, i + 1);
!               if (lp->lp_flags & LP_DELETE) /* marked for deletion */
!                       lp->lp_flags &= ~(LP_USED | LP_DELETE);
!               if (lp->lp_flags & LP_USED)
                        nused++;
                else if (unused)
                        unused[i - nused] = (OffsetNumber) i;
***************
*** 354,390 ****
                for (i = 0; i < nline; i++)
                {
                        lp = PageGetItemId(page, i + 1);
!                       (*lp).lp_len = 0;       /* indicate unused & deallocated */
                }
                ((PageHeader) page)->pd_upper = pd_special;
        }
        else
        {                                                       /* nused != 0 */
                /* Need to compact the page the hard way */
!               itemidbase = (struct itemIdSortData *)
!                       palloc(sizeof(struct itemIdSortData) * nused);
                itemidptr = itemidbase;
                totallen = 0;
                for (i = 0; i < nline; i++)
                {
                        lp = PageGetItemId(page, i + 1);
!                       if ((*lp).lp_flags & LP_USED)
                        {
                                itemidptr->offsetindex = i;
!                               itemidptr->itemoff = (*lp).lp_off;
                                if (itemidptr->itemoff < (int) pd_upper ||
                                        itemidptr->itemoff >= (int) pd_special)
                                        ereport(ERROR,
                                                        
(errcode(ERRCODE_DATA_CORRUPTED),
                                                         errmsg("corrupted item 
pointer: %u",
                                                                        
itemidptr->itemoff)));
!                               itemidptr->alignedlen = MAXALIGN((*lp).lp_len);
                                totallen += itemidptr->alignedlen;
                                itemidptr++;
                        }
                        else
                        {
!                               (*lp).lp_len = 0;               /* indicate unused & 
deallocated */
                        }
                }
  
--- 355,390 ----
                for (i = 0; i < nline; i++)
                {
                        lp = PageGetItemId(page, i + 1);
!                       lp->lp_len = 0; /* indicate unused & deallocated */
                }
                ((PageHeader) page)->pd_upper = pd_special;
        }
        else
        {                                                       /* nused != 0 */
                /* Need to compact the page the hard way */
!               itemidbase = (itemIdSort) palloc(sizeof(itemIdSortData) * nused);
                itemidptr = itemidbase;
                totallen = 0;
                for (i = 0; i < nline; i++)
                {
                        lp = PageGetItemId(page, i + 1);
!                       if (lp->lp_flags & LP_USED)
                        {
                                itemidptr->offsetindex = i;
!                               itemidptr->itemoff = lp->lp_off;
                                if (itemidptr->itemoff < (int) pd_upper ||
                                        itemidptr->itemoff >= (int) pd_special)
                                        ereport(ERROR,
                                                        
(errcode(ERRCODE_DATA_CORRUPTED),
                                                         errmsg("corrupted item 
pointer: %u",
                                                                        
itemidptr->itemoff)));
!                               itemidptr->alignedlen = MAXALIGN(lp->lp_len);
                                totallen += itemidptr->alignedlen;
                                itemidptr++;
                        }
                        else
                        {
!                               lp->lp_len = 0;         /* indicate unused & 
deallocated */
                        }
                }
  
***************
*** 395,401 ****
                                   (unsigned int) totallen, pd_special - pd_lower)));
  
                /* sort itemIdSortData array into decreasing itemoff order */
!               qsort((char *) itemidbase, nused, sizeof(struct itemIdSortData),
                          itemoffcompare);
  
                /* compactify page */
--- 395,401 ----
                                   (unsigned int) totallen, pd_special - pd_lower)));
  
                /* sort itemIdSortData array into decreasing itemoff order */
!               qsort((char *) itemidbase, nused, sizeof(itemIdSortData),
                          itemoffcompare);
  
                /* compactify page */
***************
*** 408,414 ****
                        memmove((char *) page + upper,
                                        (char *) page + itemidptr->itemoff,
                                        itemidptr->alignedlen);
!                       (*lp).lp_off = upper;
                }
  
                ((PageHeader) page)->pd_upper = upper;
--- 408,414 ----
                        memmove((char *) page + upper,
                                        (char *) page + itemidptr->itemoff,
                                        itemidptr->alignedlen);
!                       lp->lp_off = upper;
                }
  
                ((PageHeader) page)->pd_upper = upper;
***************
*** 538,545 ****
                nline--;                                /* there's one less than when 
we started */
                for (i = 1; i <= nline; i++)
                {
!                       if (PageGetItemId(phdr, i)->lp_off <= offset)
!                               PageGetItemId(phdr, i)->lp_off += size;
                }
        }
  }
--- 538,546 ----
                nline--;                                /* there's one less than when 
we started */
                for (i = 1; i <= nline; i++)
                {
!                       ItemId ii = PageGetItemId(phdr, i);
!                       if (ii->lp_off <= offset)
!                               ii->lp_off += size;
                }
        }
  }
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to