Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf ·...

44
Chapter Chapter 6: Physical Database Design and Physical Database Design and Performance Performance Performance Performance Modern Database Management Modern Database Management 9 th th Edition Edition 9 Edition Edition Jeffrey A. Jeffrey A. Hoffer Hoffer, Mary B. Prescott, , Mary B. Prescott, Heikki Heikki Topi Topi Heikki Heikki Topi Topi © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice Hall Publishing as Prentice Hall 1

Transcript of Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf ·...

Page 1: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Chapter Chapter 66::Physical Database Design and Physical Database Design and

PerformancePerformancePerformancePerformance

Modern Database ManagementModern Database Management99thth EditionEdition99 EditionEdition

Jeffrey A. Jeffrey A. HofferHoffer, Mary B. Prescott, , Mary B. Prescott, HeikkiHeikki TopiTopiHeikkiHeikki TopiTopi

© © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 11

Page 2: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

ObjectivesObjectivesObjectivesObjectivesD fi iti f tD fi iti f tDefinition of termsDefinition of termsDescribe the physical database design processDescribe the physical database design processChoose storage formats for attributesChoose storage formats for attributesSelect appropriate file organizationsSelect appropriate file organizationspp p gpp p gDescribe three types of file organizationDescribe three types of file organizationDescribe indexes and their appropriate useDescribe indexes and their appropriate useDescribe indexes and their appropriate useDescribe indexes and their appropriate useTranslate a database model into efficient Translate a database model into efficient structuresstructuresstructuresstructuresKnow when and how to use denormalizationKnow when and how to use denormalization

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 22

Page 3: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Physical Database DesignPhysical Database Design

PurposePurpose––translate the logical description translate the logical description of data into the of data into the technical specificationstechnical specifications for for storing and retrieving datastoring and retrieving datag gg gGoalGoal––create a design for storing data that create a design for storing data that will providewill provide adequate performanceadequate performance andandwill provide will provide adequate performanceadequate performance and and insure insure database integritydatabase integrity, , securitysecurity, and , and recoverabilityrecoverability

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 33

Page 4: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Physical Design ProcessPhysical Design ProcessPhysical Design ProcessPhysical Design ProcessInputs

Normalized relations

Inputs

Attribute data types

Decisions

Volume estimates

Attribute definitions

Attribute data types

