dbTalk Databases Forums  

A question in retrieving multiple data item

comp.databases.berkeley-db comp.databases.berkeley-db


Discuss A question in retrieving multiple data item in the comp.databases.berkeley-db forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Joe
 
Posts: n/a

Default A question in retrieving multiple data item - 02-13-2006 , 08:03 PM






Dear all,

If I use multiple data items for a single key item, for example, with
key: "k" and data: "data1", "data2", "data3",.... When I do the search
operation, if I know that I just need the third data of the key "k",
what's the most efficient way without retriving the first two data?

Sincerely,
Joe


Reply With Quote
  #2  
Old   
Ron
 
Posts: n/a

Default Re: A question in retrieving multiple data item - 02-14-2006 , 09:44 AM






Hi Joe,

If you want to search by data3 I would set up a secondary Index:

https://iweb.sleepycat.com/support.w.../msg00001.html

If you want to search by K and only retrieve data3 then I would take a
look at the DB_DBT_PARTIAL flag along with dblen and doff fields of
the DBT. That should give you just the data you are interested in.

http://www.sleepycat.com/docs/api_c/...DB_DBT_PARTIAL

Ron


Reply With Quote
  #3  
Old   
Joe
 
Posts: n/a

Default Re: A question in retrieving multiple data item - 02-15-2006 , 10:45 AM



Hi Ron,

I just want to search by "k" and only retrieve data3 as you said. I
have seen the reference for DB_DBT_PARTIAL.

It is to do the partial retrieval or storage of an item. I am not sure
whether it's what I want. I think that data3 is an item, not the
combination of data1, data2 and data3. When I store them into database,
I use the form as put(k, data1), (k, data2), (k, data3). They are three
items for the key "k" and I only want some item, data3, for example.
Could DB_DBT_PARTIAL together with dlen and doff do this?

Sincerely,
Joe


Reply With Quote
  #4  
Old   
Ron
 
Posts: n/a

Default Re: A question in retrieving multiple data item - 02-16-2006 , 03:09 PM



Joe wrote

Quote:
Hi Ron,

I just want to search by "k" and only retrieve data3 as you said. I
have seen the reference for DB_DBT_PARTIAL.

It is to do the partial retrieval or storage of an item. I am not sure
whether it's what I want. I think that data3 is an item, not the
combination of data1, data2 and data3. When I store them into database,
I use the form as put(k, data1), (k, data2), (k, data3).
Glad you explained that since I thought you were referring to a single
record.

If all 3 records have the same key, I'm not sure how you know which one
you want so I am assuming you just know which one.

In this case, you would use DBcursor->c_get() three times. The first
time would be using the DB_SET flag and the next 2 times would be
simply using the DB_NEXT flag.

http://www.sleepycat.com/docs/api_c/dbc_get.html

If the data records are very large and you know in advance which record
you want (with the same key) you could use the optimization technique I
mentioned in my first reply. That is, use DB_DBT_PARTIAL and dlen=0
as flags on your dbt. For further information:

http://www.sleepycat.com/docs/api_c/dbt_class.html

Ron



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.