mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
Add FILLFACTOR to CREATE INDEX.
ITAGAKI Takahiro
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.139 2006/06/28 12:00:14 teodor Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.140 2006/07/02 02:23:18 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -44,6 +44,7 @@ static void gistbuildCallback(Relation index,
|
||||
void *state);
|
||||
static void gistdoinsert(Relation r,
|
||||
IndexTuple itup,
|
||||
Size freespace,
|
||||
GISTSTATE *GISTstate);
|
||||
static void gistfindleaf(GISTInsertState *state,
|
||||
GISTSTATE *giststate);
|
||||
@ -197,7 +198,8 @@ gistbuildCallback(Relation index,
|
||||
* you're inserting single tups, but not when you're initializing the
|
||||
* whole index at once.
|
||||
*/
|
||||
gistdoinsert(index, itup, &buildstate->giststate);
|
||||
gistdoinsert(index, itup, IndexGetPageFreeSpace(index),
|
||||
&buildstate->giststate);
|
||||
|
||||
buildstate->indtuples += 1;
|
||||
MemoryContextSwitchTo(oldCtx);
|
||||
@ -236,7 +238,7 @@ gistinsert(PG_FUNCTION_ARGS)
|
||||
values, isnull, true /* size is currently bogus */);
|
||||
itup->t_tid = *ht_ctid;
|
||||
|
||||
gistdoinsert(r, itup, &giststate);
|
||||
gistdoinsert(r, itup, 0, &giststate);
|
||||
|
||||
/* cleanup */
|
||||
freeGISTstate(&giststate);
|
||||
@ -253,7 +255,7 @@ gistinsert(PG_FUNCTION_ARGS)
|
||||
* so it does not bother releasing palloc'd allocations.
|
||||
*/
|
||||
static void
|
||||
gistdoinsert(Relation r, IndexTuple itup, GISTSTATE *giststate)
|
||||
gistdoinsert(Relation r, IndexTuple itup, Size freespace, GISTSTATE *giststate)
|
||||
{
|
||||
GISTInsertState state;
|
||||
|
||||
@ -263,6 +265,7 @@ gistdoinsert(Relation r, IndexTuple itup, GISTSTATE *giststate)
|
||||
state.itup[0] = (IndexTuple) palloc(IndexTupleSize(itup));
|
||||
memcpy(state.itup[0], itup, IndexTupleSize(itup));
|
||||
state.ituplen = 1;
|
||||
state.freespace = freespace;
|
||||
state.r = r;
|
||||
state.key = itup->t_tid;
|
||||
state.needInsertComplete = true;
|
||||
@ -294,7 +297,11 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
|
||||
*/
|
||||
|
||||
|
||||
if (gistnospace(state->stack->page, state->itup, state->ituplen, (is_leaf) ? InvalidOffsetNumber : state->stack->childoffnum))
|
||||
/*
|
||||
* XXX: If we want to change fillfactors between node and leaf,
|
||||
* fillfactor = (is_leaf ? state->leaf_fillfactor : state->node_fillfactor)
|
||||
*/
|
||||
if (gistnospace(state->stack->page, state->itup, state->ituplen, (is_leaf) ? InvalidOffsetNumber : state->stack->childoffnum, state->freespace))
|
||||
{
|
||||
/* no space for insertion */
|
||||
IndexTuple *itvec;
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.16 2006/06/28 12:00:14 teodor Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistutil.c,v 1.17 2006/07/02 02:23:18 momjian Exp $
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@ -58,9 +58,9 @@ gistfillbuffer(Relation r, Page page, IndexTuple *itup,
|
||||
* Check space for itup vector on page
|
||||
*/
|
||||
bool
|
||||
gistnospace(Page page, IndexTuple *itvec, int len, OffsetNumber todelete)
|
||||
gistnospace(Page page, IndexTuple *itvec, int len, OffsetNumber todelete, Size freespace)
|
||||
{
|
||||
unsigned int size = 0, deleted = 0;
|
||||
unsigned int size = freespace, deleted = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
@ -82,6 +82,7 @@ gistfitpage(IndexTuple *itvec, int len) {
|
||||
for(i=0;i<len;i++)
|
||||
size += IndexTupleSize(itvec[i]) + sizeof(ItemIdData);
|
||||
|
||||
/* TODO: Consider fillfactor */
|
||||
return (size <= GiSTPageSize);
|
||||
}
|
||||
|
||||
@ -634,3 +635,16 @@ gistNewBuffer(Relation r)
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Datum
|
||||
gistoption(PG_FUNCTION_ARGS)
|
||||
{
|
||||
#define GIST_DEFAULT_FILLFACTOR 90
|
||||
#define GIST_MIN_FILLFACTOR 50
|
||||
|
||||
ArrayType *options = (ArrayType *) PG_GETARG_POINTER(0);
|
||||
|
||||
/* Use index common routine. */
|
||||
PG_RETURN_BYTEA_P(genam_option(options,
|
||||
GIST_MIN_FILLFACTOR, GIST_DEFAULT_FILLFACTOR));
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.22 2006/05/19 11:10:25 teodor Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistvacuum.c,v 1.23 2006/07/02 02:23:18 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -376,7 +376,7 @@ gistVacuumUpdate(GistVacuum *gv, BlockNumber blkno, bool needunion)
|
||||
if (curlenaddon)
|
||||
{
|
||||
/* insert updated tuples */
|
||||
if (gistnospace(tempPage, addon, curlenaddon, InvalidOffsetNumber)) {
|
||||
if (gistnospace(tempPage, addon, curlenaddon, InvalidOffsetNumber, 0)) {
|
||||
/* there is no space on page to insert tuples */
|
||||
res = vacuumSplitPage(gv, tempPage, buffer, addon, curlenaddon);
|
||||
tempPage=NULL; /* vacuumSplitPage() free tempPage */
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.20 2006/05/19 17:15:41 teodor Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/gist/gistxlog.c,v 1.21 2006/07/02 02:23:18 momjian Exp $
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "postgres.h"
|
||||
@ -690,7 +690,7 @@ gistContinueInsert(gistIncompleteInsert *insert)
|
||||
* that wiil be enough space....
|
||||
*/
|
||||
|
||||
if (gistnospace(pages[0], itup, lenitup, *todelete))
|
||||
if (gistnospace(pages[0], itup, lenitup, *todelete, 0))
|
||||
{
|
||||
|
||||
/* no space left on page, so we must split */
|
||||
|
Reference in New Issue
Block a user