⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ug_ch4b.htm

📁 db.* (pronounced dee-be star) is an advanced, high performance, small footprint embedded database fo
💻 HTM
📖 第 1 页 / 共 3 页
字号:
   Type: data   Size of record slots : 90   Record slots per page: 5   Unused page space    : 58FILE: chkg.k01   Id  : 1   Type: key   Size of record slots : 16   Record slots per page: 63   Unused page space    : 6FILE: chkg.k02   Id  : 2   Type: key   Size of record slots : 14   Record slots per page: 145   Unused page space    : 8RECORD: BUDGET   Id  : 0   File: chkg.dat [0]   Total set pointers   : 1   Total member pointers: 0   Offset to data       : 26   Size of record       : 90   Unused slot space    : 0RECORD: CHECK   Id  : 1   File: chkg.dat [0]   Total set pointers   : 0   Total member pointers: 1   Offset to data       : 18   Size of record       : 78   Unused slot space    : 12</font></pre><p><font size="2">The summary for each data and key file includesthe following:</font></p><ul><li>File name</li><li>File id number</li><li>File type: data or key</li><li>Size of each record or key slot in bytes</li><li>Total number of slots per page</li><li>Total amount of unused page space</li></ul><p>The information most significant to database design is thenumber of slots per page and the amount of unused page space in adata file. The unused page space occurs because the slot sizemultiplied by the number of slots per page does not always exactlyequal the size of the database page. Much of this unused space canbe reserved by adding an extra (unused) data field to the largestrecord on the file. The length of the field is computed asfollows:</p><div style="margin-left: 4em"><p>length = (unused page space) / (slots per page)</p></div><p>The unused space is contained in a record so that if additionaldata needs to be stored in that record, space will be available. Ifthe reserved space is large enough, the new field can be addedwithout restructuring the database.</p><p>The record summary contains the following information.</p><ul><li>Record name</li><li>Record number</li><li>File in which record is contained</li><li>Total number of set pointers (sets owned by record)</li><li>Total number of member pointers (sets in which record ismember)</li><li>Offset to start of data from start of record</li><li>Total size of record in bytes</li><li>Amount of unused slot space</li></ul><p>The design-related information in this report is the unused slotspace. This space can easily be converted into a usable form byadding an extra field the length of the unused slot space to therecord. Then, as explained above, the space is available foradditional data to be stored in the record at a later date, withoutrequiring a restructure of the database.</p><p>Also important in calculating the size of the records is theordering and size of the data types used in the record. Mostsystems require numeric data to start on word boundaries. Thismeans that if the field preceding a numeric field does not end on aword boundary, unseen and unusable padding is inserted to force thenumeric data to the word boundary. When character and numeric dataare not carefully mixed, wasted space can be generated.</p><h4><a name="Sizes" id="Sizes"></a>File Page Sizes</h4><p><font size="2">To optimize file access performance, the pagesizes for data and key files should be a multiple of the file blocksize used by your operating system. Many systems have a block sizeof 512 bytes. In these systems block sizes of 512, 1024, 1536, etc.would be acceptable.</font></p><p>The best page size for a given file is not always easilydetermined, and will be based on application implementationdetails. Key file pages should be large enough to hold a reasonablenumber of keys, so that the number of levels in the resultingB-tree are kept as small as possible (less than or equal to four).Data file page sizes should be based on the number of records youwant to store on each page. For example, if all members of a setare stored together, then they will likely be stored in contiguousrecord slots. If they will usually be accessed together as well,then you may decide that the page size should be large enough tohold the average number of set members in order to minimize theactual disk accesses necessary to read each member.</p><p>The initial <b><i>db.*</i></b> runtime page buffers are sizedbased upon the largest page size specified in the DDL. For example,if you have specified four files with a 1024-byte page size and onefile with a 4096-byte page size, <b><i>db.*</i></b> will allocate4096 bytes for each page in the cache. You need to be aware of yourmemory requirements in deciding on page sizes.</p><h2><a name="DesignExample" id="DesignExample"></a>4.5 DatabaseDesign Example</h2><h3><a name="DesignIntroduction" id="DesignIntroduction"></a>4.5.1Introduction</h3><p><font size="2">The example to be presented in this section is anelaboration of the <b>tims</b> database introduced in Chapter 3. Itwill be used in examples throughout the remainder of this document.A solid understanding of this example design isnecessary.</font></p><p>The requirements for the <b>tims</b> application are givenfirst, followed by a description of the schema with explanations ofhow the design will be used to satisfy the stated requirements.</p><h3><a name="Requirements" id="Requirements"></a>4.5.2Requirements</h3><p><font size="2">The system is to be used to maintain a databaseof technical information contained in books, technical journals ormagazines, and articles. In the following discussion, a singlebook, journal issue, or article will be generally referred to as aninfo item.</font></p><p>The following data is to be stored for each book, journal, orarticle:</p><div style="margin-left: 4em"><p>author's name</p><p>information id code</p><p>title</p><p>publisher</p><p>date published</p><p>abstract</p><p>topical key words</p></div><p>The id code will be a unique Dewey-Decimal library code assignedby the user. The abstract will be a brief description (up toseveral paragraphs) of the info item. Each info item may haveseveral key words associated with it that identify topics discussedin it.</p><p>Functions are to be provided to allow info item entry anddeletion.</p><p>The info item data is to be retrieved as follows:</p><ul><li>By author name, where all info items for a given author arereported</li><li>By id code, through which individual occurrences can be foundor all occurrences can be retrieved in id code order</li><li>By key word, where all info items for a given key word arereported</li></ul><p>The ability to keep track of loaned books and magazines is alsoto be provided, where the borrower's name, the date borrowed, andthe date returned are stored for each item loaned. A loan historyis to be maintained for each info item. In addition, the ability toreport all unreturned info items is to be provided.</p><h3><a name="DatabaseDesign" id="DatabaseDesign"></a>4.5.3 DatabaseDesign</h3><p><font size="2">The schema diagram for the database design isshown in Figure 4-5 below.</font></p><p align="center">&nbsp;</p><p align="center"><img alt="dbstar_4-5.gif - 5346 Bytes" border="0"height="366" src="dbstar_4-5.gif" width="396"></p><p align="center">Fig. 4-5. tims Database Schema</p><p>The principal data for each info item is stored in a recordcalled <b>info</b>. This includes the id code, title, publisher,and publication date. Also included is a coded-value field forstoring the type of info, where 0 = book, 1 = journal or magazineand 2 = article. The id code will be a key in order to quickly findspecific <b>info</b> occurrences.</p><p>Because there may be many books or articles written by a singleauthor, storing the author name in the <b>info</b> record wouldreplicate multiple occurrences of the same author. This is oftenreferred to as redundant data. So, the author is stored in aseparate record with a set, <b>has_published</b>, connecting anauthor to that author's <b>info</b> records.</p><p>Since the <b>info</b> records for a given author are to beretrievable by author name, a set, ordered by author name, called<b>author_list,</b> has been defined with the system record as theowner. To find a specified author, this set is searched. This issufficient for a small personal library where there would berelatively few authors (less than 100) and the system is only usedby a single user. In a large library with many authors, accesswould be faster if we used the author name as a key field and didnot use a set. Here (mainly for instructional purposes), theassumption is that the system is for a small, personal library.</p><p>A simple variable-length text structure is used for storing theabstract. A record type called <b>text</b> is defined that stores atext string of up to 80 characters, including a sentinel null byte.A set called <b>abstract</b> with order <b>last</b> is defined with<b>info</b> as owner and <b>text</b> as member, forming aone-to-many set between an <b>info</b> record and each line ofabstract text.</p><p>The relationship between key words and item <b>info</b> recordsis many-to-many. A key word is stored in a record type named<b>key_word</b>. The key word is a string field that is keyed toallow rapid retrieval of individual key word occurrences and toallow alphabetized key word perusal. The many-to-many relationshipis implemented through the use of two sets, as described in section4.4.1, "Logical Design Considerations." <b>Key_word</b> records and<b>info</b> records are connected to an intersection record called<b>intersect</b>. Set <b>key_to_info</b> is used to find the<b>info</b> records corresponding to a particular key word. Set<b>info_to_key</b> is used to find the key words associated with agiven <b>info</b> record. The <b>intersect</b> record has one fieldto hold a copy of the <b>info</b> type from its <b>info</b> ownerthrough the <b>info_to_key</b> set. By eliminating an extra diskread of the <b>info</b> record for non-books, this facilitates thekind of key word searches where, for example, you're onlyinterested in finding the books covering a specific topic.Redundant data is sometimes incorporated into a database design inorder to improve data access performance.</p><p>A record type named <b>borrower</b> will contain the name of theborrower, the date loaned, and the date returned. The borrower'sname will be a key field, in order to be able to quickly find allof the items borrowed by a particular person. Dates will be storedas a long integer of the form YYMMDD (for example, 870709 is July9, 1987). A date of zero indicates that the loaned item has not yetbeen returned. When an item is loaned, a new borrower record iscreated and is connected to two sets. A set called<b>loaned_books</b> connects the <b>borrower</b> record to the<b>info</b> record for the loaned item. These records will normallyremain members of this set even after the item is returned, tomaintain a loan history for each item in the library. The<b>borrower</b> record is also connected to a set called<b>loan_history</b>, which is owned by the system record. This setis scanned when a list of all unreturned books is desired. Bothsets are in <b>last</b> order so the records will be connected inchronological order (without having to specify ascending order bydate loaned).</p><p>One final set has been included. The set named <b>articles</b>has <b>info</b> records participating as both owner and member ofthe same set (which is legal in <b><i>db.*</i></b>). Here, the setis intended to connect article <b>info</b> records to the<b>info</b> record of the journal or magazine in which it ispublished.</p><p>The <b><i>db.*</i></b> DDL that implements the <b>tims</b>database design is presented on the next page. Two data files andtwo key files have been defined. Data file <b>tims.d01</b> containsthe <b>system</b> record (of which there is only one occurrence andis small because it has no fields), <b>key_word</b> records and<b>intersect</b> records. Data file <b>tims.d02</b> contains theoccurrences of record types <b>author</b>, <b>borrower</b>,<b>info</b>, and <b>text</b>. This organization is arbitrary inthis case since the database is not large.</p><p>Key field <b>id_code</b> is much smaller than keys <b>friend</b>and <b>word</b> and is therefore stored in a separate key file, asis shown in the example below.</p><pre><font color="#0000FF">/*--------------------------------------------------------------------Technical Information Management System (TIMS) Database--------------------------------------------------------------------*/database tims{   data file "tims.d01" contains system, key_word, intersect;   data file "tims.d02" contains author, borrower, info, text;   key  file "tims.k01" contains id_code;   key  file "tims.k02" contains friend, word;      record author {      char name[32];               /* author's name: "last, first" */   }                               /* or editor's name */   record info {      unique key char id_code[16]; /* dewey dec. code */      char info_title[80];         /* title of book, article, mag. */      char publisher[32];          /* name of publisher */      char pub_date[12];           /* date of publication */      short info_type;             /* 0=book, 1=mag, 2=art */   }   record borrower {      key char friend[32];         /* name of borrower */      long date_borrowed;          /* dates are stored initially */      long date_returned;          /* numeric YYMMDD */   }   record text {      char line[80];               /* line of abstract text */   }   record key_word {      unique key char word[32];    /* subject key words */   }   record intersect {      short int_type;              /* copy of info_type */   }   set author_list {      order ascending;      owner system;      member author by name;   }   set has_published {      order ascending;      owner author;      member info by info_title;   }   set articles {      order last;      owner info;      member info;   }   set loaned_books {      order last;      owner info;      member borrower;   }   set abstract {      order last;      owner info;      member text;   }   set key_to_info {      order last;      owner key_word;      member intersect;   }   set info_to_key {      order last;      owner info;      member intersect;   }   set loan_history {      order last;      owner system;      member borrower;   }}</font></pre><p><a href="UG_Ch5a.htm">Next Page</a></p></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -