@@ -7685,17 +7685,23 @@ mdb_rebalance(MDB_cursor *mc)
7685
7685
{
7686
7686
MDB_node * node ;
7687
7687
int rc ;
7688
- unsigned int ptop , minkeys ;
7688
+ unsigned int ptop , minkeys , thresh ;
7689
7689
MDB_cursor mn ;
7690
7690
indx_t oldki ;
7691
7691
7692
- minkeys = 1 + (IS_BRANCH (mc -> mc_pg [mc -> mc_top ]));
7692
+ if (IS_BRANCH (mc -> mc_pg [mc -> mc_top ])) {
7693
+ minkeys = 1 ;
7694
+ thresh = 1 ;
7695
+ } else {
7696
+ minkeys = 2 ;
7697
+ thresh = FILL_THRESHOLD ;
7698
+ }
7693
7699
DPRINTF (("rebalancing %s page %" Z "u (has %u keys, %.1f%% full)" ,
7694
7700
IS_LEAF (mc -> mc_pg [mc -> mc_top ]) ? "leaf" : "branch" ,
7695
7701
mdb_dbg_pgno (mc -> mc_pg [mc -> mc_top ]), NUMKEYS (mc -> mc_pg [mc -> mc_top ]),
7696
7702
(float )PAGEFILL (mc -> mc_txn -> mt_env , mc -> mc_pg [mc -> mc_top ]) / 10 ));
7697
7703
7698
- if (PAGEFILL (mc -> mc_txn -> mt_env , mc -> mc_pg [mc -> mc_top ]) >= FILL_THRESHOLD &&
7704
+ if (PAGEFILL (mc -> mc_txn -> mt_env , mc -> mc_pg [mc -> mc_top ]) >= thresh &&
7699
7705
NUMKEYS (mc -> mc_pg [mc -> mc_top ]) >= minkeys ) {
7700
7706
DPRINTF (("no need to rebalance page %" Z "u, above fill threshold" ,
7701
7707
mdb_dbg_pgno (mc -> mc_pg [mc -> mc_top ])));
@@ -7829,8 +7835,7 @@ mdb_rebalance(MDB_cursor *mc)
7829
7835
* move one key from it. Otherwise we should try to merge them.
7830
7836
* (A branch page must never have less than 2 keys.)
7831
7837
*/
7832
- minkeys = 1 + (IS_BRANCH (mn .mc_pg [mn .mc_top ]));
7833
- if (PAGEFILL (mc -> mc_txn -> mt_env , mn .mc_pg [mn .mc_top ]) >= FILL_THRESHOLD && NUMKEYS (mn .mc_pg [mn .mc_top ]) > minkeys ) {
7838
+ if (PAGEFILL (mc -> mc_txn -> mt_env , mn .mc_pg [mn .mc_top ]) >= thresh && NUMKEYS (mn .mc_pg [mn .mc_top ]) > minkeys ) {
7834
7839
rc = mdb_node_move (& mn , mc );
7835
7840
if (mc -> mc_ki [ptop ]) {
7836
7841
oldki ++ ;
0 commit comments