Distributed Database Management Systems: Lecture 31. The main topics covered in this chapter include: query decomposition; steps in query processing; SQL query on distributed relations; optimized fragment query with communication operations;...
Trang 1Distributed Database Management Systems
Lecture 31
Trang 2In the previous lecture
• Basic Concepts of Query
Optimization
• QP in centralized and
Distributed DBs
Trang 3In this Lecture
• Query Decomposition
• Its Phases
Trang 4SQL Query on Distributed Relations
QUERY DECOMPOSITION GLOBALSCHEMAAlgebraic Query on Distributed
Relations
DATA LOCALIZATION FRAGMENTSCHEMAFragment Query
GLOBAL OPTIMIZATION STAT OFFRAGMENTSOptimized Fragment Query with
Communication Operations LOCAL
OPTIMIZATION SCHEMALOCAL
Optimized Local Query
Steps in Query Processing
Trang 71- Normalization
complex
Analysis (like compilers)
Clause
Trang 9V into U and ^ into
V into U and ^ into or ⋈
.
Trang 10• SELECT eName
FROM EMP, ASG
WHERE EMP.eNo = ASG.eNo AND ASG.pNo = ‘P1’
AND dur = 12 OR dur = 24
Trang 11^ASG.pNo = ‘P1’ ^ dur = 24)
Trang 122- Analysis
• Reject incorrect ones
• Type incorrect
–Relations/attributes not exist
Trang 14Query Graph
or operand relations
• Links represent joins or
projection (result node)
• Self join/select on
operand nodes
Trang 15• Select eName, resp
FROM EMP, ASG, PROJ
WHERE EMP.eNo = ASG.eNo AND ASG.pNo = PROJ.pNo AND pName = ‘CAD/CAM’ AND dur ≥ 36
AND title = ‘Programmer’
Trang 16Query Graph
RESULT EMP
Dur ≥ 36
ASG.pNo = PROJ.pNo
pName =
‘CAD/CAM’ resp
Trang 18Semantically Incorrect
• Select eName, resp
FROM EMP, ASG, PROJ
WHERE EMP.eNo =ASG.eNo AND pName = ‘CAD/CAM’ AND dur ≥ 36
AND title = ‘Programmer’
Trang 19Query Graph
RESULT EMP
Dur ≥ 36
pName =
‘CAD/CAM’ resp
Trang 203- Elimination of Redundancy
already used in views
• User mistake or this
replacement may contain
redundant predicates
rules
Trang 22• Select title
FROM EMP
WHERE (title = ‘Prog’
AND ((not (title = ‘Prog’))
OR title = ‘Elect Engr’)
AND (not (title = ‘Elect Engr’)))
OR eName = ‘Saleem’
Trang 23(false) v (false) v p3 = p3
Trang 27steps-Query Tree
• Select eName
FROM EMP, ASG, PROJ
WHERE EMP.eNo = ASG.eNo AND ASG.pNo = PROJ.pNo
AND pName = ‘CAD/CAM’ AND (dur = 36 or dur = 24)
Trang 28PROJ ASG EMP
Trang 29(R x S) x T S x (R x T)
(R (R S) T ⋈ ⋈ S (R ⋈ ⋈ T)
Trang 303- Idempotency of unary Ops
i) A’( A”(R)) A’(R)
ii) σp1(A1)(σp2(A2) (R))
σp1(A1) ∧ p2(A2)
(R)-4- Commuting selection with projection
A1, ….,An ( p(Ap)(R)) A1,
….,An (( p(Ap) A1, ….,An, Ap
Trang 32• Many eq query trees
can be generated
• Comparing all such
trees to select best is not feasible
• Heuristic is applied
Trang 331 Separation of Unary Ops
relation grouped together
binary ops
Trang 34ASN PROJ EMP
x
⋈ pNo^eNo
(pName = ‘CAD/CAM’)^ ( dur = 12 v dur = 24)^ eName ’Saleem’
eName
Trang 35PROJ ASG EMP
pNo, eName eName
Trang 36• This concludes QP that
comprises 4 steps
• Now we move to the
second phase of Query Optimization; Data
Localization of DD
Trang 37• QD at global level, this
phase transform into
local ones
• A Nạve rule…
• However, it won’t be
an efficient one
Trang 38Reduction During Data
Localization
Trang 39Example Schema
Trang 40• Reduction with Selection
• Rule 1:
pi (Rj) = Ø if x in R ∀ j: (pi(x) ^ pj(x))
• That is, there exist
conflicting predicates
Trang 41• Select * from EMP where
Trang 42Reduction on Join
• Distributing joins over
unions and avoiding
unnecessary joins
• (R1UR2) ⋈ R3= (R1 ⋈
R3) U (R2UR3)
Trang 43• Rule2:
• Ri⋈Rj = Ø if x in R∀ iand y in R∀ j: (pi(x) ^
pj(x))
• Useless joins can be
determined viewing the join predicates
Trang 44• Remember! Reduced query
is not always better We
have to be watchful
• ASG1 = eNo ≤ ‘E3’ (ASG)ASG1 =
• ASG2 = ’eNo > ‘E3’ (ASG).ASG2 =
Trang 45–θ {=, <, ≠ ≤, >, ≥} ∈ ∈ ∀– ←Ø ⇒ ⋉ ⋈ ∪ ^
–