mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 18:34:13 +08:00
lmdb: ITS#8221 don't merge branch pages needlessly.
Change-Id: I6b535f70392e081027d8803b6623b0c51f21ec8b
This commit is contained in:
parent
8e7fbfa063
commit
ef72fbaea6
15
mdb.c
15
mdb.c
@ -7888,17 +7888,23 @@ mdb_rebalance(MDB_cursor *mc)
|
|||||||
{
|
{
|
||||||
MDB_node *node;
|
MDB_node *node;
|
||||||
int rc;
|
int rc;
|
||||||
unsigned ptop, minkeys;
|
unsigned ptop, minkeys, thresh;
|
||||||
MDB_cursor mn;
|
MDB_cursor mn;
|
||||||
indx_t oldki;
|
indx_t oldki;
|
||||||
|
|
||||||
minkeys = 1 + (IS_BRANCH(mc->mc_pg[mc->mc_top]));
|
if (IS_BRANCH(mc->mc_pg[mc->mc_top])) {
|
||||||
|
minkeys = 2;
|
||||||
|
thresh = 1;
|
||||||
|
} else {
|
||||||
|
minkeys = 1;
|
||||||
|
thresh = FILL_THRESHOLD;
|
||||||
|
}
|
||||||
mdb_debug("rebalancing %s page %zu (has %u keys, %.1f%% full)",
|
mdb_debug("rebalancing %s page %zu (has %u keys, %.1f%% full)",
|
||||||
IS_LEAF(mc->mc_pg[mc->mc_top]) ? "leaf" : "branch",
|
IS_LEAF(mc->mc_pg[mc->mc_top]) ? "leaf" : "branch",
|
||||||
mdb_dbg_pgno(mc->mc_pg[mc->mc_top]), NUMKEYS(mc->mc_pg[mc->mc_top]),
|
mdb_dbg_pgno(mc->mc_pg[mc->mc_top]), NUMKEYS(mc->mc_pg[mc->mc_top]),
|
||||||
(float)PAGEFILL(mc->mc_txn->mt_env, mc->mc_pg[mc->mc_top]) / 10);
|
(float)PAGEFILL(mc->mc_txn->mt_env, mc->mc_pg[mc->mc_top]) / 10);
|
||||||
|
|
||||||
if (PAGEFILL(mc->mc_txn->mt_env, mc->mc_pg[mc->mc_top]) >= FILL_THRESHOLD &&
|
if (PAGEFILL(mc->mc_txn->mt_env, mc->mc_pg[mc->mc_top]) >= thresh &&
|
||||||
NUMKEYS(mc->mc_pg[mc->mc_top]) >= minkeys) {
|
NUMKEYS(mc->mc_pg[mc->mc_top]) >= minkeys) {
|
||||||
mdb_debug("no need to rebalance page %zu, above fill threshold",
|
mdb_debug("no need to rebalance page %zu, above fill threshold",
|
||||||
mdb_dbg_pgno(mc->mc_pg[mc->mc_top]));
|
mdb_dbg_pgno(mc->mc_pg[mc->mc_top]));
|
||||||
@ -8032,8 +8038,7 @@ mdb_rebalance(MDB_cursor *mc)
|
|||||||
* move one key from it. Otherwise we should try to merge them.
|
* move one key from it. Otherwise we should try to merge them.
|
||||||
* (A branch page must never have less than 2 keys.)
|
* (A branch page must never have less than 2 keys.)
|
||||||
*/
|
*/
|
||||||
minkeys = 1 + (IS_BRANCH(mn.mc_pg[mn.mc_top]));
|
if (PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) >= thresh && NUMKEYS(mn.mc_pg[mn.mc_top]) > minkeys) {
|
||||||
if (PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) >= FILL_THRESHOLD && NUMKEYS(mn.mc_pg[mn.mc_top]) > minkeys) {
|
|
||||||
rc = mdb_node_move(&mn, mc);
|
rc = mdb_node_move(&mn, mc);
|
||||||
if (mc->mc_ki[ptop]) {
|
if (mc->mc_ki[ptop]) {
|
||||||
oldki++;
|
oldki++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user