Physical record descriptions (doesn’t always match

Response time expectations

Data security needs

( ylogical design)

File organizationsLeads to

Backup/recovery needs

Integrity expectations

Indexes and database architecturesg y p

DBMS technology used Query optimization

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 44

Page 5: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-1 Composite usage map(Pine Valley Furniture Company)(Pine Valley Furniture Company)

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 55

Page 6: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-1 Composite usage map(Pine Valley Furniture Company) (cont )(Pine Valley Furniture Company) (cont.)

Data volumes

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 66

Page 7: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-1 Composite usage map(Pine Valley Furniture Company) (cont )(Pine Valley Furniture Company) (cont.)

Access Frequencies (per hour)(per hour)

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 77

Page 8: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-1 Composite usage map(Pine Valley Furniture Company) (cont )(Pine Valley Furniture Company) (cont.)

Usage analysis:140 purchased parts accessed per hour80 quotations accessed from these 140 purchased part accesses 70 suppliers accessed from these 80 quotation accessesthese 80 quotation accesses

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 88

Page 9: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-1 Composite usage map(Pine Valley Furniture Company) (cont )(Pine Valley Furniture Company) (cont.)

Usage analysis:75 suppliers accessed per75 suppliers accessed per hour40 quotations accessed from these 75 supplier accessesthese 75 supplier accesses 40 purchased parts accessed from these 40 quotation accesses

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 99

Page 10: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Designing FieldsDesigning Fields

Field: smallest unit of data in Field: smallest unit of data in databasedatabaseField design Field design

Choo ing d t t peChoo ing d t t peChoosing data typeChoosing data typeCoding, compression, encryptionCoding, compression, encryptionCoding, compression, encryptionCoding, compression, encryptionControlling data integrityControlling data integrity

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1010

Page 11: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Choosing Data TypesChoosing Data Types

CHARCHAR––fixedfixed--length characterlength characterVARCHARVARCHAR22––variablevariable--length character (memo)length character (memo)LONGLONG––large numberlarge numberggNUMBERNUMBER––positive/negative numberpositive/negative numberINEGERINEGER positive/negative whole numberpositive/negative whole numberINEGERINEGER––positive/negative whole numberpositive/negative whole numberDATEDATE––actual dateactual dateBLOBBLOB––binary large object (good for graphics, binary large object (good for graphics, sound clips, etc.)sound clips, etc.)

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1111

Page 12: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-2 Example code look-up tableg(Pine Valley Furniture Company)

Code saves space, but costs an additional lookup toan additional lookup to obtain actual value

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1212

Page 13: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Field Data IntegrityField Data IntegrityDefault valueDefault value assumed value if no explicitassumed value if no explicitDefault valueDefault value––assumed value if no explicit assumed value if no explicit valuevalueRange controlRange control allowable value limitationsallowable value limitationsRange controlRange control––allowable value limitations allowable value limitations (constraints or validation rules)(constraints or validation rules)Null value controlNull value control allowing or prohibitingallowing or prohibitingNull value controlNull value control––allowing or prohibiting allowing or prohibiting empty fieldsempty fieldsReferential integrityReferential integrity range control (and nullrange control (and nullReferential integrityReferential integrity––range control (and null range control (and null value allowances) for foreignvalue allowances) for foreign--key to primarykey to primary--key matchkey match--upsupskey matchkey match upsups

Sarbanes-Oxley Act (SOX) legislates importance of financial data integrity

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1313

y ( ) g p g y

Page 14: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Handling Missing DataHandling Missing Data

Substitute an estimate of the missing value Substitute an estimate of the missing value (e g using a formula)(e g using a formula)(e.g., using a formula)(e.g., using a formula)Construct a report listing missing valuesConstruct a report listing missing valuesI i i i d l hI i i i d l hIn programs, ignore missing data unless the In programs, ignore missing data unless the value is significant (sensitivity testing)value is significant (sensitivity testing)

Triggers can be used to perform these operations

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1414

Page 15: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Physical RecordsPhysical RecordsPhysical Record: A group of fields Physical Record: A group of fields stored in adjacent memory locationsstored in adjacent memory locationsstored in adjacent memory locations stored in adjacent memory locations and retrieved together as a unitand retrieved together as a unitP Th t f d t dP Th t f d t dPage: The amount of data read or Page: The amount of data read or written in one I/O operationwritten in one I/O operationBlocking Factor: The number of physical Blocking Factor: The number of physical records per pagerecords per pagerecords per pagerecords per page

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1515

Page 16: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

DenormalizationDenormalizationDenormalizationDenormalizationTransformingTransforming normalizednormalized relations intorelations into unnormalizedunnormalizedTransforming Transforming normalizednormalized relations into relations into unnormalizedunnormalizedphysical record specificationsphysical record specificationsBenefits:Benefits:

Can improve performance (speed) by reducing number of table Can improve performance (speed) by reducing number of table lookups (i.e. lookups (i.e. reduce number of necessary join queriesreduce number of necessary join queries))

Costs (due to data duplication)Costs (due to data duplication)Costs (due to data duplication)Costs (due to data duplication)Wasted storage spaceWasted storage spaceData integrity/consistency threatsData integrity/consistency threatsg y/ yg y/ y

Common denormalization opportunitiesCommon denormalization opportunitiesOneOne--toto--one relationship (Fig. one relationship (Fig. 66--33))

l h h b (l h h b ( ))ManyMany--toto--many relationship with attributes (Fig. many relationship with attributes (Fig. 66--44))Reference data (Reference data (11:N relationship where :N relationship where 11--side has data not used side has data not used in any other relationship) (Fig. in any other relationship) (Fig. 66--55))

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1616

Page 17: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-3 A possible denormalization situation: two entities with one-to one relationshipto-one relationship

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1717

Page 18: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-4 A possible denormalization situation: a many-to-many relationship with nonkey attributes

Extra table access required

N ll d i ti ibl

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1818

Null description possible

Page 19: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-5A possibleA possible denormalization situation:

f d treference data

Extra table access

i drequired

d li iData duplication

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 1919

Page 20: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

PartitioningPartitioningPartitioningPartitioningHorizontal Partitioning: Distributing the rows of a Horizontal Partitioning: Distributing the rows of a

bl i l filbl i l filtable into several separate filestable into several separate filesUseful for situations where different users need access to Useful for situations where different users need access to different rowsdifferent rowsThree types: Key Range Partitioning, Hash Partitioning, or Three types: Key Range Partitioning, Hash Partitioning, or Composite PartitioningComposite Partitioning

Vertical Partitioning: Distributing the columns of aVertical Partitioning: Distributing the columns of aVertical Partitioning: Distributing the columns of a Vertical Partitioning: Distributing the columns of a table into several separate relationstable into several separate relations

Useful for situations where different users need access to Useful for situations where different users need access to different columnsdifferent columnsThe primary key must be repeated in each fileThe primary key must be repeated in each file

Combinations of Horizontal and VerticalCombinations of Horizontal and VerticalCombinations of Horizontal and VerticalCombinations of Horizontal and Vertical

Partitions often correspond with User Schemas (user views)

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2020

p ( )

Page 21: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Partitioning (cont.)Partitioning (cont.)Advantages of Partitioning:Advantages of Partitioning:

Efficiency: Records used together are grouped togetherEfficiency: Records used together are grouped togetherLocal optimization: Each partition can be optimized for Local optimization: Each partition can be optimized for performanceperformanceSecurity, recoverySecurity, recoveryLoad balancing: Partitions stored on different disks, reduces Load balancing: Partitions stored on different disks, reduces contentioncontentionTake advantage of parallel processing capabilityTake advantage of parallel processing capability

Disadvantages of Partitioning:Disadvantages of Partitioning:Inconsistent access speed: Slow retrievals across partitionsInconsistent access speed: Slow retrievals across partitionsComplexity: NonComplexity: Non--transparent partitioningtransparent partitioningComplexity: NonComplexity: Non transparent partitioningtransparent partitioningExtra space or update time: Duplicate data; access from multiple Extra space or update time: Duplicate data; access from multiple partitionspartitions

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2121

Page 22: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

OracleOracle 1010i Horizontali HorizontalOracle Oracle 1010i Horizontal i Horizontal Partitioning MethodsPartitioning Methodsgg

Key range partitioningKey range partitioningPartitions defined by range of field valuesPartitions defined by range of field valuesy gy gCould result in unbalanced distribution of rowsCould result in unbalanced distribution of rowsLikeLike--valued fields share partitionsvalued fields share partitions

H h titi iH h titi iHash partitioningHash partitioningPartitions defined via hash functionsPartitions defined via hash functionsWill guarantee balanced distribution of rowsWill guarantee balanced distribution of rowsWill guarantee balanced distribution of rowsWill guarantee balanced distribution of rowsPartition could contain widely varying valued fieldsPartition could contain widely varying valued fields

Composite partitioningComposite partitioningComposite partitioningComposite partitioningCombines key range and hashCombines key range and hash

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2222

Page 23: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Data ReplicationData Replication

Purposely storing the same data in Purposely storing the same data in lti l l ti f th d t blti l l ti f th d t bmultiple locations of the databasemultiple locations of the database

Improves performance by allowing Improves performance by allowing p p y gp p y gmultiple users to access the same data at multiple users to access the same data at the same time with minimum contentionthe same time with minimum contentionSacrifices data integrity due to data Sacrifices data integrity due to data duplicationduplicationduplicationduplicationBest for data that is not updated oftenBest for data that is not updated often

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2323

Page 24: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Designing Physical FilesDesigning Physical FilesDesigning Physical FilesDesigning Physical FilesPhysical File:Physical File:Physical File: Physical File:

A named portion of secondary memory allocated A named portion of secondary memory allocated for the purpose of storing physical recordsfor the purpose of storing physical recordsfor the purpose of storing physical recordsfor the purpose of storing physical recordsTablespaceTablespace––named set of disk storage elements in named set of disk storage elements in which physical files for database tables can be which physical files for database tables can be storedstoredExtentExtent––contiguous section of disk spacecontiguous section of disk space

C li k i f dC li k i f dConstructs to link two pieces of data:Constructs to link two pieces of data:Sequential storageSequential storageP iP i fi ld f d h b d lfi ld f d h b d lPointersPointers––field of data that can be used to locate field of data that can be used to locate related fields or recordsrelated fields or records

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2424

Page 25: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-6 Physical file terminology in an Oracle environment

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2525

Page 26: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

File OrganizationsFile OrganizationsFile OrganizationsFile OrganizationsTechnique for physically arranging records of a Technique for physically arranging records of a fil d tfil d tfile on secondary storagefile on secondary storageFactors for selecting file organization:Factors for selecting file organization:

F t d t t i l d th h tF t d t t i l d th h tFast data retrieval and throughputFast data retrieval and throughputEfficient storage space utilizationEfficient storage space utilizationProtection from failure and data lossProtection from failure and data lossProtection from failure and data lossProtection from failure and data lossMinimizing need for reorganizationMinimizing need for reorganizationAccommodating growthAccommodating growthSecurity from unauthorized useSecurity from unauthorized use

Types of file organizationsTypes of file organizationsSequentialSequentialIndexedIndexedHashedHashed

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2626

HashedHashed

Page 27: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-7a Sequential file 1Sequential file organization

1

2

Records of the file are stored in

If sorted –every insert or file are stored in

sequence by the primary key

delete requires resort

If not sortedAverage time to

p y yfield values

Average time to find desired record = n/2

n

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2727

Page 28: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Indexed File OrganizationsIndexed File OrganizationsIndexed File OrganizationsIndexed File OrganizationsIndexIndex––a separate table that containsa separate table that containsIndexIndex a separate table that contains a separate table that contains organization of records for quick retrievalorganization of records for quick retrievalPrimary keys are automatically indexedPrimary keys are automatically indexedPrimary keys are automatically indexedPrimary keys are automatically indexedOracle has a CREATE INDEX operation, and Oracle has a CREATE INDEX operation, and MS ACCESS allows indexes to be created forMS ACCESS allows indexes to be created forMS ACCESS allows indexes to be created for MS ACCESS allows indexes to be created for most field typesmost field typesIndexing approaches:Indexing approaches:Indexing approaches:Indexing approaches:

BB--tree index, Fig. tree index, Fig. 66--77bbBitmap index, Fig. Bitmap index, Fig. 66--88p , gp , gHash Index, Fig. Hash Index, Fig. 66--77ccJoin Index, Fig Join Index, Fig 66--99

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2828

Page 29: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-7b B-tree index

Leaves of the tree are all at same level

consistent access time

uses a tree searchAverage time to find desired record = depth of the tree

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 2929

record = depth of the tree

Page 30: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-7cHashed file orHashed file or index organizationorganization

Hash algorithmUsually uses divisionUsually uses division-remainder to determine record position. Records with same position arewith same position are grouped in lists

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3030

Page 31: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-8Bitmap index

Bitmap saves on space requirementsRows - possible values of the attributeBitmap index

organization Rows - possible values of the attributeColumns - table rowsBit indicates whether the attribute of a row has the values

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3131

Page 32: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-9 Join Indexes–speeds up join operations

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3232

Page 33: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3333

Page 34: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Clustering FilesClustering Files

In some relational DBMSs, related records from In some relational DBMSs, related records from different tables can be stored together in thedifferent tables can be stored together in thedifferent tables can be stored together in the different tables can be stored together in the same disk areasame disk areaUseful for improving performance of joinUseful for improving performance of joinUseful for improving performance of join Useful for improving performance of join operationsoperationsPrimary key records of the main table are storedPrimary key records of the main table are storedPrimary key records of the main table are stored Primary key records of the main table are stored adjacent to associated foreign key records of the adjacent to associated foreign key records of the dependent tabledependent tabledependent tabledependent tablee.g. Oracle has a CREATE CLUSTER commande.g. Oracle has a CREATE CLUSTER command

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3434

Page 35: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Rules for Using IndexesRules for Using Indexes

1.1. Use on larger tablesUse on larger tables2.2. Index the primary key of each tableIndex the primary key of each table3.3. Index search fields (fields frequently inIndex search fields (fields frequently in3.3. Index search fields (fields frequently in Index search fields (fields frequently in

WHERE clause)WHERE clause)44 Fields in SQL ORDER BY and GROUP BYFields in SQL ORDER BY and GROUP BY4.4. Fields in SQL ORDER BY and GROUP BY Fields in SQL ORDER BY and GROUP BY

commandscommands55 Wh thWh th 100100 l b t tl b t t5.5. When there are >When there are >100 100 values but not values but not

when there are <when there are <30 30 valuesvalues

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3535

Page 36: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Rules for Using Indexes (cont )Rules for Using Indexes (cont )Rules for Using Indexes (cont.)Rules for Using Indexes (cont.)66 Avoid use of indexes for fields with longAvoid use of indexes for fields with long6.6. Avoid use of indexes for fields with long Avoid use of indexes for fields with long

values; perhaps compress values firstvalues; perhaps compress values first77 DBMS may have limit on number of indexesDBMS may have limit on number of indexes7.7. DBMS may have limit on number of indexes DBMS may have limit on number of indexes

per table and number of bytes per indexed per table and number of bytes per indexed field(s)field(s)d(s)d(s)

8.8. Null values will not be referenced from an Null values will not be referenced from an indexindex

9.9. Use indexes heavily for nonUse indexes heavily for non--volatile volatile databases; limit the use of indexes for databases; limit the use of indexes for ;;volatile databasesvolatile databases

Why? Because modifications (e.g. inserts, deletes) require Why? Because modifications (e.g. inserts, deletes) require d t t i i d fild t t i i d fil

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3636

updates to occur in index filesupdates to occur in index files

Page 37: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

RAIDRAID

Redundant Array of Inexpensive DisksRedundant Array of Inexpensive DisksA set of disk drives that appear to the user A set of disk drives that appear to the user to be a single disk driveto be a single disk driveto be a single disk driveto be a single disk driveAllows parallel access to data (improves Allows parallel access to data (improves

d)d)access speed)access speed)Pages are arranged inPages are arranged in stripesstripesPages are arranged in Pages are arranged in stripesstripes

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3737

Page 38: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Figure 6-10RAID withRAID with four disks and stripingp g

Here, pages 1-4Here, pages 1 4 can be read/written simultaneouslysimultaneously

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3838

Page 39: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Raid Types (Figure Raid Types (Figure 66--1010))yp ( gyp ( g ))Raid 0

Maximized parallelism

Raid 3Error correction in one diskMaximized parallelism

No redundancyNo error correctionno fault tolerance

Record spans multiple data disks (more than RAID2)Not good for multi-user no fault-tolerance

Raid 1Redundant data–fault tolerant

genvironments,

Raid 4Error correction in one disk

Most common form

Raid 2No redundancy

Error correction in one diskMultiple records per stripeParallelism, but slow updates due to error correction contentionNo redundancy

One record spans across data disksError correction in multiple

error correction contention

Raid 5Rotating parity array

Error correction in multiple disks–reconstruct damaged data

Error correction takes place in same disks as data storageParallelism, better performance than R id4

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 3939

Raid4

Page 40: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

res

re

s

ctur

ctur Legacy

Systemshi

tec

hite

c--1

111))

Arch

Arch

ure

ure

66-- CurrentTechnology

ase

Aas

e A

(Fig

u(F

igu

taba

taba

((

DataWarehouses

Dat

Dat Warehouses

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 4040

Page 41: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Query OptimizationQuery OptimizationParallel query processing Parallel query processing –– possible when possible when working in multiprocessor systemsworking in multiprocessor systemsOverriding automatic query optimization Overriding automatic query optimization –– allows allows for query writers to preempt the automated for query writers to preempt the automated optimizationoptimizationPicking data block size Picking data block size –– factors to consider factors to consider include:include:

Block contention, random and sequential row access Block contention, random and sequential row access d id ispeed, row sizespeed, row size

Balancing I/O across disk controllersBalancing I/O across disk controllers

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 4141

Page 42: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Query Design GuidelinesQuery Design GuidelinesUnderstand how indexes are usedUnderstand how indexes are usedKeep optimization statistics upKeep optimization statistics up--toto--datedateKeep optimization statistics upKeep optimization statistics up toto datedateUse compatible data types for fields and literalsUse compatible data types for fields and literalsWrite simple queriesWrite simple queriesWrite simple queriesWrite simple queriesBreak complex queries into multiple, simple Break complex queries into multiple, simple partspartspartspartsDon’t use one query inside anotherDon’t use one query inside anotherDon’t combine a table with itselfDon’t combine a table with itselfDon t combine a table with itselfDon t combine a table with itself

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 4242

Page 43: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

Query Design Guidelines (cont.)Query Design Guidelines (cont.)Create temporary tables for groups of queriesCreate temporary tables for groups of queriesCombine update operationsCombine update operationsCombine update operationsCombine update operationsRetrieve only the data you needRetrieve only the data you needDon’t have the DBMS sort without an indexDon’t have the DBMS sort without an indexDon t have the DBMS sort without an indexDon t have the DBMS sort without an indexLearn!Learn!Consider the total query processing time for adConsider the total query processing time for adConsider the total query processing time for ad Consider the total query processing time for ad hoc querieshoc queries

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 4343

Page 44: Chapter Chapter 66:: Physical Database Design and Performanceis.cba.edu.kw/433/Handouts/ch06.pdf · Chapter Chapter 66:: Physical Database Design and ... (Pine Valley Furniture Company)(Pine

All rights reserved. No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means electronicretrieval system, or transmitted, in any form or by any means, electronic,

mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher. Printed in the United States of America.

Copyright © Copyright © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall

Chapter 6 © © 2009 2009 Pearson Education, Inc. Pearson Education, Inc. Publishing as Prentice HallPublishing as Prentice Hall 4444