diff -cpr pgsql-orig/src/backend/storage/page/bufpage.c pgsql/src/backend/storage/page/bufpage.c
*** pgsql-orig/src/backend/storage/page/bufpage.c	2005-09-22 13:01:11.125625032 +0900
--- pgsql/src/backend/storage/page/bufpage.c	2005-09-22 13:02:57.680426240 +0900
*************** PageAddItem(Page page,
*** 149,156 ****
  			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;
--- 149,155 ----
  			if (offsetNumber < limit)
  			{
  				itemId = PageGetItemId(phdr, offsetNumber);
! 				if (ItemIdIsUsed(itemId) || ItemIdGetLength(itemId) != 0)
  				{
  					elog(WARNING, "will not overwrite a used ItemId");
  					return InvalidOffsetNumber;
*************** PageAddItem(Page page,
*** 170,177 ****
  		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) */
--- 169,175 ----
  		for (offsetNumber = 1; offsetNumber < limit; offsetNumber++)
  		{
  			itemId = PageGetItemId(phdr, offsetNumber);
! 			if (!ItemIdIsUsed(itemId) && ItemIdGetLength(itemId) == 0)
  				break;
  		}
  		/* if no free slot, we'll put it at limit (1st open slot) */
*************** PageRepairFragmentation(Page page, Offse
*** 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;
--- 339,347 ----
  	for (i = 0; i < nline; i++)
  	{
  		lp = PageGetItemId(page, i + 1);
! 		if (ItemIdDeleted(lp))	/* marked for deletion */
  			lp->lp_flags &= ~(LP_USED | LP_DELETE);
! 		if (ItemIdIsUsed(lp))
  			nused++;
  		else if (unused)
  			unused[i - nused] = (OffsetNumber) i;
*************** PageRepairFragmentation(Page page, Offse
*** 368,384 ****
  		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++;
  			}
--- 366,382 ----
  		for (i = 0; i < nline; i++)
  		{
  			lp = PageGetItemId(page, i + 1);
! 			if (ItemIdIsUsed(lp))
  			{
  				itemidptr->offsetindex = i;
! 				itemidptr->itemoff = ItemIdGetOffset(lp);
  				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(ItemIdGetLength(lp));
  				totallen += itemidptr->alignedlen;
  				itemidptr++;
  			}
*************** PageIndexTupleDelete(Page page, OffsetNu
*** 540,546 ****
  		{
  			ItemId		ii = PageGetItemId(phdr, i);
  
! 			if (ii->lp_off <= offset)
  				ii->lp_off += size;
  		}
  	}
--- 538,544 ----
  		{
  			ItemId		ii = PageGetItemId(phdr, i);
  
! 			if (ItemIdGetOffset(ii) <= offset)
  				ii->lp_off += size;
  		}
  	}
diff -cpr pgsql-orig/src/include/storage/bufpage.h pgsql/src/include/storage/bufpage.h
*** pgsql-orig/src/include/storage/bufpage.h	2005-09-22 13:01:11.272602688 +0900
--- pgsql/src/include/storage/bufpage.h	2005-09-22 13:03:05.224279400 +0900
*************** typedef PageHeaderData *PageHeader;
*** 258,265 ****
  #define PageGetItem(page, itemId) \
  ( \
  	AssertMacro(PageIsValid(page)), \
! 	AssertMacro((itemId)->lp_flags & LP_USED), \
! 	(Item)(((char *)(page)) + (itemId)->lp_off) \
  )
  
  /*
--- 258,265 ----
  #define PageGetItem(page, itemId) \
  ( \
  	AssertMacro(PageIsValid(page)), \
! 	AssertMacro(ItemIdIsUsed(itemId)), \
! 	(Item)(((char *)(page)) + ItemIdGetOffset(itemId)) \
  )
  
  /*
diff -cpr pgsql-orig/src/include/storage/itemid.h pgsql/src/include/storage/itemid.h
*** pgsql-orig/src/include/storage/itemid.h	2005-09-22 13:01:11.270602992 +0900
--- pgsql/src/include/storage/itemid.h	2005-09-22 13:02:17.032605648 +0900
*************** typedef ItemIdData *ItemId;
*** 38,44 ****
  
  /*
   * This bit may be passed to PageAddItem together with
!  * LP_USED & LP_DELETED bits to specify overwrite mode
   */
  #define OverwritePageMode	0x10
  
--- 38,44 ----
  
  /*
   * This bit may be passed to PageAddItem together with
!  * LP_USED & LP_DELETE bits to specify overwrite mode
   */
  #define OverwritePageMode	0x10
  