mirror of
https://github.com/isar/libmdbx.git
synced 2025-02-02 05:38:20 +08:00
mdbx: returns as-is (i.e. negative) the estimation results for an inverted ranges.
This commit is contained in:
parent
8ddfd1f34a
commit
3535e7a6d6
40
src/mdbx.c
40
src/mdbx.c
@ -13423,7 +13423,6 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
MDBX_val origin_begin_key, origin_begin_data;
|
||||
if (!begin_key) {
|
||||
if (unlikely(!end_key)) {
|
||||
/* LY: FIRST..LAST case */
|
||||
@ -13432,8 +13431,7 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
||||
}
|
||||
MDBX_val stub = {0, 0};
|
||||
rc = mdbx_cursor_first(&begin.outer, &stub, &stub);
|
||||
} else {
|
||||
if (end_key && !begin_data && !end_data &&
|
||||
} else if (end_key && !begin_data && !end_data &&
|
||||
(begin_key == end_key || mdbx_is_samedata(begin_key, end_key))) {
|
||||
/* LY: single key case */
|
||||
int exact = 0;
|
||||
@ -13448,8 +13446,7 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
||||
begin.outer.mc_ki[begin.outer.mc_top]);
|
||||
if (F_ISSET(leaf->mn_flags, F_DUPDATA)) {
|
||||
/* LY: return the number of duplicates for given key */
|
||||
mdbx_tassert(txn,
|
||||
begin.outer.mc_xcursor == &begin.inner &&
|
||||
mdbx_tassert(txn, begin.outer.mc_xcursor == &begin.inner &&
|
||||
(begin.inner.mx_cursor.mc_flags & C_INITIALIZED));
|
||||
*size_items =
|
||||
(sizeof(*size_items) >= sizeof(begin.inner.mx_db.md_entries) ||
|
||||
@ -13459,15 +13456,10 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
||||
}
|
||||
}
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
MDBX_cursor_op begin_op = MDBX_SET_RANGE;
|
||||
if (begin_data) {
|
||||
begin_op = MDBX_GET_BOTH_RANGE;
|
||||
origin_begin_data = *begin_data;
|
||||
}
|
||||
origin_begin_key = *begin_key;
|
||||
rc = mdbx_cursor_set(&begin.outer, begin_key, begin_data, begin_op, NULL);
|
||||
} else {
|
||||
rc = mdbx_cursor_set(&begin.outer, begin_key, begin_data,
|
||||
begin_data ? MDBX_GET_BOTH_RANGE : MDBX_SET_RANGE,
|
||||
NULL);
|
||||
}
|
||||
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
@ -13479,18 +13471,12 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
||||
rc = mdbx_cursor_init(&end.outer, txn, dbi);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
return rc;
|
||||
MDBX_val origin_end_key, origin_end_data;
|
||||
if (!end_key) {
|
||||
MDBX_val stub = {0, 0};
|
||||
rc = mdbx_cursor_last(&end.outer, &stub, &stub);
|
||||
} else {
|
||||
MDBX_cursor_op end_op = MDBX_SET_RANGE;
|
||||
if (end_data) {
|
||||
end_op = MDBX_GET_BOTH_RANGE;
|
||||
origin_end_data = *end_data;
|
||||
}
|
||||
origin_end_key = *end_key;
|
||||
rc = mdbx_cursor_set(&end.outer, end_key, end_data, end_op, NULL);
|
||||
rc = mdbx_cursor_set(&end.outer, end_key, end_data,
|
||||
end_data ? MDBX_GET_BOTH_RANGE : MDBX_SET_RANGE, NULL);
|
||||
}
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
if (rc != MDBX_NOTFOUND || !(end.outer.mc_flags & C_INITIALIZED))
|
||||
@ -13502,6 +13488,13 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
||||
return rc;
|
||||
assert(*size_items >= -(ptrdiff_t)begin.outer.mc_db->md_entries &&
|
||||
*size_items <= (ptrdiff_t)begin.outer.mc_db->md_entries);
|
||||
|
||||
#if 0 /* LY: Was decided to returns as-is (i.e. negative) the estimation \
|
||||
* results for an inverted ranges. */
|
||||
|
||||
/* Commit 8ddfd1f34ad7cf7a3c4aa75d2e248ca7e639ed63
|
||||
Change-Id: If59eccf7311123ab6384c4b93f9b1fed5a0a10d1 */
|
||||
|
||||
if (*size_items < 0) {
|
||||
/* LY: inverted range case */
|
||||
*size_items += (ptrdiff_t)begin.outer.mc_db->md_entries;
|
||||
@ -13515,9 +13508,10 @@ int mdbx_estimate_range(MDBX_txn *txn, MDBX_dbi dbi, MDBX_val *begin_key,
|
||||
*size_items = (ptrdiff_t)begin.outer.mc_db->md_entries;
|
||||
}
|
||||
}
|
||||
|
||||
assert(*size_items >= 0 &&
|
||||
*size_items <= (ptrdiff_t)begin.outer.mc_db->md_entries);
|
||||
#endif
|
||||
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user