chapter 21 parallel databases

26
Advanced DB CHAPTER 21 PARALLEL DATABASES

Upload: khangminh22

Post on 22-Nov-2023

1 views

Category:

Documents


0 download

TRANSCRIPT

Advanced DB

CHAPTER 21PARALLEL DATABASES

Chapter 21: Parallel Databases

IntroductionI/O ParallelismInterquery Parallelismq yIntraquery ParallelismI tr p r ti P r ll liIntraoperation ParallelismInteroperation ParallelismDesign of Parallel Systems

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 2

Introduction

Parallel machines are becoming quite common and affordableP i f i d di k h d d h lPrices of microprocessors, memory and disks have dropped sharply

Databases are growing increasingly largelarge vol mes of transaction data are collected and stored for later analysislarge volumes of transaction data are collected and stored for later analysis (eg. data warehouses)multimedia objects like images are increasingly stored in databasesdemand for high throughput transaction systems are common

Databases naturally lend themselves to parallelismData can be partitioned across multiple disks for parallel I/O.Individual relational operations (e.g., sort, join, aggregation) can be executed in parallelexecuted in parallelQueries are expressed in high level languageDifferent queries can be run in parallel with each other

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 3

Concurrency control takes care of conflicts

Exploiting Parallelism

I/O ParallelismInterquery Parallelism

e.g., assign one query to each node

I t P ll liIntraquery ParallelismOne query is processed by multiple nodes

Inter-operation ParallelismpBreakup query into subqueries (operations)Assign each operation to a node

I i P ll liIntra-operation ParallelismUtilize multiple nodes to execute one operationParallel join, parallel sort, etc.j , p ,

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 4

I/O Parallelism

Reduce the time required to retrieve relations from disk by partitioning the relations on multiple diskspartitioning the relations on multiple disks.Horizontal partitioning used mainlyPartitioning techniquesPartitioning techniques

Round-robinHash partitioningRange partitioning

Evaluate how well each technique supports different types of data accessdata access

Table scan: scanning the entire relationPoint queries: locating a tuple associatively: e.g., r.A = 25.Range queries: locating all tuples attribute value lies within a specified range: e.g., 10 ≤ r.A < 25.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 5

Round-robin

MethodS d th ith t l i t d i th l ti t di k (i d )Send the ith tuple inserted in the relation to disk (i mod n)

AdvantagesBest suited for sequential scan of entire relation on each queryBest suited for sequential scan of entire relation on each queryAll disks have almost an equal number of tuples; retrieval work is thus well balanced between disks.

Range queries are difficult to processNo clustering - tuples are scattered across all disks

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 6

Hash Partitioning

Method 1 Choose one or more attributes as the partitioning attributes (say A)1. Choose one or more attributes as the partitioning attributes (say, A) 2. Choose hash function h with range 0…n - 13. Send tuple to disk h(t[A])

Good for sequential access If partitioning attribute is a key and hash function is good=> tuples will be equally distributed between disks=> tuples will be equally distributed between disksRetrieval work is then well balanced between disks.

Good for point queries on partitioning attributeCan locate correct disk Index on partitioning attribute can be local to disk=> making lookup and update more efficient> making lookup and update more efficient

No clustering, so difficult to answer range queries

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 7

Range Partitioning

Method 1 Choose an attribute as the partitioning attribute (say A)1. Choose an attribute as the partitioning attribute (say, A)2. A partitioning vector [vo, v1, ..., vn-2] is chosen, for vi ≤ vi+1

3. If t[A] is between vi and vi+1 , t goes to disk i + 1If t[A] < v0 , t goes to disk 0 if t[A] ≥ vn-2, t goes to disk n-1.

Good for sequential accessGood for sequential accessGood for point queries on partitioning attribute: only one disk needs to be accessed.Provides data clustering by partitioning attribute value

For range queries on partitioning attribute, only a few disks may need to be accessedaccessedIf many blocks are to be fetched, they are still fetched from one to a few disks, and potential parallelism in disk access is wasted

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 8

Data Skew

Distribution of tuples to disks may be skeweddi k h l hil h h f lsome disks have many tuples, while others may have fewer tuples

Types of skew:Attrib te val e skewAttribute-value skew

Some values appear in the partitioning attributes of many tuplesall tuples with same value for the partitioning attribute end up in the same partitioncan occur with range-partitioning and hash-partitioning.

Partition skewPartition skewWith range-partitioning, badly chosen partition vector may assign too many tuples to some partitions and too few to others.L lik l ith h h p rtiti nin if d h h f n ti n i h nLess likely with hash-partitioning if a good hash-function is chosen.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 9

