mdbx: backport - mdb_drop optimization.

If we know there are no sub-DBs and no overflow pages, skip leaf scan.

Change-Id: I3005aaf0f80821f87d8a88c435fda1a52ee0557a
This commit is contained in:
Howard Chu 2016-04-09 20:42:45 +01:00 committed by Leo Yuriev
parent 828a5d73ca
commit ebf1ae1bdc

11
mdb.c
View File

@ -9986,8 +9986,11 @@ mdb_drop0(MDB_cursor *mc, int subs)
/* DUPSORT sub-DBs have no ovpages/DBs. Omit scanning leaves.
* This also avoids any P_LEAF2 pages, which have no nodes.
* Also if the DB doesn't have sub-DBs and has no overflow
* pages, omit scanning leaves.
*/
if (mc->mc_flags & C_SUB)
if ((mc->mc_flags & C_SUB) ||
(!subs && !mc->mc_db->md_overflow_pages))
mdb_cursor_pop(mc);
mdb_cursor_copy(mc, &mx);
@ -10009,6 +10012,9 @@ mdb_drop0(MDB_cursor *mc, int subs)
pg, omp->mp_pages);
if (unlikely(rc))
goto done;
mc->mc_db->md_overflow_pages -= omp->mp_pages;
if (!mc->mc_db->md_overflow_pages && !subs)
break;
} else if (subs && (ni->mn_flags & F_SUBDATA)) {
mdb_xcursor_init1(mc, ni);
rc = mdb_drop0(&mc->mc_xcursor->mx_cursor, 0);
@ -10016,6 +10022,8 @@ mdb_drop0(MDB_cursor *mc, int subs)
goto done;
}
}
if (!subs && !mc->mc_db->md_overflow_pages)
goto pop;
} else {
if (unlikely((rc = mdb_midl_need(&txn->mt_free_pgs, n)) != 0))
goto done;
@ -10037,6 +10045,7 @@ mdb_drop0(MDB_cursor *mc, int subs)
/* no more siblings, go back to beginning
* of previous level.
*/
pop:
mdb_cursor_pop(mc);
mc->mc_ki[0] = 0;
for (i=1; i<mc->mc_snum; i++) {