Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

CPSC-608 Database Systems

Παρόμοιες παρουσιάσεις


Παρουσίαση με θέμα: "CPSC-608 Database Systems"— Μεταγράφημα παρουσίασης:

1 CPSC-608 Database Systems
Fall 2018 Instructor: Jianer Chen Office: HRBB 315C Phone: Notes #16

2 parse tree-lqp convertor
Query Optimization An input database program P Prepare a collection A of efficient algorithms for operations in relational algebra; parser View processing, Semantic checking parse tree preprocessing parse tree parse tree-lqp convertor logic query plan push selections, group joins apply logic laws logic query plan reduce the size of intermediate results Optimization via logic and size logic query plan Lqp-pqp convertor take care of issues in optimization and security. physical query plan choices of algorithms, data structures, and computational modes Optimization via algorithms and cost Machine executable code

3 Improving logic plan via logic laws
Major Steps: Move selections σ so they can be applied early (σ reduces table size); Combine cross product × with selections σ to make natural joins and theta joins ( has more efficient algorithms); 3. group commutative and associative binary operations (e.g., ∩, U, ) (for later opt.); 4. May consider other operations (e.g., π, δ, τ, γ) C

4 Improving logic plan via logic laws
Major Steps: Move selections σ so they can be applied early (σ reduces table size); Combine cross product × with selections σ to make natural joins and theta joins ( has more efficient algorithms); 3. group commutative and associative binary operations (e.g., ∩, U, ) (for later opt.); 4. May consider other operations (e.g., π, δ, τ, γ) C

5 Improving logic plan via logic laws
Major Steps: Move selections σ so they can be applied early (σ reduces table size); Why is reducing table size important?

6 Improving logic plan via logic laws
Major Steps: Move selections σ so they can be applied early (σ reduces table size); Why is reducing table size important? Tables are large, the intermediate tables can be even larger, so they may have to be written back to disks. Reducing table size will save, or even avoid disk reads/writes.

7 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R))

8 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R))

9 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Take the tuples that are either in R or in S and satisfy the condition C

10 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Take the tuples that are either in R or in S and satisfy the condition C Take the tuples that are either in R and satisfy the condition C or in U and satisfy the condition C

11 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Take the tuples that are either in R or in S and satisfy the condition C Take the tuples that are either in R and satisfy the condition C or in U and satisfy the condition C

12 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) R(a,b) S(b,d) σ C σ C σ C R(a,b) S(b,d) Take the tuples that are either in R or in S and satisfy the condition C Take the tuples that are either in R and satisfy the condition C or in U and satisfy the condition C

13 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) R(a,b) S(b,d) σ C 100 100 σ C σ C R(a,b) S(b,d) 10000 20000 10000 20000 Take the tuples that are either in R or in S and satisfy the condition C Take the tuples that are either in R and satisfy the condition C or in U and satisfy the condition C

14 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) R(a,b) S(b,d) σ C 100 100 σ C σ C 25000 R(a,b) S(b,d) 10000 20000 10000 20000 Take the tuples that are either in R or in S and satisfy the condition C Take the tuples that are either in R and satisfy the condition C or in U and satisfy the condition C

15 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) R(a,b) S(b,d) σ C 100 100 σ C σ C 45 80 25000 R(a,b) S(b,d) 20000 10000 20000 10000 Take the tuples that are either in R or in S and satisfy the condition C Take the tuples that are either in R and satisfy the condition C or in U and satisfy the condition C

16 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that has all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) R(a,b) S(b,d) σ C 100 100 σ C σ C 45 80 25000 R(a,b) S(b,d) 20000 10000 20000 10000 Take the tuples that are either in R or in S and satisfy the condition C Take the tuples that are either in R and satisfy the condition C or in U and satisfy the condition C

17 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R))

18 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) The correctness can be similarly proved

19 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) The correctness can be similarly proved tuples that are in R but not in S and satisfy the condition C

20 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) The correctness can be similarly proved tuples that are in R but not in S and satisfy the condition C tuples that are in R and satisfy the condition C but are not in S

21 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Again pushing the selection σC reduces the size of the intermediate relations

22 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Remarks.

23 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Remarks. 1. Set/bag operations are applied on relations of the same schema, so the condition C in σC are applicable on both arguments;

24 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Remarks. 1. Set/bag operations are applied on relations of the same schema, so the condition C in σC are applicable on both arguments; 2. The condition C may be pushed to only one argument;

