dbTalk Databases Forums  

No duplicates in indices for you!

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


Discuss No duplicates in indices for you! in the comp.databases.berkeley-db forum.



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

Default No duplicates in indices for you! - 03-16-2006 , 03:49 PM






Setup:
- env with flags = (DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL);
- BTREE database with integer keys & variable length void *data which
is marshalled to one contiguous memory block.
- 3 indices. One for a varable in data*.
- verbose error on.

I create the env and open it with flags above.
I create the database with DB_CREATE open flag in the open().
I create the index flags "DB_CREATE | DB_DUP" in the open().

when I run it with duplicate index_key values I get the following error
message
"Put results in a non-unique secondary key in an index not configured
to support duplicates"

However, when unique index_keys are written to the db, get the right
count. of those.

I looked at some examples and saw that DB_DUP was set for the indices
using set_flags() and not in the open() call. So I did that b/f the
open call
int ret;
"if( (ret = index_ttls->set_flags( DB_DUP )) )"

But when I run the code I get
"Failed to open index: Invalid argument" for the open call

I could post code, but I thought this would surffice. Any ideas on what
the problem is?

thanks,


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

Default Re: No duplicates in indices for you! - 03-16-2006 , 07:19 PM






Hi Dan,

You'll need to delete that index database and recreate it -- you can't
change the duplicates setting of an existing database.

Also, you almost certainly want DB_DUPSORT rather than DB_DUP. The
latter does linear scans of duplicate sets, which gets slow for large
duplicate sets.

Regards,
Michael.


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

Default Re: No duplicates in indices for you! - 03-16-2006 , 10:45 PM



Hey Mike,

the main database (db) is created in the env, and opened with flag
DB_CREATE.
The indices are only initialized [index = new Db(env,
DB_CXX_NO_EXCEPTIONS);].

The variations I tried were
(1) Specify DB_CREATE | DB_DUP flags in the index->open(...)
(2) index_ttls->set_flags( DB_DUP ) first, followed by index->open( )
with flags DB_CREATE.

Then as usual I associate the index with the db [db->associate(NULL,
index, index_fptr, DB_CREATE)]


Results:
(1) causes the No duplicate key error.
(2) causes the invalid key on the open func call.

Sorry about the confusion, but I hope that this illustrates that there
is no way I change the settings of an open dabase. Is there something
that I am doing wrong?

Mike, I also had another programming concern. I am wrapping this db and
indices (there are 3) in a class. I have specified the callbacks for
the key extractors for each of the indices as static members functions
of the class. This wouldnt be the problem would it?

cheers
danwald


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

Default Re: No duplicates in indices for you! - 03-17-2006 , 05:56 AM



Hi,

You need (2):

Quote:
(2) index_ttls->set_flags( DB_DUP ) first, followed by index->open( )
with flags DB_CREATE.
except that:

* you want DB_DUPSORT, not just DB_DUP
* you need to make sure that the database does not exist when you call
index->open. In other words, the database file must be deleted before
you create it with duplicates.

If you are sure that you are creating the database from scratch and the
open call is still failing with an invalid argument exception, make
sure that the error log is enabled (with DB_ENV->set_errfile), and see
whether there is more information about what is going wrong.

Quote:
I am wrapping this db and
indices (there are 3) in a class. I have specified the callbacks for
the key extractors for each of the indices as static members functions
of the class. This wouldnt be the problem would it?
That sounds fine and shouldn't cause any problems.

Michael.



Reply With Quote
  #5  
Old   
danwald
 
Posts: n/a

Default Re: No duplicates in indices for you! - 03-17-2006 , 10:15 AM



Hey Mike,

that worked!
I just deleted the index db files on intialization and all inserts are
successful.

I appreciate your help,
dan


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.