summaryrefslogtreecommitdiff
path: root/src/backend/access/heap/hio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/access/heap/hio.c')
-rw-r--r--src/backend/access/heap/hio.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c
index ccaaacefea8..82fb0a3268a 100644
--- a/src/backend/access/heap/hio.c
+++ b/src/backend/access/heap/hio.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/heap/hio.c,v 1.61 2006/03/05 15:58:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/hio.c,v 1.62 2006/07/02 02:23:18 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -102,12 +102,18 @@ RelationGetBufferForTuple(Relation relation, Size len,
{
Buffer buffer = InvalidBuffer;
Page pageHeader;
- Size pageFreeSpace;
+ Size pageFreeSpace,
+ freespace;
BlockNumber targetBlock,
otherBlock;
bool needLock;
+ if (relation->rd_options == NULL)
+ elog(ERROR, "RelationGetBufferForTuple %s IS NULL", RelationGetRelationName(relation));
+ Assert(relation->rd_options != NULL);
+
len = MAXALIGN(len); /* be conservative */
+ freespace = HeapGetPageFreeSpace(relation);
/*
* If we're gonna fail for oversize tuple, do it right away
@@ -146,7 +152,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
* We have no cached target page, so ask the FSM for an initial
* target.
*/
- targetBlock = GetPageWithFreeSpace(&relation->rd_node, len);
+ targetBlock = GetPageWithFreeSpace(&relation->rd_node, len + freespace);
/*
* If the FSM knows nothing of the rel, try the last page before we
@@ -202,7 +208,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
*/
pageHeader = (Page) BufferGetPage(buffer);
pageFreeSpace = PageGetFreeSpace(pageHeader);
- if (len <= pageFreeSpace)
+ if (len + freespace <= pageFreeSpace)
{
/* use this page as future insert target, too */
relation->rd_targblock = targetBlock;
@@ -235,7 +241,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
targetBlock = RecordAndGetPageWithFreeSpace(&relation->rd_node,
targetBlock,
pageFreeSpace,
- len);
+ len + freespace);
}
/*