cse4/562 database systems - odin.cse.buffalo.edu

15
1 CSE 4/562 Database Systems Practicum 03/02/2018 (Cancelled class)

Upload: others

Post on 02-Dec-2021

0 views

Category:

Documents


0 download

TRANSCRIPT

1

CSE 4/562Database Systems

Practicum

03/02/2018(Cancelled class)

2

• If X and Y are equivalent…• And If Y is better…• Then replace all Xs with Ys.

The idea is…

3

• Is R=S ?• Is R=!A(S) ?• Is R= !A←(A-1)(S) ?• Is !A←(A+1)(R) =!A(S) ?

Equivalent Expressions

<A>1

2

2

<A> <B>2 4

3 5

3 6

R S

4

Two expressions are equivalent if they produce the same output.

But…

Equivalent Expressions

5

• Bag semantics: The same tuples (order-independent)• Set semantics: The same set of tuples (count-independent)• List semantics: The same tuples (order matters)

Equivalent Expressions

<A>1

2

2

<A>2

1

2

<A>1

2=? =?

6

Selection

!C1 ⋀ C2(R) ≡ !C1(!C2(R)) (Decomposable)

!C1 ⋁ C2(R) ≡ %( !C1(R) ⋃ !C2(R) ) (Decomposable)

!C1(!C2(R)) ≡ !C2(!C1(R)) (Commutative)

RA Equivalencies

7

Projection

!a(R) ≡ !a(!a⋃b(R)) (Idempotent)

RA Equivalencies

8

Cross Product and Join

R ⨉ (S ⨉ T) ≡ (R ⨉ S) ⨉ T (Associative)

(R ⨉ S) ≡ (S ⨉ R) (Commutative)

RA Equivalencies

9

Selection commuteswith projection, but only if attribute set a and condition c are compatible.

Selection and Projection

Compatible: amust include all columns referenced by c

!a ( "C(R)) ≡ "C ( !a (R))

10

Selection combineswith Cross Product to form a join as per the definition of Join.

Join

!c(R ⨉ S) ≡R ⋈c S

11

Selection commuteswith Cross Product, but only if condition c references attributes of R exclusively.

Selection and Cross Product

!c(R ⨉ S) ≡ !c(R) ⨉ S

12

Projection commutes (distributes) over Cross Product, where a1 and a2 are the attributes in a from R and S respectively.

Projection and Cross Product

!a(R ⨉ S) ≡!a1 (R) ⨉!a2 (S)

13

Union and Intersection are commutative and associative.

Selection and Projection both commute with both Union and Intersection.

RA Equivalencies

14

Create different versions of the RA tree for this query and discuss which one is better

(S.C is uniformly distributed and ranges between 1-100)

SELECT R.A, T.EFROM R, S, T

WHERE R.B = S.BAND S.C < 5

AND S.D = T.D

Example

15

- What happens when we execute all joins first- What happens if we apply S.C < 5 on S relation first,

and then execute the joins- Which attributes do you need to read from R, S and T

SELECT R.A, T.EFROM R, S, T

WHERE R.B = S.BAND S.C < 5

AND S.D = T.D

Tips