Docsity

Rate-Based Query Optimization for Streaming Information Sources | CS 410, Study notes of Computer Science

Partial preview of the text

Download Rate-Based Query Optimization for Streaming Information Sources | CS 410 and more Study notes Computer Science in PDF only on Docsity!

10/30/

Data Streams: Lecture 10

CS 410/510 Data Streams Lecture 10: Rate-Based Query Optimization for Streaming Information Sources

Kristin Tufte, David Maier

10/30/

Data Streams: Lecture 10

Optimization Review „^

Relational (Selinger-style) optimization ‰^

Minimize cost of evaluating queries ‰^

Based on cardinalities of input tables ‰^

Decisions: operator order and operator implementation

SELECT * FROM A WHERE A.a > 5 AND

A.b < 10

A.a > 5 (sel 50%) A.b < 10 (sel 10%) c = cost of performingselection on one tuple |R| is cardinality (size) of R

Cost:

c·R + c·0.1R

= c·1.1·R

Cost:^ c·|R| + c·0.5·|R|

= c·1.5·|R| (A.b < 10)

(A.a > 5)

0.

·|R|

0.

·|R|

(A.a > 5)

(A.b < 10)

|R|

|R|

10/30/

Data Streams: Lecture 10

Motivating Example – Plan 1

Time

Pro-cessed

Trans-mitted

Delay-ed

0

5

0

1

10

1

0

2

15

0

3

20

2

0

σ^2

σ^2

:Processing Ability:

same as input rate Selectivity: 0.1 (10%)

Time

Pro-cessed

Trans-mitted

Delay-ed

0

50

5

450

1

100

10

900

2

150

15

1350

3

200

20

1800

σ^1

Incoming Rate: 500inputs/second σ^1

:Processing Ability:

50 inputs/second Selectivity: 0.1 (10%)

Figure courtesy: Rate-basedOptimization, Viglas & Naughton,SIGMOD

10/30/

Data Streams: Lecture 10

Motivating Example – Plan 2

Time

Pro-cessed

Trans-mitted

Delay-ed

0

50

5

0

1

100

10

0

2

150

15

0

3

200

20

0

σ^1

:Processing Ability:

50 inputs/second Selectivity: 0.1 (10%)

σ^1

Time

Pro-cessed

Trans-mitted

Delay-ed

0

500

50

0

1

1000

100

0

2

1500

150

0

3

2000

200

0

σ^2

Incoming Rate: 500inputs/second σ^2

:Processing Ability:

same as input rate Selectivity: 0.1 (10%)

Figure courtesy: Rate-basedOptimization, Viglas & Naughton,SIGMOD

10/30/

Data Streams: Lecture 10

7

Let’s try cardinality-based optimization „^

|I| = input size „^

Cost: ‰^

c^1

cost per input for

σ

1

‰^

c^2

cost per input for

σ

2

‰^

Assume: c

c 1

2

„^

Selectivity ‰^

f^1

selectivity of

σ

1

‰^

f^2

selectivity of

σ

2

‰^

Assume: f

= f 1

2

„^

If |I| is infinite, cost ofboth plans is the same

|I|·

c1 + |I|·

f1·

c

|I|·

c2 + |I|·

f2·

c

σ^2

σ^1

σ^1

σ^2

I^

I

10/30/

Data Streams: Lecture 10

Let’s just pick a finite size for I

|I|·

c2 + |I|·

f2·

c

=1000·1 + 1000·0.1·5 =

„^

Choose arbitrary sizefor |I| „^

|I| = 1000

„^

Cost/Selectivity: ‰^

c^1

= 5 cost for

σ

1

‰^

c^2

= 1 cost for

σ

2

‰^

f^1

= 0.1 selectivity of

σ

1

‰^

f^2

= 0.1 selectivity of

σ

2 |I|·

c1 + |I|·

f1·

c

= 1000·5 + 1000·0.1·1 = 5100

σ^2

σ^1

σ^1

σ^2

I^

I

10/30/

Data Streams: Lecture 10

Rate-Based Optimization Approach „^

Ask “What is the expected output rate of thisquery plan?” „^

Estimate output rates of various operators asfunction of rates of their inputs „^

Output rate = (num ouputs transmitted) / (timeneeded to make transmission) „^

