Chapter 12.2: Records Kristen Mori CS 257 – Spring /4/2008
Terminology Data ElementRecordCollection Filesfieldrecordfile Cfieldstructarray, file SQLattributetuplerelation OQL attribute, relationship objectclass
Record A record is a collection of fields, or attributes E.g. Employee record: name field, salary field, date-of-hire field,... Types of records: FIXED vs VARIABLE FORMAT FIXED vs VARIABLE LENGTH
Schema Each relation must have a schema Schema includes: field name data type of each field offset within the record The schema is necessary to access components of a record
Fixed-Length Records All fields have fixed-length Concatenate fields to form record E.g.: Declaration of MovieStar relation CREATE TABLE MovieStar( name CHAR(30), address VARCHAR(255), gender CHAR(1), birthdate DATE);
Increase Efficiency Some machines increase efficiency of reading and writing data, if the data begins at a byte whose address is a multiple of 4 Certain datatypes have strict requirements Integers begin at an address that is multiple of 4 Double-precision reals begin with a multiple of 8
Increase Efficiency Blocks read from disk to main memory (MM) are placed at an address that is a power of 2 If certain fields must have a MM address that is a multiple of 4 or 8, then the fields within the block must have an offset that has the same divisor
Offset Example The tuples of the MovieStar relation need to be represented so each field starts at a byte that is a multiple of 4 Each record consumes 304 bytes name 30 bytes address 256 bytes gender 1 byte birthdate 10 bytes
Record Headers Record headers store additional information about a record pointer to the schema length of the record timestamp indicating the time the record was last modified or last read name 30 bytes address 256 bytes gender 1 byte birthdate 10 bytes to schema length timestamp
Packing Fixed-Length Records into Blocks There is an optional block header that stores information such as: Links to other blocks Information about which relation the tuples belong to A “directory” giving the offset of each record A “block ID” Timestamp headerrecord 1record 2…record n
Block Example Suppose we have fixed-length records of 316 bytes and we use 4096-byte blocks Assume a 12 byte block header, therefore we have 4084 bytes for data In this space we can fit 12 records, each 316 bytes long (12 * 316 = 3792) 292 bytes of unused space