mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 22:34:12 +08:00
mdbx: refine mdbx_cursor_set()
around the exact-flag.
Change-Id: Ifbad6bb4a3a4eabaf85c7986f9566705d53c45b9
This commit is contained in:
parent
1b21703c7b
commit
77e84ccca8
25
src/core.c
25
src/core.c
@ -11681,9 +11681,6 @@ int mdbx_get(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *key, MDBX_val *data) {
|
|||||||
|
|
||||||
int mdbx_get_equal_or_great(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
int mdbx_get_equal_or_great(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
||||||
MDBX_val *data) {
|
MDBX_val *data) {
|
||||||
DKBUF;
|
|
||||||
mdbx_debug("===> get db %u key [%s]", dbi, DKEY(key));
|
|
||||||
|
|
||||||
int rc = check_txn(txn, MDBX_TXN_BLOCKED);
|
int rc = check_txn(txn, MDBX_TXN_BLOCKED);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
@ -11702,20 +11699,13 @@ int mdbx_get_equal_or_great(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *key,
|
|||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
MDBX_val save_data = *data;
|
|
||||||
int exact = 0;
|
int exact = 0;
|
||||||
rc = mdbx_cursor_set(&cx.outer, key, data, MDBX_SET_RANGE, &exact);
|
rc = mdbx_cursor_set(
|
||||||
|
&cx.outer, key, data,
|
||||||
|
cx.outer.mc_xcursor ? MDBX_GET_BOTH_RANGE : MDBX_SET_RANGE, &exact);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if (exact && (txn->mt_dbs[dbi].md_flags & MDBX_DUPSORT) != 0) {
|
|
||||||
*data = save_data;
|
|
||||||
exact = 0;
|
|
||||||
rc = mdbx_cursor_set(&cx.outer, key, data, MDBX_GET_BOTH_RANGE, &exact);
|
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
|
||||||
return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
return exact ? MDBX_SUCCESS : MDBX_RESULT_TRUE;
|
return exact ? MDBX_SUCCESS : MDBX_RESULT_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -12187,9 +12177,10 @@ set1:
|
|||||||
if (op == MDBX_SET || op == MDBX_SET_KEY || op == MDBX_SET_RANGE) {
|
if (op == MDBX_SET || op == MDBX_SET_KEY || op == MDBX_SET_RANGE) {
|
||||||
rc = mdbx_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
|
rc = mdbx_cursor_first(&mc->mc_xcursor->mx_cursor, data, NULL);
|
||||||
} else {
|
} else {
|
||||||
int ex2 = 0, *ex2p = (op == MDBX_GET_BOTH) ? &ex2 : NULL;
|
int dummy = 0;
|
||||||
rc = mdbx_cursor_set(&mc->mc_xcursor->mx_cursor, data, NULL,
|
rc = mdbx_cursor_set(&mc->mc_xcursor->mx_cursor, data, NULL,
|
||||||
MDBX_SET_RANGE, ex2p);
|
MDBX_SET_RANGE,
|
||||||
|
(op == MDBX_GET_BOTH_RANGE) ? exactp : &dummy);
|
||||||
}
|
}
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
return rc;
|
return rc;
|
||||||
@ -12231,6 +12222,7 @@ set1:
|
|||||||
if (rc) {
|
if (rc) {
|
||||||
if (op != MDBX_GET_BOTH_RANGE || rc > 0)
|
if (op != MDBX_GET_BOTH_RANGE || rc > 0)
|
||||||
return MDBX_NOTFOUND;
|
return MDBX_NOTFOUND;
|
||||||
|
*exactp = 0;
|
||||||
rc = 0;
|
rc = 0;
|
||||||
}
|
}
|
||||||
*data = olddata;
|
*data = olddata;
|
||||||
@ -12420,8 +12412,7 @@ int mdbx_cursor_get(MDBX_cursor *mc, MDBX_val *key, MDBX_val *data,
|
|||||||
case MDBX_SET_RANGE:
|
case MDBX_SET_RANGE:
|
||||||
if (unlikely(key == NULL))
|
if (unlikely(key == NULL))
|
||||||
return MDBX_EINVAL;
|
return MDBX_EINVAL;
|
||||||
rc = mdbx_cursor_set(mc, key, data, op,
|
rc = mdbx_cursor_set(mc, key, data, op, &exact);
|
||||||
op == MDBX_SET_RANGE ? NULL : &exact);
|
|
||||||
break;
|
break;
|
||||||
case MDBX_GET_MULTIPLE:
|
case MDBX_GET_MULTIPLE:
|
||||||
if (unlikely(data == NULL || !(mc->mc_flags & C_INITIALIZED)))
|
if (unlikely(data == NULL || !(mc->mc_flags & C_INITIALIZED)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user