2 Distribution Design
2 Distribution Design
Systems
Presenter: Mr. Thomas Tesha
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 1
Outline
Introduction
Distributed and Parallel Database Design
Distributed Data Control
Distributed Query Processing
Distributed Transaction Processing
Data Replication
Database Integration – Multidatabase Systems
Parallel Database Systems
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 2
Outline
Distributed and Parallel Database Design
Fragmentation
Data distribution
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 3
Distribution Design
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 4
Distribution Design
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 5
Outline
Distributed and Parallel Database Design
Fragmentation
Data distribution
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 6
Fragmentation
Why Fragmentation?
First, application views are usually subsets of relations.
Therefore, the locality of accesses of applications is defined not on
entire relations but on their subsets. Hence it is only natural to
consider subsets of relations as distribution units.
Second, if the applications that have views defined on a given
relation reside at different sites, two alternatives can be followed,
with the entire relation being the unit of distribution.
Either the relation is not replicated and is stored at only one site, or
it is replicated at all or some of the sites where the applications
reside. The former results in an unnecessarily high volume of
remote data accesses. The latter, has unnecessary replication,
which causes problems in executing updates (to be discussed later)
and may not be desirable if storage is limited.
Finally to facilitate concurrency where each unit of fragment can
permit transaction execution.. 7
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez
Fragmentation alternatives
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 8
Fragmentation Alternatives – Horizontal
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 9
Fragmentation Alternatives – Vertical
PROJ1: information about
project budgets
PROJ2: information about
project names and
locations
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 10
Correctness of Fragmentation
Completeness
Decomposition of relation R into fragments R1, R2, ..., Rn is
complete if and only if each data item in R can also be found in
some Ri
Reconstruction
If relation R is decomposed into fragments R1, R2, ..., Rn, then
there should exist some relational operator ∇ such that
R = ∇1≤i≤nRi
Disjointness
If relation R is decomposed into fragments R1, R2, ..., Rn, and
data item di is in Rj, then di should not be in any other fragment
Rk (k ≠ j ).
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 11
Allocation Alternatives
Non-replicated
partitioned : each fragment resides at only one site
Replicated
fully replicated : each fragment at each site
partially replicated : each fragment at some of the sites
Rule of thumb:
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 12
Comparison of Replication Alternatives
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 13
Fragmentation
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 14
PHF – Information Requirements
Database Information
relationship
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 15
PHF - Information Requirements
Application Information
simple predicates : Given R[A1, A2, …, An], a simple predicate pj
is
pj : Ai θValue
where θ {=,<,≤,>,≥,≠}, Value Di and Di is the domain of Ai.
For relation R we define Pr = {p1, p2, …,pm}
Example :
PNAME = "Maintenance"
BUDGET ≤ 200000
minterm predicates : Given R and Pr = {p1, p2, …,pm}
define M = {m1,m2,…,mr} as
M = { mi | mi = pjPr pj* }, 1≤j≤m, 1≤i≤z
where pj* = pj or pj* = ¬(pj).
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 16
PHF – Information Requirements
Example
m1: PNAME="Maintenance" BUDGET≤200000
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 17
PHF – Information Requirements
Application Information
minterm selectivities: sel(mi)
The number of tuples of the relation that would be accessed by a
user query which is specified according to a given minterm
predicate mi.
access frequencies: acc(qi)
The frequency with which a user application qi accesses data.
Access frequency for a minterm predicate can also be defined.
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 18
Primary Horizontal Fragmentation
Preliminaries :
Pr should be complete
Pr should be minimal
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 20
Completeness of Simple Predicates
Example :
Assume PROJ[PNO,PNAME,BUDGET,LOC] has two
applications defined on it.
Find the budgets of projects at each location. (1)
Find projects with budgets less than $200000. (2)
According to (1),
Pr={LOC=“Montreal”,LOC=“New York”,LOC=“Paris”}
which is not complete with respect to (2).
Modify
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 23
Minimality of Simple Predicates
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 24
Minimality of Simple Predicates
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 25
Minimality of Simple Predicates
Example :
Pr ={LOC=“Montreal”,LOC=“New York”, LOC=“Paris”,
BUDGET≤200000,BUDGET>200000}
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 26
COM_MIN Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 27
COM_MIN Algorithm
Initialization :
find a pi Pr such that pi partitions R according to Rule 1
set Pr' = pi ; Pr Pr – {pi} ; F {fi}
Iteratively add predicates to Pr' until it is complete
find a pj Pr such that pj partitions some fk defined according to
minterm predicate over Pr' according to Rule 1
set Pr' = Pr' {pi}; Pr Pr – {pi}; F F {fi}
if pk Pr' which is nonrelevant then
Pr' Pr – {pi}
F F – {fi}
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 28
PHORIZONTAL Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 29
PHF – Example
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 30
PHF – Example
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 31
PHF – Example
Fragmentation of relation PROJ
Applications:
Find the name and budget of projects given their no.
Issued at three sites
Simple predicates
For application (1)
p1 : LOC = “Montreal”
p2 : LOC = “New York”
p3 : LOC = “Paris”
For application (2)
p4 : BUDGET ≤ 200000
p5 : BUDGET > 200000
Pr = Pr' = {p1,p2,p3,p4,p5}
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 32
PHF – Example
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 33
PHF – Example
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 34
PHF – Correctness
Completeness
Since Pr' is complete and minimal, the selection predicates are
complete
Reconstruction
If relation R is fragmented into FR = {R1,R2,…,Rr}
R = Ri FR Ri
Disjointness
Minterm predicates that form the basis of fragmentation should
be mutually exclusive.
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 35
Derived Horizontal Fragmentation
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 36
DHF – Definition
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 37
DHF – Example
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 38
DHF – Correctness
Completeness
Referential integrity
Let R be the member relation of a link whose owner is relation S
which is fragmented as FS = {S1, S2, ..., Sn}. Furthermore, let A
be the join attribute between R and S. Then, for each tuple t of
R, there should be a tuple t' of S such that
t[A] = t' [A]
Reconstruction
Same as primary horizontal fragmentation.
Disjointness
Simple join graphs between the owner and the member
fragments.
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 39
Vertical Fragmentation
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 40
Vertical Fragmentation
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 41
Vertical Fragmentation
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 42
VF – Information Requirements
Application Information
Attribute affinities
a measure that indicates how closely related the attributes are
This is obtained from more primitive usage data
Attribute usage values
Given a set of queries Q = {q1, q2,…, qq} that will run on the relation
R[A1, A2,…, An],
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 43
VF – Examples
The following are example of 4 queries on applications that
are defined for the relation PROJ where vertical fragment
on attributes is indicated
PNO PNAMEBUDGETLOC
q1: Find the budget of a project, given q1 1 0 1 0
its identification number q2 0 1 1 0
SELECT BUDGET FROM PROJ q3 0 1 0 1
WHERE PNO=Value q4 0 0 1 1
q2: Find the names and budgets of all projects.
Attribute Usage Matrix
SELECT PNAME,BUDGET FROM PROJ
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 44
VF – Affinity Measure aff(Ai,Aj)
access
query access access
frequency of a query
execution
all sites
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 45
VF – Calculation of aff(Ai, Aj)
Assume each query in the previous example accesses the attributes once
during each execution.
Also assume the access frequencies S S S 1 2 3
q1 15 20 10
q2 5 0 0
q3 25 25 25
q4 3 0 0
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 46
VF – Calculation of aff(Ai, Aj)
Using the cost matrix, we can construct the attribute affinity matrix as follows
PNO BUDGET =45
PNAMEBUDGET= 5
PNAME LOC =75
BUDGET LOC 3
LOC 0 75 3 78
i j
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 49
Bond Energy Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 50
Bond Energy Algorithm
z 1
bond(PNO,BUDGET) =45*45+0*5+45*53+0*78=4410
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 51
BEA – Complete Example
Consider the following AA matrix and the corresponding CA matrix where
PNO and PNAME have been placed. Place BUDGET:
PNO PNAMEBUDGET LOC PNO PNAME
0
PNO 45 0 45 PNO 45 0
75 PNAME 0 80
PNAME 0 80 5
3 BUDGET 45 5
BUDGET 45 5 53
0 75 3 78 LOC 0 75
LOC
Ordering (0-3-1) :
cont(A0,BUDGET,PNO) = 2bond(A0, BUDGET)+2bond(BUDGET, PNO)
–2bond(A0 , PNO)
= 8820
Ordering (1-3-2) :
cont(PNO,BUDGET,PNAME) = 10150
Ordering (2-3-4) :
cont (PNAME,BUDGET,LOC) = 1780
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 52
BEA – Example
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 53
VF – Algorithm: Partitioning Algorithm
The objective of
the splitting
activity is to
find sets of
attributes that
are accessed Locating a Splitting Point
solely, or for the
54
most part,
Lecture slides bycustomized from © 2020, M.T. Özsu & P. Valduriez
as adapted and
VF – Algorithm
Two problems :
Cluster forming in the middle of the CA matrix
Shift a row up and a column left and apply the algorithm to find
the “best” partitioning point
Do this for all possible shifts
Cost O(m2)
More than two clusters
m-way partitioning
try 1, 2, …, m–1 split points along diagonal and try to find the
best point for each of these
Cost O(2m)
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 55
VF – Correctness
Reconstruction
Reconstruction can be achieved by
R = ⋈K Ri, Ri FR
Disjointness
TID's are not considered to be overlapping since they are
maintained by the system
Duplicated keys are not considered to be overlapping
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 56
VF – Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 57
VF – Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 58
VF – Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 59
VF – Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 60
VF – Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 61
VF – Algorithm
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 62
Hybrid Fragmentation
In most cases a simple horizontal or vertical fragmentation
of a database schema will not be sufficient to satisfy the
requirements of user applications. In this case a vertical
fragmentation may be followed by a horizontal one, or vice
versa, producing a tree structured partitioning
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 63
Reconstruction of HF
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 64
Hybrid Fragmentation
In most cases a simple horizontal or vertical fragmentation
of a database schema will not be sufficient to satisfy the
requirements of user applications. In this case a vertical
fragmentation may be followed by a horizontal one, or vice
versa, producing a tree structured partitioning
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 65
Outline
Distributed and Parallel Database Design
Fragmentation
Data distribution
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 66
Fragment Allocation
Problem Statement
Given
F = {F1, F2, …, Fn} fragments
S ={S1, S2, …, Sm} network sites
Q = {q1, q2,…, qq} applications
Find the "optimal" distribution of F to S.
Optimality
Minimal cost
Communication + storage + processing (read & update)
Cost in terms of time (usually)
Performance
Response time and/or throughput
Constraints
Per site constraints (storage & processing)
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 67
Information Requirements
Database information
selectivity of fragments
size of a fragment
Application information
access types and numbers
access localities
Communication network information
unit cost of storing data at a site
unit cost of processing at a site
Computer system information
bandwidth
latency
communication overhead
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 68
Allocation
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 69
Allocation Model
General Form
min(Total Cost)
subject to
response time constraint
storage constraint
processing constraint
Decision Variable
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 70
Allocation Model
Total Cost
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 71
Allocation Model
Processing component
access cost + integrity enforcement cost + concurrency control cost
Access cost
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 72
Allocation Model
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 73
Allocation Model
Constraints
Response Time
execution time of query ≤ max. allowable response time for that query
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 74
Allocation Model
Solution Methods
FAP is NP-complete
DAP also NP-complete
Heuristics based on
single commodity warehouse location (for FAP)
knapsack problem
branch and bound techniques
network flow
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 75
Allocation Model
Lecture slides as adapted and customized from © 2020, M.T. Özsu & P. Valduriez 76
Individual exercise
Question 1