Trang 3
Cost-Based Optimization • Prune the space of plans using heuristics • Estimate cost for remaining plans – Be smart about how you iterate through plans • Pick the plan with least cost Focus on queries with joins
Đang tạo bản xem trước...
Cost-Based Optimization • Prune the space of plans using heuristics • Estimate cost for remaining plans – Be smart about how you iterate through plans • Pick the plan with least cost Focus on queries with joins
Heuristics for pruning plan space • Predicates as early as possible • Avoid plans with cross products • Only left-deep join trees
Physical Plan Selection Logical Query Plan P1 P2 …. Pn Physical plans C1 C2 …. Cn Costs Pick minimum cost one
Simple Cost Model Cost (R S) = T(R) + T(S) All other operators have 0 cost Note: The simple cost model used for illustration only
Selinger Algorithm • Dynamic Programming based • Dynamic Programming: – General algorithmic paradigm – Exploits “principle of optimality” – Useful reading: • Chapter 16, Introduction to Algorithms, Cormen, Leiserson, Rivest
Principle of Optimality Query: R1 R2 R3 R4 R5 Optimal Plan: R5 R1 R4 R3 R2 Optimal plan for joining R3, R2, R4, R1
Principle of Optimality Query: R1 R2 R3 R4 R5 Optimal Plan: R5 R1 R4 R3 R2 Optimal plan for joining R3, R2, R4
Exploiting Principle of Optimality Query: R1 R2 … Rn R1 R2 R2 R3 R3 R1 Optimal Sub-Optimal for joining R1, R2, R3 for joining R1, R2, R3
Exploiting Principle of Optimality Ri Rj Sub-Optimal R2 for joining R1,…,Rn R3 R1 A sub-optimal sub-plan cannot lead to an optimal plan
Selinger Algorithm: Query: R1 R2 R3 R4 Progress of { R1, R2, R3, R4 } algorithm { R1, R2, R3 } { R1, R2, R4 } { R1, R3, R4 } { R2, R3, R4 } { R1, R2 } { R1, R3 } { R1, R4 } { R2, R3 } { R2, R4 } { R3, R4 } { R1 } { R2 } { R3 } { R4 }
Notation OPT ( { R1, R2, R3 } ): Cost of optimal plan to join R1,R2,R3 T ( { R1, R2, R3 } ): Number of tuples in R1 R2 R3
Selinger Algorithm: OPT ( { R1, R2, R3 } ): OPT ( { R1, R2 } ) + T ( { R1, R2 } ) + T(R3) Min OPT ( { R2, R3 } ) + T ( { R2, R3 } ) + T(R1) OPT ( { R1, R3 } ) + T ( { R1, R3 } ) + T(R2) Note: Valid only for the simple cost model
Selinger Algorithm: Query: R1 R2 R3 R4 Progress of { R1, R2, R3, R4 } algorithm { R1, R2, R3 } { R1, R2, R4 } { R1, R3, R4 } { R2, R3, R4 } { R1, R2 } { R1, R3 } { R1, R4 } { R2, R3 } { R2, R4 } { R3, R4 } { R1 } { R2 } { R3 } { R4 }
Selinger Algorithm: Query: R1 R2 R3 R4 Progress of { R1, R2, R3, R4 } algorithm { R1, R2, R3 } { R1, R2, R4 } { R1, R3, R4 } { R2, R3, R4 } { R1, R2 } { R1, R3 } { R1, R4 } { R2, R3 } { R2, R4 } { R3, R4 } { R1 } { R2 } { R3 } { R4 }
Hiển thị 20 trang đầu. Tải tài liệu để xem đầy đủ.
Chưa có bình luận nào. Hãy là người đầu tiên!
Bình luận (0)
Chưa có bình luận nào. Hãy là người đầu tiên!