Você está na página 1de 31

ESD 2004

Tuyet-Trinh Vu
1
Distributed Query Processing
V Tuyt Trinh
Trinhvt-fit@mail.hut.edu.vn
http://is.hut.vn/~trinhvt
Department of Information Systems School of ICT
Hanoi University of Technology
Outline
Part 1: Overview of query processing
Optimization
Execution
Part 2 : Querying distributed data sources
Characteristics
Some techniques
Querying of Distributed Data
Sources
ESD 2004 2
ESD 2004
Tuyet-Trinh Vu
2
Part 1: Overview of query processing
Architecture of query processing (QP)
Query execution
Algorithms
Implementation
Query optimization
Rewriting
Planning
Distributed architectures
Querying of Distributed Data
Sources
ESD 2004 3
Architecture of QP
a1 a2 a3 a4 a5
Querying of Distributed Data Sources ESD 2004 4
Execution Engine
Optimization
Parse
Data
Query
Internal
representation
of query
Execution plan
Select *
From R, S, T
R S
T
Scan(S) Scan_I(T)
Scan(R)
HJ
I_NLJ
Results
ESD 2004
Tuyet-Trinh Vu
3
Query execution
Principle
accessing to data
executing every operator (algorithm) of query
Taxonomy of algorithms
sorting-based vs. hash-based vs. index-based
one-pass vs. two-pass vs. multi-pass
blocking vs. non-blocking
Querying of Distributed Data
Sources
ESD 2004 5
Nested-loop-join (NLJ)
Principle
reading the external relation
R & iterating over the
internal relation S
one-and-haft pass, non-
blocking
Variations
Tuple-based NLJ, block-
based NLJ, index-based NLJ
Querying of Distributed Data
Sources
ESD 2004 6
Relation S
SOURCE
S
SOURCE
R
Tuple R
Tuple R
Tuple S
Matching
ESD 2004
Tuyet-Trinh Vu
4
Hash Join (HJ)
Principle
using a hash table (HT) of
R
two-pass, blocking
algorithm
Process
build the HT of R
probe every tuple of S
with corresponding tuples
in the HT of R
Querying of Distributed Data
Sources
ESD 2004 7
SOURCE
S
SOURCE
R
Tuple R Tuple S
Hash Table S

1 n
Matching
hash(Tuple S)
hash(Tuple R)
build
probe
Implementation
Iterator model [Gra93]
not need to store
intermediate results
demand-driven flow
(synchronous)
uniform interface
Querying of Distributed Data
Sources
ESD 2004 8
Oper.
Oper.
Oper.
Oper.
open open
open
next next
next
close
close close
ESD 2004
Tuyet-Trinh Vu
5
Part 1: Overview of query processing
- Architecture of query processing (QP)
- Query execution
-Algorithms
-Implementation
Query optimization
Rewriting
Planning
Querying of Distributed Data
Sources
ESD 2004 9
Query optimization [Ioa00]
Querying of Distributed Data
Sources
ESD 2004 10
Rewriter
Planner
Method-Structure
Space
Algebraic
Space
Size-Distribution
Estimator
Cost Model
Rewriting Stage (Declarative)
Planning Stage (Procedural)
ESD 2004
Tuyet-Trinh Vu
6
Rewriting
Principle [Lev01]
reformulating a
client query to use
available views
replacing views by
their definition
Querying of Distributed Data
Sources
ESD 2004 11
T U R S
T U
V
client query
R S
View def.: V
Query optimization [Ioa00]
Querying of Distributed Data
Sources
ESD 2004 12
Rewriter
Planner
Method-Structure
Space
Algebraic
Space
Size-Distribution
Estimator
Cost Model
Rewriting Stage (Declarative)
Planning Stage (Procedural)
Search space
Cost estimation
Search strategy
ESD 2004
Tuyet-Trinh Vu
7
Search Space
Algebraic space
operators execution orders that are to be considered by
the Planner for each query sent to it
Method-structure space
implementation choices that exist for the execution of
each specified ordered series of operators
Querying of Distributed Data
Sources
ESD 2004 13
Cost estimation
Cost factors
CPU cost + I/O cost + Communication cost
Size of (intermediate) relations
Optimization objective
minimizing resources consummation
maximizing throughput

