chapter 12 representing data elements by yue lu cs257 spring 2008 instructor: dr.lin

20
Chapter 12 Chapter 12 Representing Data Representing Data Elements Elements By Yue Lu By Yue Lu CS257 Spring 2008 CS257 Spring 2008 Instructor: Dr.Lin Instructor: Dr.Lin

Post on 21-Dec-2015

219 views

Category:

Documents


4 download

TRANSCRIPT

Chapter 12 Chapter 12 Representing Data ElementsRepresenting Data Elements

By Yue LuBy Yue LuCS257 Spring 2008CS257 Spring 2008Instructor: Dr.LinInstructor: Dr.Lin

ContentsContents Data Elements and FieldsData Elements and Fields

– Representing Relational Database Representing Relational Database ElementsElements

– Representing ObjectsRepresenting Objects– Representing Data ElementsRepresenting Data Elements

RecordsRecords– Building Fixed-Length RecordsBuilding Fixed-Length Records– Record HeadersRecord Headers– Packing Fixed-Length Records into Packing Fixed-Length Records into

BlocksBlocks

ContentsContents Data Elements and FieldsData Elements and Fields

– Representing Relational Database Representing Relational Database ElementsElements

– Representing ObjectsRepresenting Objects– Representing Data ElementsRepresenting Data Elements

RecordsRecords– Building Fixed-Length RecordsBuilding Fixed-Length Records– Record HeadersRecord Headers– Packing Fixed-Length Records into Packing Fixed-Length Records into

BlocksBlocks

Data Elements and FieldsData Elements and Fields

Representing Relational Database Representing Relational Database ElementsElements– Consider the MovieStar relation below Consider the MovieStar relation below

declared in SQLdeclared in SQL CREATE TABLE MovieStar (CREATE TABLE MovieStar (

name CHAR(30) PRIMARY KEY,name CHAR(30) PRIMARY KEY,

address VARCHAR(255),address VARCHAR(255),

gender CHAR(1),gender CHAR(1),

birthdate DATEbirthdate DATE

););

– DBMS has to represent and store the relationDBMS has to represent and store the relation

Data Elements and FieldsData Elements and Fields

Issues in representing relational DB Issues in representing relational DB elementselements– How to represent SQL datatypes as fieldsHow to represent SQL datatypes as fields– How to represent tuples as recordsHow to represent tuples as records– How to represent collections or records in How to represent collections or records in

blocks of memoryblocks of memory– How to represent and store relations as How to represent and store relations as

collections of blockscollections of blocks– How to cope with record sizesHow to cope with record sizes– What if the size of a record changes due to What if the size of a record changes due to

updatingupdating

ContentsContents Data Elements and FieldsData Elements and Fields

– Representing Relational Database Representing Relational Database ElementsElements

– Representing ObjectsRepresenting Objects– Representing Data ElementsRepresenting Data Elements

RecordsRecords– Building Fixed-Length RecordsBuilding Fixed-Length Records– Record HeadersRecord Headers– Packing Fixed-Length Records into Packing Fixed-Length Records into

BlocksBlocks

Data Elements and FieldsData Elements and Fields

Representing ObjectsRepresenting Objects– Objects can have Objects can have methodsmethods or or

special-purpose functions associated special-purpose functions associated with themwith them

– Objects may have an Objects may have an object object identifieridentifier(OID), which is an address (OID), which is an address that refers uniquely to that objectthat refers uniquely to that object

ContentsContents Data Elements and FieldsData Elements and Fields

– Representing Relational Database Representing Relational Database ElementsElements

– Representing ObjectsRepresenting Objects– Representing Data ElementsRepresenting Data Elements

RecordsRecords– Building Fixed-Length RecordsBuilding Fixed-Length Records– Record HeadersRecord Headers– Packing Fixed-Length Records into Packing Fixed-Length Records into

BlocksBlocks

Data Elements and FieldsData Elements and Fields

Data Elements and FieldsData Elements and Fields

Representing Data ElementsRepresenting Data Elements– Fixed-Length Character StringsFixed-Length Character Strings

