开发者

Berkeley DB: Retrieving only keys

开发者 https://www.devze.com 2023-01-25 10:50 出处:网络
I am retrieving a range of keys in Berkeley DB database using a cursor. I do a get us开发者_开发技巧ing the DB_SET_RANGE flag followed by a number of gets using the DB_NEXT flag.

I am retrieving a range of keys in Berkeley DB database using a cursor. I do a get us开发者_开发技巧ing the DB_SET_RANGE flag followed by a number of gets using the DB_NEXT flag.

Everything works fine. The problem is I only need the keys for this particular operation but I always get both keys and associated values. Since the values can get pretty large (hundreds of kilobytes), I would like to avoid retrieving them. Any ideas?


Interesting problem. I dont believe that it is possible to just get the keys alone.

One approach would be to store the keys in their own database with zero data. If you cant stand the duplication, I think the best approach would be to bulk read, since you have by definition good locality of reference for your range of values. Use the DB_MULTIPLE_KEY flag in your DBC::get() call, and a large DBT buffer for data. Use a DbMultipleKeyDataIterator to iterate the bulk retrieved block.

This should improve things as the consecutive leaf items in your retrieval will result in efficient page copies to the DBT temporary buffer you use in DBC::get.


I think you can use the DatabaseEntry.setPartial method (with a len=0) to tell the BerkeleyDB engine to fetch no data from the value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号