Querying of Distributed Data
Sources
ESD 2004 14
Different application scenarios have
different weight for those factors and
different optimization objective
ESD 2004
Tuyet-Trinh Vu
8
Query optimization [Ioa00]
Querying of Distributed Data
Sources
ESD 2004 15
Rewriter
Planner
Method-Structure
Space
Algebraic
Space
Size-Distribution
Estimator
Cost Model
Rewriting Stage (Declarative)
Planning Stage (Procedural)
Search strategy
Search strategy
Objective
exploring the set of alternative execution plans and finding
the cheapest one
Taxonomy
Polynomial vs. Combinatorial
Heuristics vs. Systematic
Deterministic vs. Randomized
Transformative vs. Constructive
orthogonal but related
Querying of Distributed Data
Sources
ESD 2004 16
ESD 2004
Tuyet-Trinh Vu
9
Bottom-up approach
Systematic
Deterministic
Constructive
Querying of Distributed Data
Sources
ESD 2004 17
r1 r2 r3 r1 r1 r4
2
r3 r2
r1
r3 r1
r4
r3 r2
r4
r1
3
4

r1 r2 r3
1

r4
Top-down approach
Systematic
Deterministic
Transformative
Querying of Distributed Data
Sources
ESD 2004 18
r1 r2
r3
r4
r1 r2
r4
r3
r2 r4
r1
r3
r4 r2
r1
r3

ESD 2004
Tuyet-Trinh Vu
10
Heuristic approach
Deterministically choosing the next relation without search
Criteria of choosing is based on heuristics:
minimize intermediate result, ex. push down selection, projection,
limit disk access, ex. use index if possible,

limit the plans for considering by focusing in some form of
query plan
left-deep tree
right-deep tree
bushy tree
Querying of Distributed Data
Sources
ESD 2004 19
Distributed architectures
Distributed DBMSs
having global schema, no heterogeneity, centralized
catalog of partitions
need to determine involved fragments
Mediation Systems
having global schema, correspondence definition as GaV
or LaV
need to identify interested sources and to resolve
heterogeneity
P2P Systems
no global knowledge about data distribution, dynamic
topologies
need to direct query processing tasks from one node to
neighboring nodes
Querying of Distributed Data
Sources
ESD 2004 20
ESD 2004
Tuyet-Trinh Vu
11
Distributed QP
Querying of Distributed Data
Sources
ESD 2004 21
Decomposition
Localization
Global optimization
Local optimization
Query on distributed relations
Algebraic expression
on distributed relations
Fragment query
Optimized fragments query
with communication operations
Optimized local query
Control
site
Local
sites
QP in mediation systems
Querying of Distributed Data
Sources
ESD 2004 22
Execution Engine
Optimization
Reformulation
Query
Query over
exported schemas
Query plan
Data
Wrapper
Data
Wrapper
Data
Wrapper
Result
Sources
catalog
Source
description
LaV / GaV
mediator
wrappers
data
sources
ESD 2004
Tuyet-Trinh Vu
12
QP in P2P systems
Purely decentralized
~ No central co-ordination.
propagating a query from a
peer to neighboring peers
Partially centralized
~ Some nodes assume role of
local servers, called
SuperPeers
propagating a query from a
super peer to its under peers
Querying of Distributed Data
Sources
ESD 2004 23
Q
A
B
R
D
C
Q
A
R
C
B
Super
Peer
Part 2: Querying distributed data sources
Characteristics of distributed data systems
(DDS)
Forwarding query
Adaptive query evaluation (AQP)
Interactive query evaluation (IQP)
Querying of Distributed Data
Sources
ESD 2004 24
ESD 2004
Tuyet-Trinh Vu
13
Characteristics
Heterogeneity
model, semantic, capacity,
Distribution
communication environment (ex: Internet)
Autonomy
availability of knowledge (ex: statistics)
availability of data (ex: available source)
Querying of Distributed Data
Sources
ESD 2004 25
Forwarding query
Principle
reformulating a client query to use available
sources, ex. partitions, underlying sources,
based on knowledge of data location, ex. metadata,
Terminologies
Centralized
localization in DDBMS [OV99]
query rewriting in mediation systems (GaV vs. LaV) [CHS+95,
GMPQ+97, PL00]
Distributed
query propagation or query reformulation in P2P systems
(based on DHT or semantic path) [LIST03, BDK+03, TL04]
Querying of Distributed Data
Sources
ESD 2004 26
ESD 2004
Tuyet-Trinh Vu
14
Local as View (LaV)
S1: V1(title, year, director) :-
MovieYear(title, year) &
MovieRev(title, director, review)
S2: V2(title, year, director) :-
MovieYear(title, year) &
MovieRev(title, director, review)
S3: V3(title, review) :-
MovieRev(title, director, review)
Querying of Distributed Data
Sources
ESD 2004 27
Schma global
S1 S2 S3
MovieYear (title, year)
MovieRev(title, director, review)
V1(title, director, year)
V2(title, director, year)
V3(title, review)
Exported schemas are defined as views on the global schema
LaV - rewriting
Query: look for reviews of films in 1997
q(title, review):- MovieYear(title, 1997) &
MovieReview(title, director, review)
Querying of Distributed Data
Sources
ESD 2004 28
???
q1(title, review):-V1(title, 1997,director) &
V3(title, review)
q2(title, review):-V2(title, 1997,director) &
V3(title, review)

