BDB- Recno multiple key/data pairs retrieval
984965Jan 15 2013 — edited Jan 15 2013Hey,
I am new to BDB and have just started to work with Berkley DB (ver. 5.3.15) using the Linux C API.
I set up a simple Recno DB which is populated with sequential keys 1,2,3….100. DB Records are in variable length size, although, I am limiting them to a max size.
Below are the environment and DB open flags I am using:
dbenv->open(dbenv, DB_HOME_DIR, DB_SYSTEM_MEM | DB_INIT_LOCK | DB_CREATE | DB_INIT_MPOOL, 0)
dbp->open(dbp, NULL, NULL,DATABASE_NAME, DB_RECNO, DB_CREATE, 0664))
Single record get/put or using cursor to iterate over the all DB works well.
However, I would like to retrieve multiple records in a single get call.
These records can be non-sequential.
For example, retrieving 3 records with the keys 4,89,90. I prefer the bulk buffer to be as minimal as possible (avoiding stack or heap unnecessary memory allocation).
I was reading and saw few examples about using bulk retrieval. Though, I couldn’t find any example for racno bulk get on multiple specified keys.
From what I figured out till now, it seems that I should use:
Get flags: DB_SET_RECNO, DB_MULTIPLE_KEY. And the macros: DB_MULTIPLE_INIT and DB_MULTIPLE_RECNO_NEXT to iterate over a bulk buffer received.
But, I couldn’t figure it out where and how I should specify the list of Keys.
Beside, the BDB man says: "For DB_SET_RECNO to be specified, the underlying database must be of type Btree, and it must have been created with the DB_RECNUM flag."
Does the BDB open with DB_RECNO flag imply that the underlying database is Btree? If creating Btree instead of recno, wouldn’t I loss access performances?
I would appreciate if anyone could supply some guidelines or an example which will assist me to figure it out how to retrieve multiple key/data pairs from a recno DB.
Thanks in advance
Kimel