© 2005 by prentice hall 1 chapter 6: physical database design and performance modern database...
Post on 21-Dec-2015
224 views
TRANSCRIPT
© 2005 by Prentice Hall© 2005 by Prentice Hall 11
Chapter 6:Chapter 6:Physical Database Design Physical Database Design
and Performanceand Performance
Modern Database Modern Database ManagementManagement
77thth Edition EditionJeffrey A. Hoffer, Mary B. Prescott, Jeffrey A. Hoffer, Mary B. Prescott,
Fred R. McFaddenFred R. McFadden
22Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
ObjectivesObjectives Definition of termsDefinition of terms Describe the physical database design Describe the physical database design
processprocess Choose storage formats for attributesChoose storage formats for attributes Select appropriate file organizationsSelect appropriate file organizations Describe three types of file organizationDescribe three types of file organization Describe indexes and their appropriate useDescribe indexes and their appropriate use Translate a database model into efficient Translate a database model into efficient
structuresstructures Know when to use denormalizationKnow when to use denormalization
33Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
The Physical Design Stage of SDLC The Physical Design Stage of SDLC (Figures 2-4, 2-5 revisited)(Figures 2-4, 2-5 revisited)
Purpose –develop technology specsDeliverable – program/data structures, technology purchases, organization redesigns
Database activity – physical database design
Project Identification and Selection
Project Initiation and Planning
Analysis
Physical Design
Implementation
Maintenance
Logical Design
Physical Design
44Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Physical Database DesignPhysical Database Design
PurposePurpose - translate the logical - translate the logical description of data into the description of data into the technical technical specificationsspecifications for storing and for storing and retrieving dataretrieving data
Goal - create a design for storing Goal - create a design for storing data that will provide data that will provide adequate adequate performanceperformance and insure and insure database database integrityintegrity, , securitysecurity and and recoverabilityrecoverability
55Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Physical Design ProcessPhysical Design Process
Normalized relations
Volume estimates
Attribute definitions
Response time expectations
Data security needs
Backup/recovery needs
Integrity expectations
DBMS technology used
Inputs
Attribute data types
Physical record descriptions (doesn’t always match logical design)
File organizations
Indexes and database architectures
Query optimization
Leads to
Decisions
66Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-1 - Composite usage map (Pine Valley Furniture Company)
77Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-1 - Composite usage map (Pine Valley Furniture Company) (Cont.)
Data volumes
88Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-1 - Composite usage map (Pine Valley Furniture Company) (Cont.)
Access Frequencies (per hour)
99Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-1 - Composite usage map (Pine Valley Furniture Company) (Cont.)
Usage analysis:140 purchased parts accessed per hour 80 quotations accessed from these 140 purchased part accesses 70 suppliers accessed from these 80 quotation accesses
1010Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-1 - Composite usage map (Pine Valley Furniture Company) (Cont.)
Usage analysis:75 suppliers accessed per hour 40 quotations accessed from these 75 supplier accesses 40 purchased parts accessed from these 40 quotation accesses
1111Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Designing FieldsDesigning Fields
Field: smallest unit of data in Field: smallest unit of data in databasedatabase
Field design Field design Choosing data typeChoosing data type Coding, compression, encryptionCoding, compression, encryption Controlling data integrityControlling data integrity
1212Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Choosing Data TypesChoosing Data Types
CHAR – fixed-length characterCHAR – fixed-length character VARCHAR2 – variable-length VARCHAR2 – variable-length
character (memo)character (memo) LONG – large numberLONG – large number NUMBER – positive/negative numberNUMBER – positive/negative number DATE – actual dateDATE – actual date BLOB – binary large object (good for BLOB – binary large object (good for
graphics, sound clips, etc.)graphics, sound clips, etc.)
1313Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-2Example code look-up table (Pine Valley Furniture Company)
Code saves space, but costs an additional lookup to obtain actual value.
1414Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Field Data IntegrityField Data Integrity
Default value – assumed value if no Default value – assumed value if no explicit valueexplicit value
Range control – allowable value Range control – allowable value limitations (constraints or validation limitations (constraints or validation rules)rules)
Null value control – allowing or Null value control – allowing or prohibiting empty fieldsprohibiting empty fields
Referential integrity – range control (and Referential integrity – range control (and null value allowances) for foreign-key to null value allowances) for foreign-key to primary-key match-upsprimary-key match-ups
1515Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Handling Missing DataHandling Missing Data
Substitute an estimate of the missing Substitute an estimate of the missing value (e.g. using a formula)value (e.g. using a formula)
Construct a report listing missing valuesConstruct a report listing missing values In programs, ignore missing data unless In programs, ignore missing data unless
the value is significant (sensitivity the value is significant (sensitivity testing)testing)
Triggers can be used to perform these operations
1616Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Physical RecordsPhysical Records Physical Record: A group of fields Physical Record: A group of fields
stored in adjacent memory locations stored in adjacent memory locations and retrieved together as a unitand retrieved together as a unit
Page: The amount of data read or Page: The amount of data read or written in one I/O operationwritten in one I/O operation
Blocking Factor: The number of Blocking Factor: The number of physical records per pagephysical records per page
1717Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
DenormalizationDenormalization Transforming Transforming normalizednormalized relations into relations into
unnormalizedunnormalized physical record specifications physical record specifications Benefits:Benefits:
Can improve performance (speed) be reducing number of Can improve performance (speed) be reducing number of table lookups (i.e table lookups (i.e reduce number of necessary join queriesreduce number of necessary join queries))
Costs (due to data duplication)Costs (due to data duplication) Wasted storage spaceWasted storage space Data integrity/consistency threatsData integrity/consistency threats
Common denormalization opportunitiesCommon denormalization opportunities One-to-one relationship (Fig 6-3)One-to-one relationship (Fig 6-3) Many-to-many relationship with attributes (Fig. 6-4)Many-to-many relationship with attributes (Fig. 6-4) Reference data (1:N relationship where 1-side has data not Reference data (1:N relationship where 1-side has data not
used in any other relationship) (Fig. 6-5)used in any other relationship) (Fig. 6-5)
1818Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Fig 6-5 A possible denormalization situation: reference data
Extra table access required
Data duplication
1919Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
PartitioningPartitioning Horizontal Partitioning: Distributing the rows of Horizontal Partitioning: Distributing the rows of
a table into several separate filesa table into several separate files Useful for situations where different users need Useful for situations where different users need
access to different rowsaccess to different rows Three types: Key Range Partitioning, Hash Three types: Key Range Partitioning, Hash
Partitioning, or Composite PartitioningPartitioning, or Composite Partitioning Vertical Partitioning: Distributing the columns Vertical Partitioning: Distributing the columns
of a table into several separate filesof a table into several separate files Useful for situations where different users need Useful for situations where different users need
access to different columnsaccess to different columns The primary key must be repeated in each fileThe primary key must be repeated in each file
Combinations of Horizontal and VerticalCombinations of Horizontal and Vertical
Partitions often correspond with User Schemas (user views)
2020Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Partitioning (cont.)Partitioning (cont.) Advantages of Partitioning:Advantages of Partitioning:
Efficiency: Records used together are grouped togetherEfficiency: Records used together are grouped together Local optimization: Each partition can be optimized for Local optimization: Each partition can be optimized for
performanceperformance Security, recoverySecurity, recovery Load balancing: Partitions stored on different disks, Load balancing: Partitions stored on different disks,
reduces contentionreduces contention Take advantage of parallel processing capabilityTake advantage of parallel processing capability
Disadvantages of Partitioning:Disadvantages of Partitioning: Inconsistent access speed: Slow retrievals across Inconsistent access speed: Slow retrievals across
partitionspartitions Complexity: non-transparent partitioningComplexity: non-transparent partitioning Extra space or update time: duplicate data; access from Extra space or update time: duplicate data; access from
multiple partitionsmultiple partitions
2121Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Partitioning in Oracle 9iPartitioning in Oracle 9i
Key-range partitioning:Key-range partitioning: Partition defined by a range of values for Partition defined by a range of values for
column(s) in a tablecolumn(s) in a table May result in uneven distributionMay result in uneven distribution
Hash partitioning:Hash partitioning: Data spread evenly across partitions Data spread evenly across partitions
independent of key valueindependent of key value Composite partitioning:Composite partitioning:
Combination of key and hash partitioningCombination of key and hash partitioning
2222Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Data ReplicationData Replication
Purposely storing the same data in Purposely storing the same data in multiple locations of the databasemultiple locations of the database
Improves performance by allowing Improves performance by allowing multiple users to access the same data multiple users to access the same data at the same time with minimum at the same time with minimum contentioncontention
Sacrifices data integrity due to data Sacrifices data integrity due to data duplicationduplication
Best for data that is not updated oftenBest for data that is not updated often
2323Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Designing Physical FilesDesigning Physical Files 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 records
Tablespace – named set of disk storage Tablespace – named set of disk storage elements in which physical files for database elements in which physical files for database tables can be storedtables can be stored
Extent – contiguous section of disk spaceExtent – contiguous section of disk space Constructs to link two pieces of data:Constructs to link two pieces of data:
Sequential storageSequential storage Pointers – field of data that can be used to locate Pointers – field of data that can be used to locate
related fields or recordsrelated fields or records
2424Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
2525Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
File OrganizationsFile Organizations Technique for physically arranging records of a file Technique for physically arranging records of a file
on secondary storageon secondary storage Factors for selecting file organization:Factors for selecting file organization:
Fast data retrieval and throughputFast data retrieval and throughput Efficient storage space utilizationEfficient storage space utilization Protection from failure and data lossProtection from failure and data loss Minimizing need for reorganizationMinimizing need for reorganization Accommodating growthAccommodating growth Security from unauthorized useSecurity from unauthorized use
Types of file organizationsTypes of file organizations SequentialSequential IndexedIndexed HashedHashed
2626Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-7a Sequential file organization
If not sortedAverage time to find desired record = n/2
1
2
n
Records of the file are stored in sequence by the primary key field values
If sorted – every insert or delete requires resort
2727Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Indexed File OrganizationsIndexed File Organizations Index – a separate table that contains Index – a separate table that contains
organization of records for quick retrievalorganization of records for quick retrieval Primary keys are automatically indexedPrimary keys are automatically indexed Oracle has a CREATE INDEX operation, and Oracle has a CREATE INDEX operation, and
MS ACCESS allows indexes to be created for MS ACCESS allows indexes to be created for most field typesmost field types
Indexing approaches:Indexing approaches: B-tree index, Fig. 6-7bB-tree index, Fig. 6-7b Bitmap index, Fig. 6-8Bitmap index, Fig. 6-8 Hash Index, Fig. 6-7cHash Index, Fig. 6-7c Join Index, Fig 6-9Join Index, Fig 6-9
2828Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Fig. 6-7b – B-tree index
uses a tree searchAverage time to find desired record = depth of the tree
Leaves of the tree are all at same level
consistent access time
2929Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Fig 6-7cHashed file or index organization
Hash algorithmUsually uses division-remainder to determine record position. Records with same position are grouped in lists
3030Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Fig 6-8Bitmap index index organization
Bitmap saves on space requirementsRows - possible values of the attribute
Columns - table rows
Bit indicates whether the attribute of a row has the values
3131Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Fig 6-9 Join Index – speeds up join operations
3232Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
3333Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Clustering FilesClustering Files
In some relational DBMSs, related records In some relational DBMSs, related records from different tables can be stored from different tables can be stored together in the same disk areatogether in the same disk area
Useful for improving performance of join Useful for improving performance of join operationsoperations
Primary key records of the main table are Primary key records of the main table are stored adjacent to associated foreign key stored adjacent to associated foreign key records of the dependent tablerecords of the dependent table
e.g. Oracle has a CREATE CLUSTER e.g. Oracle has a CREATE CLUSTER commandcommand
3434Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Rules for Using IndexesRules for Using Indexes
1. Use on larger tables1. Use on larger tables2. Index the primary key of each table2. Index the primary key of each table3. Index search fields (fields frequently 3. Index search fields (fields frequently
in WHERE clause)in WHERE clause)4. Fields in SQL ORDER BY and GROUP 4. Fields in SQL ORDER BY and GROUP
BY commandsBY commands5. When there are >100 values but not 5. When there are >100 values but not
when there are <30 valueswhen there are <30 values
3535Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Rules for Using Indexes Rules for Using Indexes (cont.)(cont.)
6. DBMS may have limit on number of 6. DBMS may have limit on number of indexes per table and number of indexes per table and number of bytes per indexed field(s)bytes per indexed field(s)
7. Null values will not be referenced 7. Null values will not be referenced from an indexfrom an index
8. Use indexes heavily for non-volatile 8. Use indexes heavily for non-volatile databases; limit the use of indexes for databases; limit the use of indexes for volatile databasesvolatile databases
Why? Because modifications (e.g. inserts, Why? Because modifications (e.g. inserts, deletes) require updates to occur in index filesdeletes) require updates to occur in index files
3636Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
RAIDRAID
Redundant Array of Inexpensive Redundant Array of Inexpensive DisksDisks
A set of disk drives that appear to A set of disk drives that appear to the user to be a single disk drivethe user to be a single disk drive
Allows parallel access to data Allows parallel access to data (improves access speed)(improves access speed)
Pages are arranged in Pages are arranged in stripesstripes
3737Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Figure 6-10RAID with four
disks and striping
Here, pages 1-4 can be read/written simultaneously
3838Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Raid Types (Figure 6-11)Raid Types (Figure 6-11) Raid 0Raid 0
Maximized parallelismMaximized parallelism No redundancyNo redundancy No error correctionNo error correction no fault-toleranceno fault-tolerance
Raid 1Raid 1 Redundant data – fault tolerantRedundant data – fault tolerant Most common formMost common form
Raid 2Raid 2 No redundancyNo redundancy One record spans across data One record spans across data
disksdisks Error correction in multiple Error correction in multiple
disks– reconstruct damaged disks– reconstruct damaged datadata
Raid 3 Error correction in one disk Record spans multiple data disks (more
than RAID2) Not good for multi-user environments,
Raid 4 Error correction in one disk Multiple records per stripe Parallelism, but slow updates due to
error correction contention
Raid 5 Rotating parity array Error correction takes place in same disks as
data storage Parallelism, better performance than Raid4
3939Chapter 6 © 2005 by Prentice Hall© 2005 by Prentice Hall
Data
base
D
ata
base
A
rch
itect
ure
s
Arc
hit
ect
ure
s (
Figure
(F
igure
6
-12
)6
-12
)
Legacy
Systems
Current
Technology
Data
Warehouses