ESD 2004
Tuyet-Trinh Vu
15
Principle of rewriting in LaV
Inverse rules
V1(title, year, director) :- MovieYear(title, year) &
MovieRev(title, director, review)
MovieYear(title, year) :- V1(title, year, _)
MovieRev(title, director,?) :-V1(title, _, director)
V3(title, review) :- MovieRev(title, _, review)
MovieRev(title, ?, review):-V3(title, review)

Unfolding
q1(title, review):- V1(title, 1997, _) & V1(title, _, director)
q2(title, review):- V1(title, 1997, _) & V3(title,review)

Cleaning
Check validity of unfolded queries
Querying of Distributed Data
Sources
ESD 2004 29
review
Query propagation in P2P
Problem
Choosing node(s) to submit query
and node(s) to propagate query
Solution
Structured
using index
Unstructured, pure decentralized
flooding technique, TTL
Partial centralized
Super-Peer as coordinator
Querying of Distributed Data
Sources
ESD 2004 30
Q
A
B
R
D
C
Send to
???
Send to
???
ESD 2004
Tuyet-Trinh Vu
16
Characteristics
Heterogeneity
model, semantic, capacity,
Distribution
communication environment (ex: Internet)
Autonomy
availability of knowledge (ex: statistics)
availability of data (ex: available source)
Querying of Distributed Data
Sources
ESD 2004 31
What is wrong in static query
processing ?
Statistics for query optimization
inaccurate even unknown
Processing: optimization and then execution
inefficient even impossible
Need to
correct the imprecision, learn the unknown
react to the unexpectedness
Querying of Distributed Data
Sources
ESD 2004 32
ESD 2004
Tuyet-Trinh Vu
17
Overview of adaptive query processing
Adaptive query processing [HFC+00]
receiving information from its environment
using this information to determine its behaviors
iterating the two above in a feedback loop
Levels of adaptation
Operators algorithms: adaptive operators
Operators order: re-scheduling
Structure of plan: re-optimizing
Querying of Distributed Data
Sources
ESD 2004 33
Adaptive operator (1)
RippleJoin [HH99]
extension of NLJ
determining
moments of
symmetry
dealing with
fluctuant arrival
data rate
Querying of Distributed Data
Sources
ESD 2004 34
SOURCE
S
SOURCE
R
Tuple R
Tuple R
Tuple S
Matching
Relation S
ESD 2004
Tuyet-Trinh Vu
18
Adaptive operator (1)
RippleJoin [HH99]
extension of NLJ
determining
moments of
symmetry
dealing with
fluctuant arrival
data rate
Querying of Distributed Data
Sources
ESD 2004 35
SOURCE
S
SOURCE
R
Tuple R
Tuple S
Tuple S
Matching
Relation S
Adaptive operator (2)
Symmetric Hash Join
(SHJ) [WA91]
extension of HJ
using 2 hash tables
dealing with
fluctuant arrival
data rate
Querying of Distributed Data
Sources
ESD 2004 36
SOURCE
S
SOURCE
R
Tuple R Tuple S
Hash Table S
1 n
Hash Table R

