Physical Database Design: External Schemas For Our Database
Physical Database Design: External Schemas For Our Database
Physical Database Design: External Schemas For Our Database
Overview
After ER design, schema refinement, and the
definition of views, we have the conceptual and
external schemas for our database.
The next step is to choose indexes, make clustering
decisions, and to refine the conceptual and external
schemas (if necessary) to meet performance goals.
We must begin by understanding the workload:
Decisions to Make
What indexes should we create?
Which relations should have indexes? What field(s) should
be the search key? Should we build several indexes?
Example 1
Example 2
E.dno=D.dno
WHERE
Example Schemas
Contracts (Cid, Sid, Jid, Did, Pid, Qty, Val)
Depts (Did, Budget, Report)
Suppliers (Sid, Address)
Parts (Pid, Cost)
Projects (Jid, Mgr)
We will concentrate on Contracts, denoted as
CSJDPQV. The following ICs are given to hold:
JP C, SD P, C is the primary key.
10
Denormalization
Suppose that the following query is important:
Is the value of a contract less than the budget of the department?
11
Choice of Decompositions
There are 2 ways to decompose CSJDPQV into BCNF:
SDP and CSJDQV; lossless-join but not dep-preserving.
SDP, CSJDQV and CJP; dep-preserving as well.
12
13
14
Horizontal Decompositions
Our definition of decomposition: Relation is replaced
by a collection of relations that are projections. Most
important case.
Sometimes, might want to replace relation by a
collection of relations that are selections.
15
16
17
18
SELECT *
FROM Sailors S
WHERE S.sname IN
(SELECT DISTINCT Y.sname
FROM YoungSailors Y)
SELECT S.*
FROM Sailors S,
YoungSailors Y
WHERE S.sname = Y.sname
19
dname
Department D,Temp
D.building = Temp.building
D.num_emps > Temp.empcount;
20
Hard to convert.
Subqueries inside OR: Hard to convert.
ALL subqueries: Hard to convert.
21
22
vs.
GROUP BY
E.dno
and
SELECT T.dno, AVG(T.sal)
FROM Temp T
GROUP BY T.dno
23
Summary
Database design consists of several tasks:
requirements analysis, conceptual design, schema
refinement, physical design and tuning.
In general, have to go back and forth between these tasks to
refine a database design, and decisions in one task can
influence the choices in another task.
24
Summary
The conceptual schema should be refined by
considering performance criteria and workload:
May choose 3NF or lower normal form over BCNF.
May choose among alternative decompositions into BCNF
(or 3NF) based upon the workload.
May denormalize, or undo some decompositions.
May decompose a BCNF relation further!
May choose a horizontal decomposition of a relation.
Importance of dependency-preservation based upon the
dependency to be preserved, and the cost of the IC check.
Can add a relation to ensure dep-preservation (for 3NF,
not BCNF!); or else, can check dependency using a join.
25
Summary (Contd.)
Over time, indexes have to be fine-tuned (dropped,
created, re-built, ...) for performance.
Should determine the plan used by the system, and adjust
the choice of indexes appropriately.
26