aboutsummaryrefslogtreecommitdiff
path: root/src/backend/access/heap
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-07-03 22:45:41 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-07-03 22:45:41 +0000
commitb7b78d24f7fc8d621af40b2e404b6a3f3420e89e (patch)
treeda6b05ca5779ad812557b5d4cd38be79bf524825 /src/backend/access/heap
parentfeed07350b63e32ba2fbe50181df7d40ca2ee33e (diff)
downloadpostgresql-b7b78d24f7fc8d621af40b2e404b6a3f3420e89e.tar.gz
postgresql-b7b78d24f7fc8d621af40b2e404b6a3f3420e89e.zip
Code review for FILLFACTOR patch. Change WITH grammar as per earlier
discussion (including making def_arg allow reserved words), add missed opt_definition for UNIQUE case. Put the reloptions support code in a less random place (I chose to make a new file access/common/reloptions.c). Eliminate header inclusion creep. Make the index options functions safely user-callable (seems like client apps might like to be able to test validity of options before trying to make an index). Reduce overhead for normal case with no options by allowing rd_options to be NULL. Fix some unmaintainably klugy code, including getting rid of Natts_pg_class_fixed at long last. Some stylistic cleanup too, and pay attention to keeping comments in sync with code. Documentation still needs work, though I did fix the omissions in catalogs.sgml and indexam.sgml.
Diffstat (limited to 'src/backend/access/heap')
-rw-r--r--src/backend/access/heap/heapam.c62
-rw-r--r--src/backend/access/heap/hio.c35
2 files changed, 24 insertions, 73 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index cf3344c2009..cf4b920f7da 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.214 2006/07/02 02:23:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/heapam.c,v 1.215 2006/07/03 22:45:37 tgl Exp $
*
*
* INTERFACE ROUTINES
@@ -46,13 +46,9 @@
#include "access/xlogutils.h"
#include "catalog/catalog.h"
#include "catalog/namespace.h"
-#include "commands/defrem.h"
#include "miscadmin.h"
-#include "nodes/parsenodes.h"
-#include "parser/parse_clause.h"
#include "pgstat.h"
#include "storage/procarray.h"
-#include "utils/catcache.h"
#include "utils/inval.h"
#include "utils/relcache.h"
@@ -3592,59 +3588,3 @@ heap_desc(StringInfo buf, uint8 xl_info, char *rec)
else
appendStringInfo(buf, "UNKNOWN");
}
-
-/*
- * Parse options for heaps.
- *
- * relkind Kind of relation
- * options Options as text[]
- */
-bytea *
-heap_option(char relkind, ArrayType *options)
-{
- /*
- * XXX: What fillfactor should be default?
- * overriding databases:
- * - Oracle, DB2 = 90%
- * - SQL Server = 100%
- * non-overriding database:
- * - Firebird = 70%
- */
-#define HEAP_MIN_FILLFACTOR 50
-#define HEAP_DEFAULT_FILLFACTOR 100
-
- int fillfactor;
- HeapOption *result;
-
- DefElem kwds[] =
- {
- { T_DefElem, "fillfactor" },
- };
-
- /*
- * parse options
- */
- OptionParse(options, lengthof(kwds), kwds, true);
-
- /* 0: fillfactor */
- if (kwds[0].arg)
- fillfactor = (int) defGetInt64(&kwds[0]);
- else
- fillfactor = HEAP_DEFAULT_FILLFACTOR;
- if (fillfactor < HEAP_MIN_FILLFACTOR || 100 < fillfactor)
- {
- ereport(ERROR,
- (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("fillfactor=%d should be between %d and 100",
- fillfactor, HEAP_MIN_FILLFACTOR)));
- }
-
- /*
- * build option
- */
- result = (HeapOption *)
- MemoryContextAlloc(CacheMemoryContext, sizeof(HeapOption));
- VARATT_SIZEP(result) = sizeof(HeapOption);
- result->fillfactor = fillfactor;
- return (bytea *) result;
-}
diff --git a/src/backend/access/heap/hio.c b/src/backend/access/heap/hio.c
index 82fb0a3268a..aaaec863ba1 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.62 2006/07/02 02:23:18 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/access/heap/hio.c,v 1.63 2006/07/03 22:45:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -93,6 +93,11 @@ RelationPutHeapTuple(Relation relation,
* any committed data of other transactions. (See heap_insert's comments
* for additional constraints needed for safe usage of this behavior.)
*
+ * We always try to avoid filling existing pages further than the fillfactor.
+ * This is OK since this routine is not consulted when updating a tuple and
+ * keeping it on the same page, which is the scenario fillfactor is meant
+ * to reserve space for.
+ *
* ereport(ERROR) is allowed here, so this routine *must* be called
* before any (unlogged) changes are made in buffer pool.
*/
@@ -103,17 +108,12 @@ RelationGetBufferForTuple(Relation relation, Size len,
Buffer buffer = InvalidBuffer;
Page pageHeader;
Size pageFreeSpace,
- freespace;
+ saveFreeSpace;
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
@@ -125,6 +125,10 @@ RelationGetBufferForTuple(Relation relation, Size len,
(unsigned long) len,
(unsigned long) MaxTupleSize)));
+ /* Compute desired extra freespace due to fillfactor option */
+ saveFreeSpace = RelationGetTargetPageFreeSpace(relation,
+ HEAP_DEFAULT_FILLFACTOR);
+
if (otherBuffer != InvalidBuffer)
otherBlock = BufferGetBlockNumber(otherBuffer);
else
@@ -143,8 +147,14 @@ RelationGetBufferForTuple(Relation relation, Size len,
* When use_fsm is false, we either put the tuple onto the existing target
* page or extend the relation.
*/
-
- targetBlock = relation->rd_targblock;
+ if (len + saveFreeSpace <= MaxTupleSize)
+ targetBlock = relation->rd_targblock;
+ else
+ {
+ /* can't fit, don't screw up FSM request tracking by trying */
+ targetBlock = InvalidBlockNumber;
+ use_fsm = false;
+ }
if (targetBlock == InvalidBlockNumber && use_fsm)
{
@@ -152,7 +162,8 @@ 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 + freespace);
+ targetBlock = GetPageWithFreeSpace(&relation->rd_node,
+ len + saveFreeSpace);
/*
* If the FSM knows nothing of the rel, try the last page before we
@@ -208,7 +219,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
*/
pageHeader = (Page) BufferGetPage(buffer);
pageFreeSpace = PageGetFreeSpace(pageHeader);
- if (len + freespace <= pageFreeSpace)
+ if (len + saveFreeSpace <= pageFreeSpace)
{
/* use this page as future insert target, too */
relation->rd_targblock = targetBlock;
@@ -241,7 +252,7 @@ RelationGetBufferForTuple(Relation relation, Size len,
targetBlock = RecordAndGetPageWithFreeSpace(&relation->rd_node,
targetBlock,
pageFreeSpace,
- len + freespace);
+ len + saveFreeSpace);
}
/*