database Chapter05
database Chapter05
5-1
Steps in Database Design
Real World
5-2
Objectives
§Define terms
§Describe the physical database design process
§Choose storage formats for attributes
§Select appropriate file organizations
§Describe three types of file organization
§Describe indexes and their appropriate use
§Translate a database model into efficient structures
§Know when and how to use denormalization
5-3
Physical Database Design
5-4
Physical Design for Regulatory Compliance
§Sarbanes- Oxley Act (SOX) – protect investors by
improving accuracy and reliability
§Committee of Sponsoring Organizations (COSO) of the
Treadway Commission
§IT Infrastructure Library (ITIL)
§Control Objectives for Information and Related
Technology (COBIT)
5-5
5-6
5-7
Sarbanes Oxley (SOX) Act Compliance Requirements
5-8
Physical Design Process
Inputs Decisions
lNormalized relations
lAttribute data types
lVolume estimates
lPhysical record descriptions
lAttribute definitions (doesn’t always match
logical design)
lResponse time expectations
lFile organizations
lData security needs Leads to
lIndexes and database
lBackup/recovery needs
architectures
lIntegrity expectations
lQuery optimization
lDBMS technology used
5-9
Figure 5-1 Composite usage map
(Pine Valley Furniture Company)
5-10
Figure 5-1 Composite usage map
(Pine Valley Furniture Company) (cont.)
Data volumes
5-11
Figure 5-1 Composite usage map
(Pine Valley Furniture Company) (cont.)
Access Frequencies
(per hour)
5-12
Figure 5-1 Composite usage map
(Pine Valley Furniture Company) (cont.)
Usage analysis:
14,000 purchased parts
accessed per hour è
8000 supplies accessed from
these 14,000 purchased part
accesses è
7000 suppliers accessed from
these 8000 supplies accesses
5-13
Figure 5-1 Composite usage map
(Pine Valley Furniture Company) (cont.)
Usage analysis:
7500 suppliers accessed per
hour è
4000 supplies accessed from
these 7500 supplier accesses
è
4000 purchased parts
accessed from these 4000
supplies accesses
5-14
Designing Fields
Field1 Field2 …..
5-15
Choosing Data Types
5-16
Figure 5-2 Example of a code look-up table
(Pine Valley Furniture Company)
5-17
Field Data Integrity
5-18
Handling Missing Data
5-20
Figure 5-3 A possible denormalization situation: two entities with one-
to-one relationship
5-21
Figure 5-4 A possible denormalization situation: a many-to-many
relationship with nonkey attributes
Extra table
access
required
5-22
Figure 5-5
A possible
denormalization
situation:
reference data
Extra table
access
required
Data duplication
5-23
Denormalize with caution
• Denormalization can
• Increase chance of errors and inconsistencies
• Reintroduce anomalies
• Force reprogramming when business rules change
• Perhaps other methods could be used to improve
performance of joins
• Organization of tables in the database (file organization
and clustering)
• Proper query design and optimization
5-24
Partitioning
• Horizontal Partitioning: Distributing the rows of a
logical relation into several separate tables
• Useful for situations where different users need access to
different rows
• Three types: Key Range Partitioning, Hash Partitioning, or
Composite Partitioning
• Vertical Partitioning: Distributing the columns of a
logical relation into several separate physical tables
• Useful for situations where different users need access to
different columns
• The primary key must be repeated in each file
• Combinations of Horizontal and Vertical
5-25
Vertical vs Horizontal Partitioning
5-26
Example of Partitioning
5-27
Partitioning pros and cons
• Advantages of Partitioning:
• Efficiency: Records used together are grouped together
• Local optimization: Each partition can be optimized for
performance
• Security: data not relevant to users are segregated
• Recovery and uptime: smaller files take less time to back up
• Load balancing: Partitions stored on different disks, reduces
contention
• Disadvantages of Partitioning:
• Inconsistent access speed: Slow retrievals across partitions
• Complexity: Non-transparent partitioning
• Extra space or update time: Duplicate data; access from multiple
partitions
5-28
Oracle’s Horizontal Partitioning
• Range partitioning
• Partitions defined by range of field values
• Could result in unbalanced distribution of rows
• Like-valued fields share partitions
• Hash partitioning
• Partitions defined via hash functions
• Will guarantee balanced distribution of rows
• Partition could contain widely varying valued fields
• List partitioning
• Based on predefined lists of values for the partitioning key
• Composite partitioning
• Combination of the other approaches
5-29
Vertical Partitioning
• Distribution of the columns of a logical relation into
several separate physical tables.
• Example:
• One PART table involving accounting, engineering, and sales
attributes.
• Split into three, each with the same Product ID, one for each
user group.
• This reduces demand on individual relations.
• When combinations of data are required, perform join queries
for all needed relations.
5-30
Designing Physical Database Files
•Physical File:
• A named portion of secondary memory allocated for
the purpose of storing physical records
• Tablespace–named logical storage unit in which data
from multiple tables/views/objects can be stored
•Tablespace components
• Segment – a table, index, or partition
• Extent–contiguous section of disk space
• Data block – smallest unit of storage
5-31
Hard Disk Structure
5-32
Hard Disk Structure
5-33
Figure 5-6 DBMS terminology in an Oracle 12c environment
5-34
File Organizations
• Technique for physically arranging records of a file on
secondary storage
• Factors for selecting file organization:
• Fast data retrieval and throughput
• Efficient storage space utilization
• Protection from failure and data loss
• Minimizing need for reorganization
• Accommodating growth
• Security from unauthorized use
• Types of file organizations
• Heap – no particular order
• Sequential
• Indexed
• Hashed
5-35
Figure 5-7a
Sequential file
organization
5-37
Library Indexing System
5-38
Figure 5-7b Indexed file organization
a) Join index
for common
non-key
columns
5-40
Figure 5-7c
Hashed file
organization
Hash algorithm
Usually uses division-
remainder to determine
record position. Records
with same position are
grouped in lists.
5-41
5-42
Clustering Files
• In some relational DBMSs, related records from different
tables can be stored together in the same disk area
• Useful for improving performance of join operations
• Primary key records of the main table are stored adjacent
to associated foreign key records of the dependent table
• e.g. Oracle has a CREATE CLUSTER command
5-43
Unique and Nonunique Indexes
5-44
Rules for Using Indexes
5-45
Rules for Using Indexes (cont.)
6. Avoid use of indexes for fields with long values;
perhaps compress values first
7. If key to index is used to determine location of
record, use surrogate (like sequence number) to
allow even spread in storage area
8. DBMS may have limit on number of indexes per
table and number of bytes per indexed field(s)
9. Be careful of indexing attributes with null
values; many DBMSs will not recognize null
values in an index search
5-46
Exercise for Indexing
• Author(AID, Name, Street, City, Country, Email, Mobile, BankAccount …)
5-47
Summary
• Physical database design:
• Translates the logical description of data into the technical
specifications for storing and retrieving data;
• Its goal is to create a design for storing data that will provide
adequate performance and insure database integrity, security and
recoverability.
• A file organization arranges the records of a file on a
secondary storage device. The three categories are:
1. sequential;
2. indexed; and
3. hashed.
48 5-48