88 * Portions Copyright (c) 1994, Regents of the University of California
99 *
1010 * IDENTIFICATION
11- * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.139 2006/06/28 12:00:14 teodor Exp $
11+ * $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.140 2006/07/02 02:23:18 momjian Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -44,6 +44,7 @@ static void gistbuildCallback(Relation index,
4444void * state );
4545static void gistdoinsert (Relation r ,
4646IndexTuple itup ,
47+ Size freespace ,
4748GISTSTATE * GISTstate );
4849static void gistfindleaf (GISTInsertState * state ,
4950GISTSTATE * giststate );
@@ -197,7 +198,8 @@ gistbuildCallback(Relation index,
197198 * you're inserting single tups, but not when you're initializing the
198199 * whole index at once.
199200 */
200- gistdoinsert (index ,itup ,& buildstate -> giststate );
201+ gistdoinsert (index ,itup ,IndexGetPageFreeSpace (index ),
202+ & buildstate -> giststate );
201203
202204buildstate -> indtuples += 1 ;
203205MemoryContextSwitchTo (oldCtx );
@@ -236,7 +238,7 @@ gistinsert(PG_FUNCTION_ARGS)
236238values ,isnull , true/* size is currently bogus */ );
237239itup -> t_tid = * ht_ctid ;
238240
239- gistdoinsert (r ,itup ,& giststate );
241+ gistdoinsert (r ,itup ,0 , & giststate );
240242
241243/* cleanup */
242244freeGISTstate (& giststate );
@@ -253,7 +255,7 @@ gistinsert(PG_FUNCTION_ARGS)
253255 * so it does not bother releasing palloc'd allocations.
254256 */
255257static void
256- gistdoinsert (Relation r ,IndexTuple itup ,GISTSTATE * giststate )
258+ gistdoinsert (Relation r ,IndexTuple itup ,Size freespace , GISTSTATE * giststate )
257259{
258260GISTInsertState state ;
259261
@@ -263,6 +265,7 @@ gistdoinsert(Relation r, IndexTuple itup, GISTSTATE *giststate)
263265state .itup [0 ]= (IndexTuple )palloc (IndexTupleSize (itup ));
264266memcpy (state .itup [0 ],itup ,IndexTupleSize (itup ));
265267state .ituplen = 1 ;
268+ state .freespace = freespace ;
266269state .r = r ;
267270state .key = itup -> t_tid ;
268271state .needInsertComplete = true;
@@ -294,7 +297,11 @@ gistplacetopage(GISTInsertState *state, GISTSTATE *giststate)
294297 */
295298
296299
297- if (gistnospace (state -> stack -> page ,state -> itup ,state -> ituplen , (is_leaf ) ?InvalidOffsetNumber :state -> stack -> childoffnum ))
300+ /*
301+ * XXX: If we want to change fillfactors between node and leaf,
302+ * fillfactor = (is_leaf ? state->leaf_fillfactor : state->node_fillfactor)
303+ */
304+ if (gistnospace (state -> stack -> page ,state -> itup ,state -> ituplen , (is_leaf ) ?InvalidOffsetNumber :state -> stack -> childoffnum ,state -> freespace ))
298305{
299306/* no space for insertion */
300307IndexTuple * itvec ;