25 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Remarks. 1. Set/bag operations are applied on relations of the same schema, so the condition C in σC are applicable on both arguments; 2. The condition C may be pushed to only one argument; 3. σC(R⋃S) = R⋃σC(S), σC(R⋃S) = σC(R)⋃S, and σC(RS) = RσC(S) are NOT valid

26 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R))

27 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Pushing the selection may not even be meaningful

28 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Pushing the selection may not even be meaningful S(a,b) T(b,d) c × π σ S.a=T.d

29 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Pushing the selection may not even be meaningful S(a,b) T(b,d) c × π σ S.a=T.d π c × σ S.a=T.d σ S.a=T.d S(a,b) T(b,d)

30 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Pushing the selection may not even be meaningful S(a,b) T(b,d) c × π σ S.a=T.d π c × σ S.a=T.d σ S.a=T.d ?? S(a,b) T(b,d)

31 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Even when it is syntactically meaningful, it may not be logically correct.

32 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Even when it is syntactically meaningful, it may not be logically correct. R(a,b) S(b,c) a b 5 yes b c yes 4

33 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Even when it is syntactically meaningful, it may not be logically correct. R(a,b) S(b,c) 5 yes 4 a b 5 yes b c yes 4 in σa=5 or c=3(R ⨝ S) but may not be in σa=5(R) ⨝ σc=3(S)

34 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) We need a formal proof for the validity of each rule

35 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) We need a formal proof for the validity of each rule

36 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

37 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

38 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

39 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

40 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

41 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

42 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

43 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

44 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

45 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

46 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

47 Improving logic plan via logic laws
Theorem. If C contains only attributes in R, then σC(R⨝S) = σC(R)⨝S σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Proof. Let t be in σC(R⨝S). Then t is a join of a tuple t1 in R and a tuple t2 in S such that t1 and t2 agree on the common attributes. Since C contains only attributes in R and t satisfies C, t1 must also satisfy C, i.e., t1 is in σC(R). Thus, t is a join of t1 in σC(R) and t2 in S, i.e., t is in σC(R)⨝S. Thus, all tuples t in σC(R⨝S) are in σC(R)⨝S. Now consider a tuple t in σC(R)⨝S. t is a join of a tuple t1 in σC(R) and a tuple t2 in S such that t1 and t2 agree on the common attributes, and t1 satisfies C. Since t1 is in R so t is in R⨝S. Since t1 satisfies C, t also satisfies C, i.e., t is in σC(R⨝S). Thus, all tuples t in σC(R)⨝S are in σC(R⨝S). Thus, we must have σC(R⨝S) = σC(R)⨝S ⃞

48 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R))

49 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Can be trivially proved

50 Improving logic plan via logic laws
σC(R⋃S) = σC(R)⋃σC(S) σC(R∩S) = σC(R)∩σC(S) = σC(R)∩S = R∩σC(S) σC(RS) = σC(R)  σC(S) = σC(R)  S ╳, ⨝, ⨝D: σC can only be pushed to the arguments that have all attributes in C. σC and D(R) = σC(σD(R)) = σD(σC(R)) Can be trivially proved Useful when you want to further push some of the selections down.

51 Improving logic plan via logic laws
S(a,b) T(b,d) c × π σ S.b=T.b & d>4

52 Improving logic plan via logic laws
S(a,b) T(b,d) × c π σ d>4 S.b=T.b S(a,b) T(b,d) c × π σ S.b=T.b & d>4 σC&D(R) = σC(σD(R))

53 Improving logic plan via logic laws
S(a,b) T(b,d) × c π σ d>4 S.b=T.b S(a,b) T(b,d) c × π σ S.b=T.b & d>4 σC&D(R) = σC(σD(R)) σC(R×S) = R×σC(S) S(a,b) T(b,d) × c π σ S.b=T.b d>4

54 Improving logic plan via logic laws
S(a,b) T(b,d) × c π σ d>4 S.b=T.b S(a,b) T(b,d) c × π σ S.b=T.b & d>4 σC&D(R) = σC(σD(R)) σC(R×S) = R×σC(S) S(a,b) T(b,d) c π σ d>4 S(a,b) T(b,d) × c π σ S.b=T.b d>4 σS.b=T.b(S×T) = S T

55 Improving logic plan via logic laws
Major Steps: Move selections σ so they can be applied early (σ reduces table size); Combine cross product × with selections σ to make natural joins and theta joins C ( has more efficient algorithms); 3. group commutative and associative binary operations (e.g., ∩, U, ) (for later opt.); 4. May consider other operations (e.g., π, δ, τ, γ)


Κατέβασμα ppt "CPSC-608 Database Systems"

Παρόμοιες παρουσιάσεις


Διαφημίσεις Google