ADT Lecture 13
ADT Lecture 13
Lecture #13
Distributed Databases Contd…
1
Distributed Query Optimization
Distributed query optimization is more
complex due to the distribution of data.
The distributed query is processed and
optimized as a number of separate
layers consisting of:
I. Query Decomposition
II. Data Localization
III. Global Optimization
IV. Local Optimization
I. Query Decomposition:
This layer takes a query expressed on
the global relations and
performs a partial optimization
using the techniques of
◦ query decomposition and
◦ optimization (using heuristic rules)
discussed earlier.
2
II.Data Localization:
This layer takes into account how the
data has been distributed.
A further iteration of optimization is
performed
◦ by replacing the global relations at
the leaves of the relational algebra tree
◦ with their reconstruction algorithms
(sometimes called data localization
programs),
The relational algebra tree formed by
applying the reconstruction algorithms
is sometimes known as the generic
relational algebra tree.
Thereafter we use reduction techniques
to generate a simpler and optimized
query.
3
III.Global Optimization
This layer takes account of statistical information to find a
near-optimal execution plan.
The output from this layer is
o an execution strategy based on fragments
o with communication primitives added to send parts of the
query to the local DBMSs to be executed there
o and to receive the results.
IV.Local Optimization
Whereas the first three layers are run at the control site
(typically the site that launched the query),
o this particular layer is run at each of the local sites
involved in the query.
o Each local DBMS will perform its own local optimization
using techniques discussed earlier for centralized DBMS.
4
The particular reduction technique employed is dependent on the type
of fragmentation involved.
Considering reduction techniques for following types of fragmentation:-
o Primary horizontal fragmentation
o Vertical fragmentation
o Derived horizontal fragmentation
Here we consider two cases:-
I. Reduction with Selection operation
II. Reduction for the Join operation
I. Reduction with Selection Operation
o If the selection predicate contradicts the definition of the fragment,
then
o this results in an empty intermediate relation and the operations can
be eliminated.
II.Reduction for the Join operation
o We first use the transformation rule that allows the Join operation to
be commuted with the Union operation:-
(R1 U R2) ⋈ R3 = (R1 ⋈ R3) U (R2 ⋈ R3)
5
Reduction for Primary Horizontal Fragmentation
We then examine each of the individual Join
operations
o to determine whether there are any redundant joins
o that can be eliminated from the result.
A redundant join exists if the fragment predicates
do not overlap.
This transformation rule is important in DDBMS
o allowing a join of two relations to be implemented as a
union of partial joins,
o where each part of the union can be performed in parallel.
6
Example 1
List the flats that are for rent along with the corresponding branch
details.
We can express this query in SQL as:-
SELECT *
FROM Branch B, PropertyForRent P
WHERE B.BranchNo = P.BranchNo AND P.Type = ‘Flat’;
We assume that PropertyForRent and Branch are horizontally
fragmented as follows:-
P1: branchNo = ‘B003’ ^ type = ‘House’ (PropertyForRent)
P2: branchNo = ‘B003’ ^ type = ‘Flat’ (PropertyForRent)
P3: branchNo = ‘B003’ (PropertyForRent)
B1: branchNo = ‘B003’ (Branch)
B2: branchNo = ‘B003’ (Branch)
7
The generic relational algebra tree for this query is shown in
fig 1(a).
Fig 1 (a)
8
If we commute the Selection and Union operations, we obtain the
relational algebra tree shown in fig 1(b).
This tree is obtained by observing that the following branch of the tree is
redundant (it produces no tuples contributing to the result) and can be
removed:
Further, because the selection predicate is a subset of the definition of the
fragmentation for P2, the selection is not required.
Fig 1 (b)
9
If we now commute the Join and Union operations, we obtain
the tree shown in fig 1 (c).
Fig 1 (c)
10
Since the second and third joins do not contribute
to the result they can be eliminated, giving the
reduced query shown in fig 1 (d).
Fig 1 (d)
11
Reduction for Vertical Fragmentation
Reduction for vertical fragmentation involves
o removing those vertical fragments that have no attributes in
common
o with the projection attributes except the key of the relation.
Example 2
List the names of each member of staff
We can express this query in SQL as:
SELECT fName, lName
FROM Staff;
We will use the fragmentation schema for Staff as
S1: staffno, position, gender, DOB, salary(Staff)
S2: staffno, fName, lName, branchNo(Staff)
12
The generic relational algebra tree for this query is shown in
fig 2(a).
By commuting the Projection and Join operations,
o the Projection operation on S1 is redundant
o because the projection attributes fName and lName are
not part of S1.
The reduced tree is shown in Fig 2 (b).
Fig 2
13
Reduction for Derived Horizontal Fragmentation
In this case, we use the knowledge that
o the fragmentation for one relation is based on the other relation
and,
o in commuting, some of the partial joins should be redundant.
Example 3
List the clients registered at branch B003 along with the branch
details
SELECT *
FROM Branch B, Client C
WHERE B.BranchNo = C.BranchNo AND B.BranchNo = ‘B003’;
We assume that
o Branch is horizontally fragmented as in example 5 and that
o the fragmentation for Client is derived from Branch:
B1: branchNo = ‘B003’ (Branch) B2: branchNo = ‘B003’ (Branch)
Ci = Client ⊳branchno Bi i = 1, 2
14
The generic relational algebra tree is shown in fig 3 (a).
If we commute the Selection and Union operations, the Selection on
fragment B2 is redundant and this branch of the tree can be eliminated.
The entire Selection operation can be eliminated as fragment B1 is itself
defined on branch B003.
If we now commute the Join and Union operations, we get the tree shown
in fig 3 (b).
The second Join operation between B1 and C2 produces a null relation and
can be eliminated, giving the reduced tree in fig 3 (c).