Dead code in _bt_split? - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Dead code in _bt_split?
Date
Msg-id 45786C60.70200@enterprisedb.com
Whole thread Raw
Responses Re: Dead code in _bt_split?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
This piece of code in _bt_split, starting at line 859, looks curious to me:

>     /* cope with possibility that newitem goes at the end */
>     if (i <= newitemoff)
>     {
>         if (newitemonleft)
>         {
>             _bt_pgaddtup(rel, leftpage, newitemsz, newitem, leftoff,
>                          "left sibling");
>             itup_off = leftoff;
>             itup_blkno = BufferGetBlockNumber(buf);
>             leftoff = OffsetNumberNext(leftoff);
>         }
>         else
>         {
>             _bt_pgaddtup(rel, rightpage, newitemsz, newitem, rightoff,
>                          "right sibling");
>             itup_off = rightoff;
>             itup_blkno = BufferGetBlockNumber(rbuf);
>             rightoff = OffsetNumberNext(rightoff);
>         }
>     }

This is right after a for-loop, which exits when i = maxoff + 1. So the 
first if-statement could be written as "if (newitemoff > maxoff)". If 
that's true, newitemonleft shouldn't be true, because that would mean 
that we've split a page so that all items went to the left page, and the 
right page is empty.

Is that really dead code, or am I missing something? How about putting 
an Assert in there instead?

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Ron Mayer
Date:
Subject: Re: Load distributed checkpoint
Next
From: Jeff Davis
Date:
Subject: Re: old synchronized scan patch