Berkeley DB Reference Guide:
Access Methods

PrevRefNext

Logical record numbers

The Berkeley DB Btree, Queue and Recno access methods can operate on logical record numbers. Record numbers are 1-based, not 0-based, that is, the first record in a database is record number 1.

(DB Btree, Queue, Recno ¾×¼¼½º¸Þ¼Òµå´Â ³í¸®ÀûÀÎ ·¹ÄÚµå¹øÈ£·Î ÀÛµ¿°¡´ÉÇÏ´Ù.·¹ÄÚµå¹øÈ£´Â 1ºÎÅͽÃÀÛÇÑ´Ù.)

In all cases for the Queue and Recno access methods, and when calling the Btree access method using the DB->get and DBcursor->c_get methods with the DB_SET_RECNO flag specified, the data field of the key DBT must be a pointer to a memory location of type db_recno_t, as typedef'd in the standard Berkeley DB include file. The size field of the key DBT should be the size of that type (for example, "sizeof(db_recno_t)" in the C programming language). The db_recno_t type is a 32-bit unsigned type, which limits the number of logical records in a Queue or Recno database, and the maximum logical record which may be directly retrieved from a Btree database, to 4,294,967,295.

(Queue , RecnoÀÇ ¸ðµç°æ¿ì¿Í BtreeÀÇ  DB->get ,DBcursor->c_get¸¦ DB_SET_RECNO flag·Î ¼³Á¤ÈÄ È£ÃâÇÒ¶§ DBTÀÇ dataÇʵå´Â Ç×»ó db_recno_t ŸÀÔÀÇ ¸Þ¸ð¸® À§Ä¡¸¦ °¡¸£ÄÑ¾ß ÇÑ´Ù.DBT ÀÇ size Çʵå´Â ŸÀÔÀÇ Å©±â·Î ¼³Á¤µÈ´Ù.32bit unsigned ŸÀÔÀÎ db_recno_t Àº À¸·Î Queue ¶Ç´Â Recno ÀÇ ³í¸®ÀûÀÎ ·¹ÄÚµå¹øÈ£ÀÇ ÇÑ°è¹øÈ£ÀÌ°í ¶ÇÇÑ BTree·Î ºÎÅÍ Á÷Á¢ ¾òÀ»¼öÀÖ´Â ³í¸®Àû·¹ÄÚµå ¼öÀÇ ÃÖ´ë°ªÀÌ´Ù.ÀÌ°ªÀÇ ÃÖ´ë°ªÀº Áï 4,294,967,295ÀÌ´Ù.)

¡¡

Record numbers in Queue databases wrap around. When the tail of the queue reaches the maximum record number, the next record appended will be given record number 1. If the head of the queue ever catches up to the tail of the queue, the Berkeley DB methods will return the system error EFBIG.

(QueueÀÇ ·¹ÄÚµå¹øÈ£´Â ¿øÇüÀûÀÌ´Ù.Áï QueueÀÇ ·¹ÄÚµå¹øÈ£°¡ ÃÖ´ë°ª¿¡ µµ´ÞÇÒ¶§ Ãß°¡µÇ´Â ´ÙÀ½·¹ÄÚµåÀÇ ¹øÈ£´Â 1À̵ȴÙ.¸¸¾à Çص尡 Å¥ÀÇ Å×ÀÏÀ» µû¶óÀâ°Ô µÇ¸é EFBIG¸¦ ¸®ÅÏÇÑ´Ù.)

Record numbers in Recno databases can be configured to run in either mutable or fixed mode: mutable, where logical record numbers change as records are deleted or inserted, and fixed, where record numbers never change regardless of the database operation. Record numbers in Queue databases are always fixed, and never change regardless of the database operation. Record numbers in Btree databases are always mutable, and as records are deleted or inserted, the logical record number for other records in the database can change. See Logically renumbering records for more information.

(Recno ÀÇ ·¹ÄÚµå¹øÈ£´Â º¯È­¶Ç´Â °íÁ¤¸ðµå·Î ¼³Á¤µÉ¼ö ÀÖ´Ù.º¯È­¸ðµå¿¡¼­´Â ·¹Äڵ尡 »èÁ¦¶Ç´Â »ðÀԵɶ§ ·¹ÄÚµå¹øÈ£°¡ º¯ÇÏ°Ô µÈ´Ù.°íÁ¤¸ðµå¿¡¼­´Â ·¹ÄÚµå¹øÈ£´Â º¯È­ÇÏÁö ¾Ê´Â´Ù.BtreeÀÇ ·¹ÄÚµå¹øÈ£´Â Ç×»ó º¯È­¸ðµå´Ù.±×¸®°í ·¹Äڵ尡 »èÁ¦,Ãß°¡µÉ¶§ µ¥ÀÌŸº£À̽º¿¡ ÀÖ´Â ´Ù¸¥ ·¹ÄÚµåÀÇ ¹øÈ£µµ º¯ÇÏ°Ô µÈ´Ù.)

