# Why can I only range read 2857 keys?

**URL:** <https://forums.foundationdb.org/t/why-can-i-only-range-read-2857-keys/1517>\
**Category:** Using FoundationDB\
**Created:** [July 13, 2019, 6:06am UTC](https://forums.foundationdb.org/t/why-can-i-only-range-read-2857-keys/1517 "2019-07-13T06:06:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonahwest](https://avatars.discourse-cdn.com/v4/letter/j/90db22/32.png) [@jonahwest](https://forums.foundationdb.org/u/jonahwest)\
**Post date:** [July 13, 2019, 6:06am UTC](https://forums.foundationdb.org/t/why-can-i-only-range-read-2857-keys/1517/1 "2019-07-13T06:06:58Z")

</div>

In the C API, when doing a range read with:

```
fdb_transaction_get_range(tr, FDB_KEYSEL_FIRST_GREATER_OR_EQUAL(start, 1), FDB_KEYSEL_FIRST_GREATER_OR_EQUAL(end, 1), 0, 0, FDB_STREAMING_MODE_WANT_ALL, 0, 0, 0);

```

then waiting for the future, and extracting the `FDBKeyValue` array with:

```
fdb_future_get_keyvalue_array(future, &keyvalue, &count, &more);

```

only the first 2857 keys are returned (`count` is `2857`). Calling `fdb_future_get_keyvalue_array()` again does not return the next 2857 keys, as one could expect.

Why am I only getting the first 2857 keys in the database and how can I get every single key? Thanks!

---

<div class="post-metadata">

**Author:** ![KrzysFR](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/krzysfr/32/43_2.png) [@KrzysFR](https://forums.foundationdb.org/u/KrzysFR)\
**Post date:** [July 13, 2019, 7:32pm UTC](https://forums.foundationdb.org/t/why-can-i-only-range-read-2857-keys/1517/2 "2019-07-13T19:32:13Z")

</div>

The get\_range operation is returning data one batch at a time, so you are supposed to check the value returned in `more` to know if you need to call it again to get the rest of the range. (see [https://apple.github.io/foundationdb/api-c.html?highlight=fdb\_transaction\_get\_range#c.fdb\_transaction\_get\_range](https://apple.github.io/foundationdb/api-c.html?highlight=fdb_transaction_get_range#c.fdb_transaction_get_range))

The `FDB_STREAMING_MODE_WANT_ALL` here does not mean “in a single batch”, but should probably be understood as “in as few batches as possible”, and in your case, 2857 keys is considered the ideal batch size. The other streaming modes are for cases where you will inspect the data as they arrive and stop iterating before the end of the range (so it would be wasteful if the db would send you ALL the keys you are are only interested in a few).

So in your case, you’ll have to check if `more` is non-zero after the call, and call `fdb_transaction_get_range` again and again, using FDB\_KEYSEL\_FIRST\_GREATER\_THAN(…) on the last key of the previous batch, and stopping when `more` is 0.

Be warned though, that reading an unbounded range in a single transaction will probably not work as you’d expect, due to the 5 seconds lifetime of each transaction: it is possible that you end up taking more than 5 seconds to read a very large range, meaning that you’ll need to figure out how to read large quantities of data across multiple transactions without the safety net of ACID transactions.
