0I:Berkeley DB Reference Guide: Access Methods[P4

Berkeley DB Reference Guide: Access Methods



7

Btree prefix function (bt_prefix)



FA prefix comparison function for the Btree can be specified as part ofethe db_open call to open the database, specifically by settingdthe bt_prefix element of the DB_INFO structure.

JThe prefix comparison routine is used to compress keys stored on the BtreeCinternal pages by minimizing the number of bytes that are stored toFdistinguish between two keys on the internal pages. The usefulness ofGthis is data dependent, but in some data sets can produce significantly/reduced tree sizes and therefore, search times.

DObviously, the prefix comparison routine must be compatible with theBoverall comparison function of the Btree. If no prefix comparisonGfunction is specified, and no overall comparison function is specified,Da default, lexical prefix comparison function is used. If no prefixGcomparison function is specified, and an overall comparison function is(specified, no prefix comparison is done.

IPrefix comparison routines are passed pointers to keys as arguments. The>keys are represented as DBT structures. The prefix comparisonHfunction must return the number of bytes of the second key argument thatJare necessary to determine that it is greater than the first key argument.GIf the keys are equal, the length of the second key should be returned.CThe only fields that the routines may examine in the DBT structures'are data and size fields.

-An example prefix comparison routine follows:



LAKÿÿ