Skip to content

Commit 4b01cb3

Browse files
committed
ITS#8221 don't merge branch pages needlessly
1 parent ddb7478 commit 4b01cb3

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

libraries/liblmdb/mdb.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7685,17 +7685,23 @@ mdb_rebalance(MDB_cursor *mc)
76857685
{
76867686
MDB_node *node;
76877687
int rc;
7688-
unsigned int ptop, minkeys;
7688+
unsigned int ptop, minkeys, thresh;
76897689
MDB_cursor mn;
76907690
indx_t oldki;
76917691

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+
}
76937699
DPRINTF(("rebalancing %s page %"Z"u (has %u keys, %.1f%% full)",
76947700
IS_LEAF(mc->mc_pg[mc->mc_top]) ? "leaf" : "branch",
76957701
mdb_dbg_pgno(mc->mc_pg[mc->mc_top]), NUMKEYS(mc->mc_pg[mc->mc_top]),
76967702
(float)PAGEFILL(mc->mc_txn->mt_env, mc->mc_pg[mc->mc_top]) / 10));
76977703

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 &&
76997705
NUMKEYS(mc->mc_pg[mc->mc_top]) >= minkeys) {
77007706
DPRINTF(("no need to rebalance page %"Z"u, above fill threshold",
77017707
mdb_dbg_pgno(mc->mc_pg[mc->mc_top])));
@@ -7829,8 +7835,7 @@ mdb_rebalance(MDB_cursor *mc)
78297835
* move one key from it. Otherwise we should try to merge them.
78307836
* (A branch page must never have less than 2 keys.)
78317837
*/
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) {
78347839
rc = mdb_node_move(&mn, mc);
78357840
if (mc->mc_ki[ptop]) {
78367841
oldki++;

0 commit comments

Comments
 (0)