Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Silberschatz, Korth and Sudarshan11.1Database System Concepts Chapter 11: Storage and File Structure File Organization Organization of Records in Files.

Similar presentations


Presentation on theme: "©Silberschatz, Korth and Sudarshan11.1Database System Concepts Chapter 11: Storage and File Structure File Organization Organization of Records in Files."— Presentation transcript:

1 ©Silberschatz, Korth and Sudarshan11.1Database System Concepts Chapter 11: Storage and File Structure File Organization Organization of Records in Files Data-Dictionary Storage

2 ©Silberschatz, Korth and Sudarshan11.2Database System Concepts File Organization A database file is partitioned into fixed-length storage units called blocks. Blocks are units of both storage allocation and data transfer. The database is stored as a collection of files. Each file is a sequence of records. A record is a sequence of fields. One approach:  assume record size is fixed  each file has records of one particular type only  different files are used for different relations This case is easiest to implement; will consider variable length records later.

3 ©Silberschatz, Korth and Sudarshan11.3Database System Concepts File Organization Fixed-length records type account = record branch-name : char (22); account-number : char (10); balance : real; end Variable-length records type account-list = record branch-name : char (22); account-info : array [1..  ] of record; account-number : char (10); balance : real; end end

4 ©Silberschatz, Korth and Sudarshan11.4Database System Concepts Fixed-Length Records Simple approach:  Store record i starting from byte n  (i – 1), where n is the size of each record.  Record access is simple but records may cross blocks  Modification: do not allow records to cross block boundaries Deletion of record i: alternatives:  move records i + 1,..., n to i,..., n – 1 (Figure 11.7)  move record n to i (Figure 11.8)  do not move records, but link all free records on a free list

5 ©Silberschatz, Korth and Sudarshan11.5Database System Concepts Free Lists Store the address of the first deleted record in the file header. Use this first record to store the address of the second deleted record, and so on Can think of these stored addresses as pointers since they “point” to the location of a record. More space efficient representation: reuse space for normal attributes of free records to store pointers. (No pointers stored in in-use records.)

6 ©Silberschatz, Korth and Sudarshan11.6Database System Concepts Variable-Length Records Variable-length records arise in database systems in several ways:  Storage of multiple record types in a file.  Record types that allow variable lengths for one or more fields.  Record types that allow repeating fields (used in some older data models). Byte string representation  Attach an end-of-record (  ) control character to the end of each record (Figure 11.10)  Difficulty with deletion  Difficulty with growth

7 ©Silberschatz, Korth and Sudarshan11.7Database System Concepts Variable-Length Records: Slotted Page Structure Slotted page header contains:  number of record entries  end of free space in the block  location and size of each record The actual records are allocated contiguously in the block, starting from the end of the block. If a record is inserted, space is allocated for it at the end of free space, and an entry containing its size and location is added to the header. If a record is deleted, the records in the block before the deleted record are moved.

8 ©Silberschatz, Korth and Sudarshan11.8Database System Concepts Variable-Length Records (Cont.) Fixed-length representation:  reserved space (may waste a lot of space)  List (Pointer) Reserved space – can use fixed-length records of a known maximum length; unused space in shorter records filled with a null or end-of-record symbol. (Ex: we allow a maximum of three accounts per branch)

9 ©Silberschatz, Korth and Sudarshan11.9Database System Concepts Linked list Method List representation  A variable-length record is represented by a list of fixed-length records, chained together via pointers.  Can be used even if the maximum record length is not known

10 ©Silberschatz, Korth and Sudarshan11.10Database System Concepts Linked list Method (Cont.) Disadvantage to linked list structure: space is wasted in all records except the first in a chain. Solution is to allow two kinds of block in file:  Anchor block – contains the first records of chain  Overflow block – contains records other than those that are the first records of chains.

11 ©Silberschatz, Korth and Sudarshan11.11Database System Concepts Organization of Records in Files Heap file organization – a record can be placed anywhere in the file where there is space Sequential file organization – store records in sequential order, based on the value of the search key of each record Hashing file organization – a hash function computed on some attribute of each record; the result specifies in which block of the file the record should be placed Records of each relation may be stored in a separate file. In a clustering file organization records of several different relations can be stored in the same file  Motivation: store related records on the same block to minimize I/O

12 ©Silberschatz, Korth and Sudarshan11.12Database System Concepts Sequential File Organization Suitable for applications that require sequential processing of the entire file The records in the file are ordered by a search-key (Ex: branch name is the search key)

13 ©Silberschatz, Korth and Sudarshan11.13Database System Concepts Sequential File Organization (Cont.) Deletion – use pointer chains (as we saw previously) Insertion –locate the position where the record is to be inserted  if there is free space insert there  if no free space, insert the record in an overflow block  In either case, pointer chain must be updated Need to reorganize the file from time to time to restore sequential order (depend on the frequency of insertion of new records)

14 ©Silberschatz, Korth and Sudarshan11.14Database System Concepts Clustering File Organization Simple file structure stores each relation in a separate file Can instead store several relations in one file using a clustering file organization E.g., clustering organization of customer and depositor:  good for queries involving depositor customer, and for queries involving one single customer and his accounts  bad for queries involving only customer (Figure 11.20)  results in variable size records depositor (Figure 11.17) customer (Figure 11.18)

15 ©Silberschatz, Korth and Sudarshan11.15Database System Concepts Data Dictionary Storage Information about relations  names of relations  names and types of attributes of each relation  names and definitions of views  integrity constraints User and accounting information, passwords about users Statistical and descriptive data  number of tuples in each relation Physical file organization information  How relation is stored (sequential/clustering/hash/…)  Physical location of relation  operating system file name or  disk addresses of blocks containing records of the relation Information about indices (Chapter 12) Data dictionary (also called system catalog) stores metadata: that is, data about data, such as

16 ©Silberschatz, Korth and Sudarshan11.16Database System Concepts Data Dictionary Storage (Cont.) A possible catalog representation: Relation-metadata = (relation-name, number-of-attributes, storage-organization, location) Attribute-metadata = (attribute-name, relation-name, domain-type, position, length) User-metadata = (user-name, encrypted-password, group) Index-metadata = (index-name, relation-name, index-type, index-attributes) View-metadata = (view-name, definition)


Download ppt "©Silberschatz, Korth and Sudarshan11.1Database System Concepts Chapter 11: Storage and File Structure File Organization Organization of Records in Files."

Similar presentations


Ads by Google