2727 * insertion would cause a split (and not only of the leaf page; the need
2828 * for a split would cascade right up the tree). The steady-state load
2929 * factor for btrees is usually estimated at 70%. We choose to pack leaf
30- * pages to the user-controllable fill factor while upper pages are always
31- * packed to 70%. This gives us reasonable density (there aren't many upper
32- * pages if the keys are reasonable-size) without incurring a lot of cascading
33- * splits during early insertions.
30+ * pages to the user-controllable fill factor (default 90%) while upper pages
31+ * are always packed to 70%. This gives us reasonable density (there aren't
32+ * many upper pages if the keys are reasonable-size) without risking a lot of
33+ * cascading splits during early insertions.
3434 *
3535 * Formerly the index pages being built were kept in shared buffers, but
3636 * that is of no value (since other backends have no interest in them yet)
5757 * Portions Copyright (c) 1994, Regents of the University of California
5858 *
5959 * IDENTIFICATION
60- * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.104 2006/07/03 22:45:37 tgl Exp $
60+ * $PostgreSQL: pgsql/src/backend/access/nbtree/nbtsort.c,v 1.105 2006/07/11 21:05:57 tgl Exp $
6161 *
6262 *-------------------------------------------------------------------------
6363 */
@@ -349,7 +349,7 @@ _bt_pagestate(BTWriteState *wstate, uint32 level)
349349 state -> btps_level = level ;
350350 /* set "full" threshold based on level. See notes at head of file. */
351351 if (level > 0 )
352- state -> btps_full = (BLCKSZ * (100 - BTREE_MIN_FILLFACTOR ) / 100 );
352+ state -> btps_full = (BLCKSZ * (100 - BTREE_NONLEAF_FILLFACTOR ) / 100 );
353353 else
354354 state -> btps_full = RelationGetTargetPageFreeSpace (wstate -> index ,
355355 BTREE_DEFAULT_FILLFACTOR );
@@ -499,11 +499,16 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
499499 "Consider a function index of an MD5 hash of the value, "
500500 "or use full text indexing." )));
501501
502- if (pgspc < itupsz || pgspc < state -> btps_full )
502+ /*
503+ * Check to see if page is "full". It's definitely full if the item
504+ * won't fit. Otherwise, compare to the target freespace derived from
505+ * the fillfactor. However, we must put at least two items on each
506+ * page, so disregard fillfactor if we don't have that many.
507+ */
508+ if (pgspc < itupsz || (pgspc < state -> btps_full && last_off > P_FIRSTKEY ))
503509 {
504510 /*
505- * Item won't fit on this page, or we feel the page is full enough
506- * already. Finish off the page and write it out.
511+ * Finish off the page and write it out.
507512 */
508513 Page opage = npage ;
509514 BlockNumber oblkno = nblkno ;
@@ -522,8 +527,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
522527 * rearrange the old page so that the 'last item' becomes its high key
523528 * rather than a true data item. There had better be at least two
524529 * items on the page already, else the page would be empty of useful
525- * data. (Hence, we must allow pages to be packed at least 2/3rds
526- * full; the 70% figure used above is close to minimum.)
530+ * data.
527531 */
528532 Assert (last_off > P_FIRSTKEY );
529533 ii = PageGetItemId (opage , last_off );
0 commit comments