Tom Lane wrote:
Heikki Linnakangas <[EMAIL PROTECTED]> writes:
To see what's going on, I added some logs to the split code to print out the free space on both halves as calculated by findsplitloc, and the actual free space on the pages after split. I'm seeing a discrepancy of 4 bytes on the right half; actual space free on right page after split is 4 bytes less than anticipated.


Hm, mis-counting the positions of itempointers maybe?

Found it:

        /* Count up total space in data items without actually scanning 'em */
        dataitemtotal = rightspace - (int) PageGetFreeSpace(page);

This is 4 bytes off, because PageGetFreeSpace subtracts sizeof(ItemIdData) from the actual free space on page. We could do

dataitemtotal = rightspace - ((int) PageGetFreeSpace(page) +sizeof(ItemIdData));

but that again would be 4 bytes off in the other direction if there's 0 bytes left on the page :(.

IMHO the right fix is to modify PageGetFreeSpace not to do the subtraction, it's a hack anyway, but that means we have to go through and fix every caller of it. Or we can add a new PageGetReallyFreeSpace function and keep the old one for compatibility. What do we want?

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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Reply via email to