Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btr ee,hash,hashing,transaction,transactions,locking,logging,access method,access me thods,java,C,C++

### Berkeley DB Reference Guide: Access Methods

# Sorting duplicate data items

Both the Btree and Hash access methods support duplicates, i.e., a key item can have more than one data item associated with it. To create a database that can support duplicates, you should specify the DB_DUP flag in the DB_INFO structure.

It is also possible to maintain duplicate records in sorted order. This will minimize the effort needed to search them and to perform logical joins using them. To create a database where the duplicates are sorted, you should specify the DB_DUPSORT flag in the DB_INFO structure.

The sort order for duplicates in the underlying database can also be specified as part of the db_open call to open the database, specifically by setting the dup_compare element of the DB_INFO structure. If the DB_DUPSORT flag is specified and no comparison routine is specified, duplicates are maintained in a default lexical order.

For information on how searching and insertion behaves in the presence of duplicates (sorted or not), see the DB->get, DB->put, DBcursor->c_get and DBcursor->c_put functions.