Interquery Parallelism

Queries/transactions execute in parallel with one anotherIncreases transaction throughput

used primarily to scale up a transaction processing system

E i f f ll liEasiest form of parallelismparticularly in a shared-memory parallel databasesimilar to concurrent processing in a sequential database systemsimilar to concurrent processing in a sequential database system

More complicated on shared-disk or shared-nothing architecturesLocking and logging must be coordinated by passing messages betweenLocking and logging must be coordinated by passing messages between processorsData in a local buffer may have been updated at another processorCache-coherency has to be maintained — reads and writes of data in buffer must find latest version of data.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 10

Intraquery Parallelism

Execution of a single query in parallel on multiple processors/disksprocessors/disks

important for speeding up long-running queries.

Two complementary forms of intraquery parallelism :Two complementary forms of intraquery parallelism :Interoperation Parallelism – execute the different operations in a query expression in parallelIntraoperation Parallelism – parallelize the execution of each individual operation in the query

scales better with increasing parallelism becausescales better with increasing parallelism becausethe number of tuples processed by each operation is typically more than the number of operations in a query

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 11

Intraoperation parallelism

Parallel processing of relational operatorsWe assume:

read-only queriesshared nothing architect reshared-nothing architecturen processors, P0, ..., Pn-1, and n disks D0, ..., Dn-1, where disk Di is associated with processor Pi

Shared-nothing architectures can be efficiently simulated on shared-memory and shared-disk systems.

Algorithms for shared-nothing systems can be run on shared-memory and shared-disk systemssome optimizations may be possiblesome optimizations may be possible

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 12

Range-Partitioning Sort

Choose m (≤ n –1) processors P0, ..., Pm for sortingCre te r nge p rtition e tor ith entries on the sorting ttrib te(s)Create range-partition vector with m entries, on the sorting attribute(s)Redistribute the relation using range partitioning

all tuples in the ith range are sent to processor Pip g p i

Pi stores the tuples temporarily on disk Di. This step requires I/O and communication overhead.

h P i i i f h l i l llEach Pi sorts its partition of the relation locallyEach processor executes same operation (sort) in parallel with other processors, without any interaction with the others

Final merge operationis trivial (concatenation)

i i i h f 1≤ j ≤ k l i P ll l h hrange-partitioning ensures that, for 1≤ j ≤m, key values in Pj-1 are all less than the key values in Pj.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 13

Parallel External Sort Merge

Assume the relation is partitioned among disks D0, ..., Dn-1il knot necessarily on sort key

Each processor Pi locally sorts the data on disk Di.Th d h h d hThe sorted runs on each processor are then merged to get the final sorted output.P ll li tiParallelize merge operation:

The sorted runs at each processor are range-partitioned across the processors P0, ..., Pm-1.p 0, , m 1

Each processor performs a merge on the streams as they are receivedThe sorted runs are concatenated to get the final result

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 14

Parallel Join

The join operationi f l d b d if h i f h j i di ipairs of tuples need to be tested to see if they satisfy the join condition

if they do, the pair is added to the join output

Parallel join algorithmsParallel join algorithmssplit the pairs to be tested over several processorseach processor then computes part of the join locallyp p p j y

In a final stepthe results from each processor can be collected together to produce the p g pfinal result

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 15

Partitioned Join

For equi-joinspartition the two input relations across thepartition the two input relations across the processorsand compute the join locally at each processor

S ⋈Suppose we want to compute r ⋈r.A=s.B sr and s each are partitioned into n partitions

denoted r0 r1 ... r 1 and s0 s1 ... s 1.denoted r0, r1, ..., rn-1 and s0, s1, ..., sn-1.Can use either range partitioning or hash partitioning.must be partitioned on join attributes r.A and s.B

fusing the same range-part. vector or hash func.

Partitions ri and si are sent to processor Pi

Each Pi locally computes ri ⋈ i A i B siEach Pi locally computes ri ⋈ri.A=si.B si

Any of the standard join methods can be used.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 16

Fragment-and-Replicate Join

Partitioned Join is not possible for non-equijoin conditions A > Be.g., r.A > s.B

Fragment and ReplicatePartition r into n partitions s into m partitionsPartition r into n partitions, s into m partitionsSent to m*n processors

Special case – asymmetric fragment-and-replicateSpecial case asymmetric fragment and replicatem=1 (or n=1).Processor Pi locally computes the join of ri with all of s using any join technique

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 17

Fragment-and-Replicate Join (cont.)

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 18

Fragment-and-Replicate Join (cont.)

Partition r and s: any partitioning technique may be usedi i i d i i ir is partitioned into n partitions: r0, r1, ..., r n-1