1 n
Matching
hash(Tuple S)
hash(Tuple R)

build build
probe
ESD 2004
Tuyet-Trinh Vu
19
Adaptive operator (2)
Symmetric Hash Join
(SHJ) [WA91]
extension of HJ
using 2 hash tables
dealing with
fluctuant arrival
data rate
Querying of Distributed Data
Sources
ESD 2004 37
SOURCE
S
SOURCE
R
Tuple R Tuple S
Hash Table S
1 n
Hash Table R

1 n
Matching
hash(Tuple S)
hash(Tuple R)

build build
probe
Adaptive operator (3)
XJoin [UF98s]
extension of SHJ
storing a part of HTs
to disk
dealing with
fluctuant arrival
data rate and
Insufficient memory
3 phases of joint
mem mem
mem disk
cleaning
Querying of Distributed Data
Sources
ESD 2004 38
D I S K
Tuple S
hash(Tuple S)
= n
SOURCE
S
f
l
u
s
h
D partitions S D partitions R
SOURCE
R
M

E

M

O

R

Y
M partitions S
. . . . . .
k 1 n
M partitions R
. .. . . .
1 n
. . .
n 1
. . . . . .
1 k n
Tuple R
hash(Tuple R)
= 1
ESD 2004
Tuyet-Trinh Vu
20
Dynamic query plan[GW89, CG94]
Problem
parameterized queries
lack of knowledge at
compilation time
Solution
combining different
alternatives
Choose-Plan operator
decides an alternative at
starting query execution
Querying of Distributed Data
Sources
ESD 2004 39
Choose-Plan
Filter
File-Scan R
Filter
B-tree Scan R.A
Choose-Plan
HashJoin HashJoin
File-Scan S
Mid-query re-optimization [KD98]
Problem
inaccurate or unknown
statistics
Solution
collecting statistics at
mid-query
a Static-Collector
operator to
collect statistics on data
materialize intermediate
results
Querying of Distributed Data
Sources
ESD 2004 40
Average
Indexed-Join
Hash-Join T
Filter S
R
F1 ^ F2
F3
F4
G
ESD 2004
Tuyet-Trinh Vu
21
Statistic collection
Querying of Distributed Data
Sources
ESD 2004 41
Aggregate
Indexed-Join
Hash-Join T
Filter S
R
F1, F2
F3
F4
G
Aggregate
Indexed-Join
Hash-Join T
Filter
S
R
F1, F2
F3
F4
G
Statistic Collector
Histogram: R.joinattr3
Unique values: R.groupattr
Materialization
Querying of Distributed Data
Sources
ESD 2004 42
Hash-Join
Filter
S
R
F1, F2
F3
Statistic Collector
Histogram: R.joinattr3
Unique values: R.groupattr
Materialize
Temp1
Select avg(Temp1.selectattr1),
avg(Temp1.selectattr2),
Temp1.groupattr
From Temp1, T
Where Temp1.joinattr3 = T.joinattr3
Group byTemp1.groupattr
Aggregate
Hash-Join
T
Temp1.joinattr3
= T.joinattr3
G
Aggregate
Indexed-Join
Hash-Join T
Filter
S
R
F1, F2
F3
F4
G
Statistic Coll.
Histogram: Rel1.joinattr3
Unique values: Rel.groupattr
ESD 2004
Tuyet-Trinh Vu
22
Query scrambling [UFA98]
Problem
network delays
Solution
hiding delayed sources
running non-blocked
operators
2 phases
rescheduling
operators synthesis
43
R1 R2 R4 R5
R3
1 2
3
4
5
6
Phase 1: Rescheduling
Principle
running sub-tree that is independent from
delayed sources or blocked operators
(non-blocked sub-tree)
materializing intermediate results
Process
processing a non-blocked sub-tree
if return of delayed sources, continuing
otherwise, processing other non-blocked
sub-tree
if no sub-tree for processing
phase 2
Querying of Distributed Data
Sources
ESD 2004 44
R
4
R
5
R
2
R
1
R
3
1
2
4
3
5
6
R
4
R
5
R
2
R
1
R
3
?
1
2
?
3
?
rescheduling
ESD 2004
Tuyet-Trinh Vu
23
Phase 2: Operator synthesis
Principle
combining materialized data through
new join operators
Process
generating new join operator for
materialized intermediate result
if delay is left, continuing
otherwise, generating other
operators for new materialized data
if nothing to do, waiting data
Querying of Distributed Data
Sources
ESD 2004 45
Reordering
join
R
4
R
5
R
2
R
1
R
3
?
1
2
3
4
?
R
4
R
5
R
2
R
1
R
3
?
1
2
?
3
?
Eddy [AH00]
Problem
Run-time fluctuations:
cost, selectivity, rate
Solution
per-tuple operator
reordering
Eddy: routing tuples
between operators
(modules)
no query plan
but Eddy & modules
Querying of Distributed Data
Sources
ESD 2004 46
R S T
RS
ST
RST
?
Eddy
ESD 2004
Tuyet-Trinh Vu
24
Eddy: easily routing ?
Querying of Distributed Data
Sources
ESD 2004 47
Necessary properties of operator algorithms
Synchronization barrier
one input relation frozen, waiting for the other.
adaptive or non existent synchronization
barriers
Moment of symmetry
points enabling to interchange the order of relations
without affecting the output.
frequent moments of symmetry
Routing
Principle: favors the production of result tuples
2 policies: Nave vs. Fast
Eddy: tuple structure
Eddys tuple = tuple + READY + DONE
Routing is based on Ready vector value
48
1 1 0 0
op1 op2 op1 op2
Ready Bits Done Bits
Tuple
ESD 2004
Tuyet-Trinh Vu
25
Nave Eddy
Querying of Distributed Data
Sources
ESD 2004 49
select *
from R
where s1() and s2()
Static query execution
either s1() before s2()
or s2() before s1()
Statistics
50% selectivity
Cost(s2) = 5 sec & Cost(s1) = {1..9} sec.
Nave Eddy routing policy:
all operators fetch from Eddy as fast as possible
previously-seen tuples precede new tuples
Fast Eddy
Loop:
Given a tuple
Determine which operators are
eligible to process tuple
If more than 1 operator, hold a
lottery with chance of
winning proportional to
# tickets
Operator gets 1 ticket if it
gets a tuple
Operator loses 1 ticket if it
returns a tuple
Until every tuple can no longer
be processed by any operator
Querying of Distributed Data Sources ESD 2004 50
B
A
# tickets Operator
# tickets tracks efficiency
of an operator in dropping
tuples from system
The system learns ordering of the operators
ESD 2004
Tuyet-Trinh Vu
26
Part 2: Querying distributed data sources
-Characteristics of distributed data systems
(DDS)
-Dispatching query
-Adaptive query evaluation (AQP)
Interactive query evaluation (IQP)
Querying of Distributed Data
Sources
ESD 2004 51
What is inappropriate in DB query
processing ?
DB queries : what (data) I want
(may be) so large and not appropriate
Batch processing: wait for a query to complete
long even interminable
Need to
enable client controls
return feedbacks
Querying of Distributed Data
Sources
ESD 2004 52
ESD 2004
Tuyet-Trinh Vu
27
Overview of interactive query
processing
Interactive query processing
partial query results (as feedback)
dynamic user control during query execution
adaptive query execution
interactive transformation
Mechanisms of IQP
building partial results
considering client interests (preference or profile)
adapting changes of client interests
Querying of Distributed Data
Sources
ESD 2004 53
Building partial results
Problem
unavailable data
client preference on some
data
Overview of solutions
returning incomplete
results
routing data to client
according to client interest
Querying of Distributed Data
Sources
ESD 2004 54
SOURCE
S
SOURCE
R
SOURCE
T
ESD 2004
Tuyet-Trinh Vu
28
Disco [BT98]
Context:
mediation system
unavailable data source
Solution: return available
data
rewriting queries
materializing available
data
Querying of Distributed Data Sources ESD 2004 55
Optimizer
Sense
Execution
Engine
Materialize
Construct
Query
all sources
are available
at least one source
is unavailable
Answer
incremental
query
Partial results in DISCO
Some definitions
parachute query
~ executable fragment of the plan
incremental query
~ query expressed on results of parachute query(ies) & data
source(s)
partial response
~ materialized results of parachute query & incremental
query
Process
Cdetecting unavailable source
Cexecuting parachute query(ies)
Cmaterializing results of parachute query(ies)
Cgenerating incremental query(ies)
Creturning partial response
Querying of Distributed Data
Sources
ESD 2004 56
ESD 2004
Tuyet-Trinh Vu
29
Example
select x.name
from x in R, y in S, z in T
where x.name = y.name and y.name = z.name
Note: T is not available!!!
parachute query
select x.name
from x in R, y in S
where x.name = y.name
Note: results are materialized in tmp!!!
incremental query
select w.name
from w in tmp, z in person2
where w.name = z.name
Querying of Distributed Data
Sources
ESD 2004 57
Juggle[RRH99]
Context
online query processing, i.e.
users perceive data being
processed over time
user interests as preferences
Solution: prioritize processing
for interesting tuples based on
user-specified preferences
Prefetch & Spool (P&S)
reorder
Querying of Distributed Data
Sources
ESD 2004 58
S
T
R
S
T
R
reorder
ESD 2004
Tuyet-Trinh Vu
30
P&S technique
Querying of Distributed Data
Sources
ESD 2004 59
prefetch from input, spools onto
auxiliary side disk if needed
juggle data between buffer and
side disk, to keep buffer full of
interesting items
getNext chooses best item
currently on buffer
reordering policy: determines
what getNext returns,
enrich/spool decisions
JuggleEddy[RH02]
Context
unavailable data
client preference (may be
changed during QE)
spreadsheet display client
application
Solution: return continually
results to client
based on hash client
defining key columns
routing tuples
Querying of Distributed Data Sources ESD 2004 60
ESD 2004
Tuyet-Trinh Vu
31
Partial results in JuggleEddy
Some definitions
partial result
~any tuple produced by QP
intermediate result
~incomplete result displayed at client
key column
~ set of columns allowing to identify an unique
result tuple
column properties (CPs)
row properties (RPs)
row column properties (RCPs)
benefit of a partial result tuple
Benefit(cell[r,c]) = RP(c)*CP(c)*RCP(r,c)
a1 a2 name a4 a5
Querying of Distributed Data Sources ESD 2004 61
R S T
RS
ST
JuggleEddy
RP
CP

Você também pode gostar