CHAR(n): n bytesCHAR(n): n bytes– Pad characters are used if the actual Pad characters are used if the actual

value is shorter than nvalue is shorter than n– Variable-Length Character StringsVariable-Length Character Strings

VARCHAR(n): n+1 bytesVARCHAR(n): n+1 bytes– Length plus content: Length plus content: # of bytes in # of bytes in

the string + characters of the stringthe string + characters of the string– Null-terminated string: Null-terminated string: characters of characters of

the string + “null” characterthe string + “null” character

Data Elements and FieldsData Elements and Fields

Representing Data Elements (con.)Representing Data Elements (con.)– Dates and TimesDates and Times

Date: 10 bytes (YYYY-MM-DD)Date: 10 bytes (YYYY-MM-DD) Time: 8 bytes (HH:MM:SS)Time: 8 bytes (HH:MM:SS)

– May need more bytes to include May need more bytes to include fraction of a secondfraction of a second

– BitsBits– Enumerated TypesEnumerated Types

ContentsContents Data Elements and FieldsData Elements and Fields

– Representing Relational Database Representing Relational Database ElementsElements

– Representing ObjectsRepresenting Objects– Representing Data ElementsRepresenting Data Elements

RecordsRecords– Building Fixed-Length RecordsBuilding Fixed-Length Records– Record HeadersRecord Headers– Packing Fixed-Length Records into Packing Fixed-Length Records into

BlocksBlocks

RecordsRecords

Building Fixed-Length RecordsBuilding Fixed-Length Records– All the fields of the record have a All the fields of the record have a

fixed lengthfixed length– E.g. A MovieStar recordE.g. A MovieStar record

RecordsRecords

Building Fixed-Length RecordsBuilding Fixed-Length Records– Sometimes, it is more efficient to Sometimes, it is more efficient to

align fields starting at a multiple of 4align fields starting at a multiple of 4

ContentsContents Data Elements and FieldsData Elements and Fields

– Representing Relational Database Representing Relational Database ElementsElements

– Representing ObjectsRepresenting Objects– Representing Data ElementsRepresenting Data Elements

RecordsRecords– Building Fixed-Length RecordsBuilding Fixed-Length Records– Record HeadersRecord Headers– Packing Fixed-Length Records into Packing Fixed-Length Records into

BlocksBlocks

RecordsRecords

Record HeadersRecord Headers– Pointer to the record schemaPointer to the record schema– Length of the recordLength of the record– TimestampTimestamp

ContentsContents Data Elements and FieldsData Elements and Fields

– Representing Relational Database Representing Relational Database ElementsElements

– Representing ObjectsRepresenting Objects– Representing Data ElementsRepresenting Data Elements

RecordsRecords– Building Fixed-Length RecordsBuilding Fixed-Length Records– Record HeadersRecord Headers– Packing Fixed-Length Records into Packing Fixed-Length Records into

BlocksBlocks

RecordsRecords

Packing Fixed-Length Records Packing Fixed-Length Records into Blocksinto Blocks

RecordsRecords

HeaderHeader– Links to other blocksLinks to other blocks– Information about the role played by this Information about the role played by this

block in such a networkblock in such a network– Information about which relation the Information about which relation the

tuples of this block belong totuples of this block belong to– Directory giving the offset of each record Directory giving the offset of each record

in the blockin the block– Block IDBlock ID– TimestampTimestamp

ReferencesReferences

Database Systems The Complete Book by Hector Database Systems The Complete Book by Hector Garcia-Molina, Jeffrey D.Ullman and Jennifer Widom Garcia-Molina, Jeffrey D.Ullman and Jennifer Widom Fundamentals ofFundamentals of

Principles of Database Systems with Internet and Java Principles of Database Systems with Internet and Java Applications by Greg RiccardiApplications by Greg Riccardi

Database Systems by Elmasri NavatheDatabase Systems by Elmasri Navathe http://dbserver.kaist.ac.kr/~mhkim/cs560-http://dbserver.kaist.ac.kr/~mhkim/cs560-

07spring.dir/chap3.pdf07spring.dir/chap3.pdf