Docsity

Query Processing-Distributed Database-Lecture 05 Slides-Computer Science, Appunti di Basi di Dati

Anteprima parziale del testo

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

Chapter 5: Overview of Query Processing

Query Processing Overview

Query Optimization

Distributed Query Processing Steps

Acknowledgements:

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

J. Gamper

Query Processing Overview

Query processing

: A 3-step process that transforms a high-level query (of relational

calculus/SQL) into an

equivalent

and

more efficient

lower-level query (of relational

algebra).

Parsing and translation

-

Check syntax and verify relations.

relational algebra expression.Translate the query into an equivalent

Optimization

-

(with lowest cost) for the query plan.Generate an optimal evaluation plan

Evaluation

-

query.plan, and returns the answers to the(optimal) evaluation plan, executes thatThe query-execution engine takes an

J. Gamper

Query Processing Example

Example:

Transformation of an SQL-query into an RA-query.

Query:Relations: EMP(ENO, ENAME, TITLE), ASG(ENO,PNO,RESP,DUR)

Find the names of employees who are managing a project

High level query

SELECT

ENAME

FROM

EMP,ASG

WHERE

EMP.ENO = ASG.ENO

AND

DUR > 37

∗ Two possible transformations of the query are:

Expression 1:

EN AM E

DU R>

37

∧

EM P.EN O

=

ASG.EN O

EM P

×

ASG

Expression 2:

EN AM E

EM P

EN O

DU R>

37

ASG

therefore typically is better.Expression 2 avoids the expensive and large intermediate Cartesian product, and

J. Gamper

Query Processing Example...

We make the following assumptions about the data fragmentation

-

∗ Data is (horizontally) fragmented:

Site1:

ASG

EN O

≤

” E

3”

ASG

Site2:

ASG

EN O>

” E

3”

ASG

Site3:

EM P

EN O

≤

” E

3”

EM P

Site4:

EM P

EN O>

” E

3”

EM P

Site5: Result

Relations ASG and EMP are fragmented in the same way

respectivelyRelations ASG and EMP are locally clustered on attributes RESP and ENO,

J. Gamper

Query Processing Example...

Calculate the cost of the two strategies under the following assumptions:

-

Tuples are uniformly distributed to the fragments; 20 tuples satisfy

DUR

size(EMP) = 400, size(ASG) = 1000

tuple access cost = 1 unit; tuple transfer cost = 10 units

ASG and EMP have a local index on DUR and ENO

Strategy 1

-

Produce ASG’s: (10+10) * tuple access cost

20

-

Transfer ASG’s to the sites of EMPs: (10+10) * tuple transfer cost

200

-

Produce EMP’s: (10+10) * tuple access cost * 2

40

-

Transfer EMP’s to result site: (10+10) * tuple transfer cost

200

-

Total cost

460

Strategy 2

-

Transfer EMP

1

, EMP

2

to site 5: 400 * tuple transfer cost

4,

-

Transfer ASG

1

, ASG

2

to site 5: 1000 * tuple transfer cost

10,

-

Select tuples from ASG

1

ASG

2 : 1000 * tuple access cost

1,

-

Join EMP and ASG’: 400 * 20 * tuple access cost

8,

-

Total cost

23,

J. Gamper

Query Optimization

Query optimization

is a crucial and difficult part of the overall query processing

Objective of query optimization is to

minimize

the following cost function:

I/O cost

CPU cost

communication cost

Two different scenarios are considered:

-

∗ Wide area networks

Communication cost dominates

low bandwidth

low speed

high protocol overhead

Most algorithms ignore all other cost components

∗ Local area networks

Communication cost not that dominant

Total cost function should be considered

J. Gamper

Query Optimization Issues

Several issues have to be considered in query optimization

Types of query optimizers

-

wrt the search techniques (exhaustive search, heuristics)

wrt the time when the query is optimized (static, dynamic)

Statistics

Decision sites

Network topology

Use of semijoins

J. Gamper

Query Optimization Issues...

Types of Query Optimizers wrt Search Techniques

-

∗ Exhaustive search

Cost-based

Optimal

Combinatorial complexity in the number of relations

∗ Heuristics

Not optimal

Regroups common sub-expressions

Performs selection, projection first

Replaces a join by a series of semijoins

Reorders operations to reduce intermediate relation size

Optimizes individual operations

J. Gamper

Query Optimization Issues...

Statistics

-

∗ Relation/fragments

Cardinality

Size of a tuple

Fraction of tuples participating in a join with another relation/fragment

∗ Attribute

Cardinality of domain

Actual number of distinct values

Distribution of attribute values (e.g., histograms)

∗ Common assumptions

Independence between different attribute values

Uniform distribution of attribute values within their domain

J. Gamper

Query Optimization Issues...

Decision sites

-

∗ Centralized

Single site determines the ”best” schedule

Simple

Knowledge about the entire distributed database is needed

∗ Distributed

Cooperation among sites to determine the schedule

Only local information is needed

Cooperation comes with an overhead cost

∗ Hybrid

One site determines the global schedule

Each site optimizes the local sub-queries

J. Gamper

Query Optimization Issues...

Use of Semijoins

-

Reduce the size of the join operands by first computing semijoins

Particularly relevant when the main cost is the communication cost

exchange between sitesImproves the processing of distributed join operations by reducing the size of data

However, the number of messages as well as local processing time is increased

J. Gamper

Distributed Query Processing Steps

J. Gamper