aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/page/bufpage.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2007-02-21 20:02:17 +0000
committerBruce Momjian <bruce@momjian.us>2007-02-21 20:02:17 +0000
commit6f519ad01c08b3866df3774558621937644036b9 (patch)
tree7bcccc344761c666665d2c3a5f0a2e00c43d71d9 /src/backend/storage/page/bufpage.c
parent526b1d697985642ee42959d65903f1d504ae57b0 (diff)
downloadpostgresql-6f519ad01c08b3866df3774558621937644036b9.tar.gz
postgresql-6f519ad01c08b3866df3774558621937644036b9.zip
btree source code cleanups:
I refactored findsplitloc and checksplitloc so that the division of labor is more clear IMO. I pushed all the space calculation inside the loop to checksplitloc. I also fixed the off by 4 in free space calculation caused by PageGetFreeSpace subtracting sizeof(ItemIdData), even though it was harmless, because it was distracting and I felt it might come back to bite us in the future if we change the page layout or alignments. There's now a new function PageGetExactFreeSpace that doesn't do the subtraction. findsplitloc now tries the "just the new item to right page" split as well. If people don't like the refactoring, I can write a patch to just add that. Heikki Linnakangas
Diffstat (limited to 'src/backend/storage/page/bufpage.c')
-rw-r--r--src/backend/storage/page/bufpage.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.c
index 2e5c7c412bf..8299f550d6e 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.70 2007/01/05 22:19:38 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/page/bufpage.c,v 1.71 2007/02/21 20:02:17 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -418,7 +418,8 @@ PageRepairFragmentation(Page page, OffsetNumber *unused)
/*
* PageGetFreeSpace
- * Returns the size of the free (allocatable) space on a page.
+ * Returns the size of the free (allocatable) space on a page,
+ * deducted by the space needed for a new line pointer.
*/
Size
PageGetFreeSpace(Page page)
@@ -434,7 +435,26 @@ PageGetFreeSpace(Page page)
if (space < (int) sizeof(ItemIdData))
return 0;
- space -= sizeof(ItemIdData); /* XXX not always appropriate */
+ space -= sizeof(ItemIdData);
+
+ return (Size) space;
+}
+
+/*
+ * PageGetExactFreeSpace
+ * Returns the size of the free (allocatable) space on a page.
+ */
+Size
+PageGetExactFreeSpace(Page page)
+{
+ int space;
+
+ /*
+ * Use signed arithmetic here so that we behave sensibly if pd_lower >
+ * pd_upper.
+ */
+ space = (int) ((PageHeader) page)->pd_upper -
+ (int) ((PageHeader) page)->pd_lower;
return (Size) space;
}