Berkeley DB Reference Guide:
Access Methods

PrevRefNext

Retrieving Btree records by logical record number

The Btree access method optionally supports retrieval by logical record numbers. To configure a Btree to support record numbers, call the DB->set_flags method with the DB_RECNUM flag.

(Btree는 논리적 레코드번호로 리트리벌할 수 있다.레코드넘버를 지원하도록 Btree를 설정하기 위해서는 DB->set_flags(DB_RECNUM flag)를 사용한다.)

 

Configuring a Btree for record numbers should not be done lightly. While often useful, it may significantly slow down the speed at which items can be stored into the database, and can severely impact application throughput. Generally it should be avoided in trees with a need for high write concurrency.

(레코드번호를 지원하도록 Btree를 설정하는 가급적 피해야 한다.왜냐하면 저장속도와 애플리케이션의 처장속도를 급격히 떨어트리기 때문이다.일반적으로 동시적으로 여러 쓰기동작이 필요한 트리에서는 피해야 한다.)

 

To retrieve by record number, use the DB_SET_RECNO flag to the DB->get and DBcursor->c_get methods. The following is an example of a routine that displays the data item for a Btree database created with the DB_RECNUM option.

int
rec_display(dbp, recno)
	DB *dbp;
	db_recno_t recno;
{
	DBT key, data;
	int ret;

memset(&key, 0, sizeof(key)); key.data = &recno; key.size = sizeof(recno); memset(&data, 0, sizeof(data));

if ((ret = dbp->get(dbp, NULL, &key, &data, DB_SET_RECNO)) != 0) return (ret); printf("data for %lu: %.*s\n", (u_long)recno, (int)data.size, (char *)data.data); return (0); }

To determine a key's record number, use the DB_GET_RECNO flag to the DBcursor->c_get method. The following is an example of a routine that displays the record number associated with a specific key.

int
recno_display(dbp, keyvalue)
	DB *dbp;
	char *keyvalue;
{
	DBC *dbcp;
	DBT key, data;
	db_recno_t recno;
	int ret, t_ret;

/* Acquire a cursor for the database. */ if ((ret = dbp->cursor(dbp, NULL, &dbcp, 0)) != 0) { dbp->err(dbp, ret, "DB->cursor"); goto err; }

/* Position the cursor. */ memset(&key, 0, sizeof(key)); key.data = keyvalue; key.size = strlen(keyvalue); memset(&data, 0, sizeof(data)); if ((ret = dbcp->c_get(dbcp, &key, &data, DB_SET)) != 0) { dbp->err(dbp, ret, "DBC->c_get(DB_SET): %s", keyvalue); goto err; }

/* * Request the record number, and store it into appropriately * sized and aligned local memory. */ memset(&data, 0, sizeof(data)); data.data = &recno; data.ulen = sizeof(recno); data.flags = DB_DBT_USERMEM; if ((ret = dbcp->c_get(dbcp, &key, &data, DB_GET_RECNO)) != 0) { dbp->err(dbp, ret, "DBC->c_get(DB_GET_RECNO)"); goto err; }

printf("key for requested key was %lu\n", (u_long)recno);

err: /* Close the cursor. */ if ((t_ret = dbcp->c_close(dbcp)) != 0) { if (ret == 0) ret = t_ret; dbp->err(dbp, ret, "DBC->close"); } return (ret); }


PrevRefNext

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.