Presentation is loading. Please wait.

Presentation is loading. Please wait.

QueryRewriting: 1 Query Rewriting (for Query “Optimization”) Main Strategy: Make intermediate results small by applying selection and projection early.

Similar presentations


Presentation on theme: "QueryRewriting: 1 Query Rewriting (for Query “Optimization”) Main Strategy: Make intermediate results small by applying selection and projection early."— Presentation transcript:

1 QueryRewriting: 1 Query Rewriting (for Query “Optimization”) Main Strategy: Make intermediate results small by applying selection and projection early. Additional Strategies: Remove unnecessary operations, execute common subexpressions only once, re-order joins to generate smaller intermediate results, …

2 QueryRewriting: 2 Rewriting Rules 1 & 2 1.  X e = e Note: the scheme of e is X.  RoomNr, Name, NrBeds, Cost r = r 2.  X  f e =  X  f  XY e Note: f mentions the attrs. of Y.  RoomNr, Name  Cost > 75 r =  RoomNr, Name  Cost > 75  RoomNr, Name, Cost r

3 QueryRewriting: 3 Rewriting Rules 3 & 4 3.  f (e 1 |  | e 2 ) =  f1 (  f2 e 1 |  |  f3 e 2 ) Note: f = f1  f2  f3; each pertains to its respective expression.  ArrivalDate = 15 May  City = Boston (g |  | s) =  City = Boston g |  |  ArrivalDate = 15 May s 4.  X (e 1 |  | e 2 ) =  X (  X 1 Y e 1 |  |  X2Y e 2 ) Note: X1 = X  scheme(e 1 ), X2 = X  scheme(e 2 ), and Y = (scheme(e 1 )  scheme(e 2 )) – X.  RoomNr (r |  | g) =  RoomNr (  RoomNr, Name r |  |  Name g)

4 QueryRewriting: 4 Rewriting Rules 5 & 6 5.  X  Y e =  X e  Name  RoomNr, Name r =  Name r 6.  f1  f2 e =  f1  f2 e  NrBeds = 2  Cost = 80 r =  NrBeds = 2  Cost = 80 r

5 QueryRewriting: 5 Rewriting Rules 7, 8 & 9 Natural join (|  |) is (7) commutative, (8) associative, and (9) idempotent. (r |  | (g |  | s)) |  | r = 8 r |  | g |  | s |  | r = 7 r |  | r |  | g |  | s = 9 r |  | g |  | s

6 QueryRewriting: 6 Query Rewriting – Example  Name, StreetNr, City  ArrivalDate = 10 May  NrBeds = 2 (r |  | g |  | s) = 6,8,3  Name, StreetNr, City (  NrBeds = 2 r |  | g |  |  ArrivalDate = 10 May s) = 8,4  Name, StreetNr, City (  RoomNr, Name  NrBeds = 2 r |  |  GuestNr, Name, StreetNr, City g |  |  GuestNr, RoomNr  ArrivalDate = 10 May s) = 1  Name, StreetNr, City (  RoomNr, Name  NrBeds = 2 r |  | g |  |  GuestNr, RoomNr  ArrivalDate = 10 May s)


Download ppt "QueryRewriting: 1 Query Rewriting (for Query “Optimization”) Main Strategy: Make intermediate results small by applying selection and projection early."

Similar presentations


Ads by Google