s is partitioned into m partitions: s0, s1, ..., sm-1

There must be at least m * n processorsThere must be at least m * n processorsLabel the processors as P0,0, P0,1, ..., P0,m-1, P1,0, ..., Pn-1,m-1

Pi j computes ri ⋈ sji,j p i jri is replicated to Pi,0, Pi,1, ..., Pi,m-1si is replicated to P0,i, P1,i, ..., Pn-1,i

A j i h i b d h PAny join technique can be used at each processor Pi,j.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 19

Fragment-and-Replicate Join (cont.)

Works with any join condition (general or asymmetric)i l i b d i h l isince every tuple in r can be tested with every tuple in s.

Usually has a higher cost than partitioningsince one of the relations (for asymmetric fragment and replicate) or bothsince one of the relations (for asymmetric fragment-and-replicate) or both relations (for general fragment-and-replicate) have to be replicated

Sometimes asymmetric fragment-and-replicate is preferable over y g p ppartitioned join.

e.g., say s is small and r is large, and already partitioned.It may be cheaper to replicate s across all processors,rather than repartition r and s on the join attributes.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 20

Other Relational Operations

Selection: σθ(r)If θ is ai = v where ai is an attribute and v a valueIf θ is ai = v, where ai is an attribute and v a value

if r is partitioned on ai

the selection is performed at a single processor.If θ i f th f l < < (i θ i l ti )If θ is of the form l <= ai <= u (i.e., θ is a range selection)

if r has been range-partitioned on aithen selection is performed at each processor whose partition overlaps with the specified range of al esrange of values.

In all other cases: the selection is performed in parallel at all the processors.

Duplicate eliminationPerform by using either of the parallel sort techniques

eliminate duplicates as soon as they are found during sorting.Can also partition the tuples (using either range- or hash- partitioning) and performCan also partition the tuples (using either range or hash partitioning) and perform duplicate elimination locally at each processor.

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 21

Cost of Parallel Evaluation of Operations

Ideally, without skew or overhead, expected speed-up will be n(r ntime 1/n)(runtime: 1/n)Actual parallel operation time can be estimated as

Tpart + Tasm + max (T0, T1, …, Tn-1)

Tpart is the time for partitioning the relationsTasm is the time for assembling the results

Ti is the time taken for the operation at processor Pik d i d i i b ddi i l h dskew and time wasted in contentions can be additional overhead

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 22

Interoperation Parallelism

Consider a join of four relations r1 ⋈ r2 ⋈ r3 ⋈ r4

Pipelined parallelismPipelined parallelismAssign P1 to compute temp1 = r1 ⋈ r2

P2 to compute temp2 = temp1 ⋈ r3P t mp t t p ⋈P3 to compute temp2 ⋈ r4

Each of these operations can be executed in parallelSend result tuples to the next operation as they are being generated

Requires a pipeline able join evaluation algorithm (e g indexed nested loops join)Requires a pipeline-able join evaluation algorithm (e.g. indexed nested loops join)Independent parallelism

Assign P1 to compute temp1 = r1 ⋈ r2P2 to compute temp2 = r3 ⋈ r4P3 to compute temp1 ⋈ temp2

P1 and P2 can work independently in parallelP3 has to wait for input from P1 and P2Can pipeline output of P1 and P2 to P3, combining independent parallelism and pipelined parallelism

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 23

Interoperation Parallelism (Cont.)

Pipeline parallelism is useful since it avoids writing intermediate res lts to diskresults to diskUseful with small number of processorsB d l ll i hBut does not scale up well with more processors

only a limited number of operations in a querypipeline chains do not attain sufficient lengthpipeline chains do not attain sufficient length

Cannot pipeline operators which do not produce output until all inputs have been accessed (e.g. aggregate and sort)inputs have been accessed (e.g. aggregate and sort)Little speedup in cases of skew where one operator's execution cost is much higher than the others (typical)g ( yp )

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 24

Query Optimization

Query optimization in parallel databases is significantly more complex than in sequential databases.sequential databases.Cost models are more complicated

partitioning costsskewresource contention

Optimizer must decide:Optimizer must decide:How to parallelize each operation How many processors to use

allocating more processors than optimal can result in high communication overheadWhich operations to pipeline (long pipelines should be avoided), to execute independently in parallel, or to execute sequentially one after the other

The number of “equivalent” parallel evaluation plans is much largerheuristics are needed

Original Slides:© Silberschatz, Korth and Sudarshan

Advanced DB (2008-1)Copyright © 2006 - 2008 by S.-g. Lee Chap 21 - 25

END OF CHAPTER 21