ITS#8557 fix mdb_cursor_last

Optimize mdb_page_search_root(PS_LAST) when cursor is already near
last position, ignoring C_EOF flag for now.
ntdll
Howard Chu 8 years ago
parent 59ac317d2a
commit d84dee516f
  1. 15
      libraries/liblmdb/mdb.c

@ -6204,8 +6204,17 @@ mdb_page_search_root(MDB_cursor *mc, MDB_val *key, int flags)
if (flags & (MDB_PS_FIRST|MDB_PS_LAST)) { if (flags & (MDB_PS_FIRST|MDB_PS_LAST)) {
i = 0; i = 0;
if (flags & MDB_PS_LAST) if (flags & MDB_PS_LAST) {
i = NUMKEYS(mp) - 1; i = NUMKEYS(mp) - 1;
/* if already init'd, see if we're already in right place */
if (mc->mc_flags & C_INITIALIZED) {
if (mc->mc_ki[mc->mc_top] == i) {
mp = mc->mc_pg[mc->mc_top];
mc->mc_top = mc->mc_snum++;
goto ready;
}
}
}
} else { } else {
int exact; int exact;
node = mdb_node_search(mc, key, &exact); node = mdb_node_search(mc, key, &exact);
@ -6231,6 +6240,7 @@ mdb_page_search_root(MDB_cursor *mc, MDB_val *key, int flags)
if ((rc = mdb_cursor_push(mc, mp))) if ((rc = mdb_cursor_push(mc, mp)))
return rc; return rc;
ready:
if (flags & MDB_PS_MODIFY) { if (flags & MDB_PS_MODIFY) {
if ((rc = mdb_page_touch(mc)) != 0) if ((rc = mdb_page_touch(mc)) != 0)
return rc; return rc;
@ -7009,8 +7019,6 @@ mdb_cursor_last(MDB_cursor *mc, MDB_val *key, MDB_val *data)
mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF); mc->mc_xcursor->mx_cursor.mc_flags &= ~(C_INITIALIZED|C_EOF);
} }
if (!(mc->mc_flags & C_EOF)) {
if (!(mc->mc_flags & C_INITIALIZED) || mc->mc_top) { if (!(mc->mc_flags & C_INITIALIZED) || mc->mc_top) {
rc = mdb_page_search(mc, NULL, MDB_PS_LAST); rc = mdb_page_search(mc, NULL, MDB_PS_LAST);
if (rc != MDB_SUCCESS) if (rc != MDB_SUCCESS)
@ -7018,7 +7026,6 @@ mdb_cursor_last(MDB_cursor *mc, MDB_val *key, MDB_val *data)
} }
mdb_cassert(mc, IS_LEAF(mc->mc_pg[mc->mc_top])); mdb_cassert(mc, IS_LEAF(mc->mc_pg[mc->mc_top]));
}
mc->mc_ki[mc->mc_top] = NUMKEYS(mc->mc_pg[mc->mc_top]) - 1; mc->mc_ki[mc->mc_top] = NUMKEYS(mc->mc_pg[mc->mc_top]) - 1;
mc->mc_flags |= C_INITIALIZED|C_EOF; mc->mc_flags |= C_INITIALIZED|C_EOF;
leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]); leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);

Loading…
Cancel
Save