views:

31

answers:

2

Is there a way to get only the length (in bytes) of a value stored in BDB? I don't need the entire data array, only its size.

A: 

I'm assuming you're using the JE version (or the Java binding of BDB) in which case, once you get the DatabaseEntry of the desired key, getSize() should give you what you want.

If you're using the C binding, check the DBT handle's size field.

brianmckenna
I'm looking specifically for a way to avoid retrieving the entire entry, because I need only its size.
Shooshpanchick
+1  A: 

If you don't want to have to retrieve the entire entry and aren't using DPL, I'd say you should add a secondary index on the size of the stored byte array and make sure that your DAO properly updates this value on any save or updates. You could add a KeyCreator which creates a secondary size key in a secondary database based on the record.

What type of query are you trying to perform? Are you wanted to search for all records of a given size? Or are you wanting to know the size of a certain record before you retrieve it? I think the latter question is harder to answer.

jasonmp85
In my case, the value stored under key is a (very) long list of document IDs. I wanted to be able to retrieve first, say, 100 of them and display to user like "100 out of 5`000`000".At the moment, that task is cancelled, but creating secondary index is what I'd probably do. Thanks!
Shooshpanchick