Configuring Btree databases to support record numbers can severely limit the throughput of applications with multiple concurrent threads writing the database, because locations used to store record counts often become hot spots that many different threads all need to update. In the case of a Btree supporting duplicate data items, the logical record number refers to a key and all of its data items, as duplicate data items are not individually numbered.

(Btree°¡ ·¹ÄÚµå³Ñ¹ö¸¦ Áö¿øÇϵµ·Ï ¼³Á¤Çϴ°ÍÀº ¾²·¹µå¸¦ »ç¿ëÇÏ´Â ¾ÖÇø®ÄÉÀ̼ÇÀÇ Ã³¸®·®À» °¨¼Ò½ÃŲ´Ù.¿Ö³ÄÇÏ¸é ·¹ÄÚµåÄ«¿îÆ®¸¦ ÀúÀåÇϱâ À§ÇØ »ç¿ëµÇ´Â ÀúÀåÀ§Ä¡°¡ ¿©·¯ ¾²·¹µå¿¡ ÀÇÇØ ¾÷µ¥ÀÌÆ®µÇ¾ß Çϱ⶧¹®ÀÌ´Ù.µ¥ÀÌŸ¾ÆÀÌÅÛÀÇ º¹»ç¸¦ Áö¿øÇÏ´Â BtreeÀÇ °æ¿ì ³í¸®ÀûÀÎ ·¹ÄÚµå¹øÈ£´Â ÇϳªÀÇ Å°¿Í ÀÌ Å°ÀÇ ¸ðµç µ¥ÀÌŸ¾ÆÀÌÅÛÀ» ÂüÁ¶ÇÏ°í º¹»çµÈ µ¥ÀÌŸ¾ÆÀÌÅÛÀº °³º°ÀûÀ¸·Î ¹øÈ£°¡ ¸Å°ÜÁöÁö ¾Ê´Â´Ù.)

¡¡

The following is an example function that reads records from standard input and stores them into a Recno database. The function then uses a cursor to step through the database and display the stored records.

(´ÙÀ½ÀÇ ¿¹Á¦´Â Ç¥ÁØÀÔ·ÂÀ¸·ÎºÎÅÍ ·¹Äڵ带 Àаí Recno¿¡ ·¹Äڵ带 ÀúÀåÇÑ´Ù.¶ÇÇÑ Ä¿¼­¸¦ »ç¿ëÇÏ¿© µ¥ÀÌŸº£À̽º¸¦ À̵¿ÇÏ°í ÀúÀåµÈ ·¹Äڵ带 µð½ºÇ÷¹ÀÌÇÑ´Ù.)

int
recno_build(dbp)
	DB *dbp;
{
	DBC *dbcp;
	DBT key, data;
	db_recno_t recno;
	u_int32_t len;
	int ret;
	char buf[1024];

/* Insert records into the database. */ memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); for (recno = 1;; ++recno) { printf("record #%lu> ", (u_long)recno); fflush(stdout); if (fgets(buf, sizeof(buf), stdin) == NULL) break; if ((len = strlen(buf)) <= 1) continue;

key.data = &recno; key.size = sizeof(recno); data.data = buf; data.size = len - 1;

switch (ret = dbp->put(dbp, NULL, &key, &data, 0)) { case 0: break; default: dbp->err(dbp, ret, "DB->put"); break; } } printf("\n");

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

/* Re-initialize the key/data pair. */ memset(&key, 0, sizeof(key)); memset(&data, 0, sizeof(data));

/* Walk through the database and print out the key/data pairs. */ while ((ret = dbcp->c_get(dbcp, &key, &data, DB_NEXT)) == 0) printf("%lu : %.*s\n", *(u_long *)key.data, (int)data.size, (char *)data.data); if (ret != DB_NOTFOUND) dbp->err(dbp, ret, "DBcursor->get");

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


PrevRefNext

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