dbTalk Databases Forums  

Totally basic secondary question

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


Discuss Totally basic secondary question in the comp.databases.berkeley-db forum.



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

Default Totally basic secondary question - 12-30-2005 , 08:06 AM






Let's say I have a large set of stock data, each containing a
timestamp, value, stock_id.

One way I could do this would be to create a primary with an integer
key (network byte order) - upon initial load I just increment it per
each insert w/ the data containing timestamp, stock_id, and value.
Unfortunately that seems to create a bit of redundant data if I index
off of each data "field" and the integer key only being used for
uniqueness purposes (within the primary database, since primary
databases can't have dupes).

If I instead changed it so that primary was keyed off stock_id and an
insert of data where a key already exists (for instance: another
datapoint for the same stock, but different timestamp) to just do a
db.put() w/ the key being the actual stock_id, and the data being
timestamp and stock_id (essentially overwriting the last values stored
in data) - would the key extractors I setup via db.associate() called
during db.put() happen after I overwrote the data for said key?

If so, wouldn't I be able to just allow the secondary index to
implicitly create duplicates, hence giving me a "history" of sorts that
I could then query upon for useful things like timestamp ranges, etc.;
as opposed to having all the (essentially) duplicate data in the main
database (since I'd be using a key I generated) ?


Reply With Quote
  #2  
Old   
Michael Cahill
 
Posts: n/a

Default Re: Totally basic secondary question - 01-08-2006 , 08:47 PM






Quote:
If I instead changed it so that primary was keyed off stock_id and an
insert of data where a key already exists (for instance: another
datapoint for the same stock, but different timestamp) to just do a
db.put() w/ the key being the actual stock_id, and the data being
timestamp and stock_id (essentially overwriting the last values stored
in data) - would the key extractors I setup via db.associate() called
during db.put() happen after I overwrote the data for said key?
The key extractors are called twice -- once for the old version of the
data (the version you are overwriting) to remove the old secondary key
(if necessary), and then again for the new version.

Quote:
If so, wouldn't I be able to just allow the secondary index to
implicitly create duplicates, hence giving me a "history" of sorts that
I could then query upon for useful things like timestamp ranges, etc.;
as opposed to having all the (essentially) duplicate data in the main
database (since I'd be using a key I generated) ?
The callback must return the same secondary key for a given primary key
/ data pair, regardless of when it is called. So you can't use the
secondary support directly to maintain a history of old values.

Regards,
Michael.



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.