Docsity

Distributed Queries-Distributed Database-Lecture 07 Slides-Computer Science, Appunti di Basi di Dati

Anteprima parziale del testo

Scarica Distributed Queries-Distributed Database-Lecture 07 Slides-Computer Science e più Appunti in PDF di Basi di Dati solo su Docsity!

Chapter 7: Optimization of Distributed

Queries

Basic Concepts

Distributed Cost Model

Database Statistics

Joins and Semijoins

Query Optimization Algorithms

Acknowledgements:

I am indebted to Arturas Mazeika for providing me his slides of this course.

J. Gamper

Basic Concepts

Query optimization:

Process of producing an op-

represents an execution strategy for the querytimal (close to optimal) query execution plan which

-

sider different orderings of the operationsThe main task in query optimization is to con-

Centralized query optimization:

-

space of equivalent query treesFind (the best) query execution plan in the

-

Minimize an objective cost function

-

Gather statistics about relations

Distributed query optimization brings additional issues

-

Linear query trees are not necessarily a good choice

-

Bushy query trees are not necessarily a bad choice

-

What and where to ship the relations

-

How to ship relations (ship as a whole, ship as needed)

-

When to use semi-joins instead of joins

J. Gamper

Basic Concepts...

Reduction

of the search space

-

∗ Restrict by means of heuristics

Perform unary operations before binary operations, etc

-

∗ Restrict the shape of the join tree

Consider the type of trees (linear trees, vs. bushy ones)

Linear Join Tree

Bushy Join Tree

J. Gamper

Basic Concepts...

There are two main strategies to

scan the search space

-

Deterministic

-

Randomized

Deterministic scan

of the search space

-

Start from base relations and build plans by adding one relation at each step

-

(dynamic programming approach)Breadth-first strategy: build all possible plans before choosing the “best” plan

-

Depth-first strategy: build only one plan (greedy approach)

J. Gamper

Distributed Cost Model

Two different types of

cost functions

can be used

-

Reduce

total time

cost component as possibleReduce each cost component (in terms of time) individually, i.e., do as little for each

Optimize the utilization of the resources (i.e., increase system throughput)

-

Reduce

response time

Do as many things in parallel as possible

May increase total time because of increased total activity

J. Gamper

Distributed Cost Model...

Total time

: Sum of the time of all individual components

-

Local processing time: CPU time + I/O time

-

Communication time: fixed time to initiate a message + time to transmit the data

Total

time

T

CPU

instructions

T

I (^) / O

I

Os

T

MSG

messages

T

TR

bytes

The individual components of the total cost have different weights:

-

∗ Wide area network

Message initiation and transmission costs are high

Local processing cost is low (fast mainframes or minicomputers)

Ratio of communication to I/O costs is 20:

-

∗ Local area networks

Communication and local processing costs are more or less equal

Ratio of communication to I/O costs is 1:1.6 (10MB/s network)

J. Gamper

Distributed Cost Model...

Example:

Query at site 3 with data from sites 1 and 2.

-

Assume that only the communication cost is considered

-

Total

time

T

MSG

T

TR

∗ ( x + y )

-

Response

time

= max

T

MSG

T

TR

x, T

MSG

T

TR

y }

J. Gamper

Database Statistics

The

primary cost factor

is the

size of intermediate relations

-

that are produced during the execution and

-

different sitemust be transmitted over the network, if a subsequent operation is located on a

It is costly to compute the size of the intermediate relations precisely.

Instead

global statistics of relations and fragments

are computed and used to

provide approximations

J. Gamper

Database Statistics...

Selectivity factor

of an operation: the proportion of tuples of an operand relation that

participate in the result of that operation

Assumption: independent attributes and uniform distribution of attribute values

Selectivity factor of selection

SF

σ ( A

value

card

A

( R

))

SF

σ ( A > value

max(

A

value

max(

A

min(

A

SF

σ ( A < value

value

min(

A

max(

A

min(

A

SF Properties of the selectivity factor of the selection

σ ( p ( A i ) ∧ p ( A j

SF

σ ( p ( A i

SF

σ ( p ( A j

SF

σ ( p ( A i ) ∨ p ( A j

SF

σ ( p ( A i

SF

σ ( p ( A j

SF

σ ( p ( A i

SF

σ ( p ( A j

SF

σ ( A

values

SF

σ ( A

value

card

values

J. Gamper

Page 13

Database Statistics...

Cardinality

of intermediate results

-

Selection

card

σ P (^) ( R

)) =

SF

σ ( P

(^) )

∗

card

R

-

∗ Projection

More difficult: duplicates, correlations between projected attributes are unknown

Simple if the projected attribute is a key

card

A

( R

)) =

card

R

-

Cartesian Product

card

R

×

S

card

R

card

S

-

∗ Union

upper bound:

card

( R ∪ S ) ≤

card

R

card

S

lower bound:

card

( R ∪ S ) ≥

max

card

R

, card

S

-

∗ Set Difference

upper bound:

card

R

S

card

R

lower bound:

J. Gamper

Database Statistics...

Selectivity factor

for semijoins: fraction of R-tuples that join with S-tuples

-

An approximation is the selectivity of

A

in

S

SF

⊲ < ( R ⊲ < A S

SF

⊲ <

( S.A

card

A

( S

))

card

dom

[

A

])

Cardinality

of semijoin (general case):

card

( R ⊲ < A S

SF

⊲ <

( S.A

card

R

Example:

R.A

is a foreign key in

S

( S.A

is a primary key)

Then

SF

and the result size corresponds to the size of

R

J. Gamper

Join Ordering in Fragment Queries

Join ordering

is an important aspect in centralized DBMS, and it

is even more

important in a DDBMS

since joins between fragments that are stored at different sites

may increase the communication time.

Two approaches exist:

-

∗ Optimize the ordering of joins directly

INGRES and distributed INGRES

System

R

and System

R

∗

-

∗ costsReplace joins by combinations of semijoins in order to minimize the communication

Hill Climbing and SDD-

J. Gamper

Join Ordering in Fragment Queries...

Direct join ordering

of queries involving more than two relations is substantially more

complex

Example:

Consider the following query and the respective join graph, where we make

also assumptions about the locations of the three relations/fragments

P ROJ

P N O

ASG

EN O

EM P

J. Gamper

Join Ordering in Fragment Queries...

Example (contd.):

The query can be evaluated in at least 5 different ways.

-

Plan 1:

EMP

→

Site 2

Site 2: EMP’=EMP

⋊⋉

ASG

EMP’

→

Site 3

Site 3: EMP’

⋊⋉

PROJ

-

Plan 2:

ASG

→

Site 1

Site 1: EMP’=EMP

⋊⋉

ASG

EMP’

→

Site 3

Site 3: EMP’

⋊⋉

PROJ

-

Plan 3:

ASG

→

Site 3

Site 3: ASG’=ASG

⋊⋉

PROJ

ASG’

→

Site 1

Site 1: ASG’

⋊⋉

EMP

-

Plan 4:

PROJ

→

Site 2

Site 2: PROJ’=PROJ

⋊⋉

ASG

PROJ’

→

Site 1

Site 1: PROJ’

⋊⋉

EMP

-

Plan 5:

EMP

→

Site 2

PROJ

→

Site 2

Site 2: EMP

⋊⋉

PROJ

⋊⋉

ASG

To select a plan, a lot of information is needed, including

-

size

( EM P

(^) ) , size

( ASG

) , size

( P ROJ

) , size

( EM P

⋊⋉

ASG

) ,

size

( ASG

⋊⋉

P ROJ

)

-

Possibilities of parallel execution if response time is used

J. Gamper