Types of optimizations ‰^

Maximum rate for a time period ‰^

Optimize for production of first

k tuples

„^

Let’s look at some operators…

10/30/

Data Streams: Lecture 10

Symbols and Variables „^

r^ i

  • input rate

„^

r^ o

  • output rate

„^

r^ l

  • rate of left input to a join

„^

r^ r

rate of right input to a join

„^

C

Π^

  • Cost of a projection

„^

C

σ^

  • Cost of a selection

„^

C

  • Cost of handling ‘tuple’ from left input of joinl

„^

C

r^

  • Cost of handling ‘tuple’ from right input of join „^

T – Cost of transmitting a tuple

10/30/

Data Streams: Lecture 10

Selection

„^

Assuming selection is“fast” ‰^

Output_rate =selectivity·input_rate ‰^

i.e. 0.1·500 tuples/sec =50 tuples/sec ‰^

r^ o

= f·r

i

‰^

f is selectivity

„^

C

σ^

is cost of selection ‰^

If C

< 1/ rσ

, ri,^

o^

= f·r

i

‰^

If C

1/ rσ

, ri,^

o^

= f/C

σ

Output Rate

:

50 tuples/sec

ro σ

Sel = 10% (0.1)^ Input Rate

:

500 tuples/sec

ri

50 = (0.1)·(500)

10/30/

Data Streams: Lecture 10

Joins „^

More complex because we have two inputs „^

Will derive: for a time interval t, what is theoutput rate for tuples that arrived during t? ‰^

Ex. What is the output rate for tuples that arrivedduring the period 1:35-1:36?

„^

Recall: output rate =

(num ouputs transmitted) /

(time needed to make transmission) „^

Need: ‰^

num outputs generated (transmittted) by arrivals in t ‰^

time needed to make transmission

10/30/

Data Streams: Lecture 10

More specifically… „^

Consider results generated by arrivals in one timeunit ‰^

i.e. one second if the units of t are seconds

„^

Num results = (r

·t)·(rl

·t)·f = rr^

·rl^

·f (t=1)r^

„^

f is “selectivity” of join (with reference to thecross product) „^

r^ l

= 500 tuples/sec ‰^

r^ l

= 500 tuples

„^

r^ r

= 50 tuples/sec ‰^

r^ r

= 50 tuples

ro

= 50·500·1% =250 tuples^ f = 1%

rr

= 50 tuples

rl^

= 500 tuples

10/30/

Data Streams: Lecture 10

17

Join Output Rate: Next time interval(num outputs) „^

Contribution from left side: f·r

·2·rl^

r

‰^

t objects read from left, 2t read from right ‰^

f·(r

t)·(2·rl·

·t)r^

„^

Contribution from right side: f·2·r

·rl^

r

„^

Num outputs generated during 2

nd

time unit:

(f·r

·2·rl^

)·(f·2·rr^

·rl

)- rr^

·rl^

·f = f·rr^

·rl^

+3f·rr^

·rl^

r

„^

rd

time unit: f·r

·rl^

+3f·rr^

·rl^

+5f·rr^

·rl^

r^

t^

t2 t inner(R)

outer(L)

10/30/

Data Streams: Lecture 10

Output Rate for Join „^

Output Rate: ‰^

(num ouputs transmitted) / (time needed to maketransmission)

„^

Num outputs for tuples arriving in t ‰^

f·r

·rl^

·t·(t-1)r^

„^

Time to process arrivals in t ‰^

r^ l

·t·C

  • rl

·t·Cr^

r

„^

r^ o

= (f·r

·rl

·t·(t-1))/ (rr

·t·Cl

  • rl^

·t·Cr^

)r^

≈

f·r

·rl

·t/ (rr

·Cl

  • rl^

·Cr^

)r^

(Equation 2)

„^

Assumes (r

·t·Cl

  • rl

·t·Cr^

) > tr

10/30/

Data Streams: Lecture 10

Output Rate for Join - Comments „^

Output Rate

≈

f·r

·rl

·t/ (rr

·Cl

  • rl^

·Cr^

)r^

„^

This rate assumes (r

·t·Cl

  • rl^

·t·Cr^

) > tr^

‰^

Is this a good assumption?

„^

Output rate is dependent on cost of join „^

Look at join costs next