qp opt (08) (Tối ưu hóa truy vấn trong hệ thống dữ liệu chuyên sâu) (Tiếng Anh)

UN
Uni24h
0 downloads
41
0

Document content

Page 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

Page 4

Heuristics for pruning plan space • Predicates as early as possible • Avoid plans with cross products • Only left-deep join trees

Page 5

Physical Plan Selection Logical Query Plan P1 P2 …. Pn Physical plans C1 C2 …. Cn Costs Pick minimum cost one

Page 7

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

Page 9

Selinger Algorithm • Dynamic Programming based • Dynamic Programming: – General algorithmic paradigm – Exploits “principle of optimality” – Useful reading: • Chapter 16, Introduction to Algorithms, Cormen, Leiserson, Rivest

Page 12

Principle of Optimality Query: R1 R2 R3 R4 R5 Optimal Plan: R5 R1 R4 R3 R2 Optimal plan for joining R3, R2, R4, R1

Page 13

Principle of Optimality Query: R1 R2 R3 R4 R5 Optimal Plan: R5 R1 R4 R3 R2 Optimal plan for joining R3, R2, R4

Page 14

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

Page 15

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

Page 16

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 }

Page 17

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

Page 18

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

Page 19

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 }

Page 20

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 }

Showing the first 20 pages. Download the document to see it all.

Comments (0)

Sign in to join the discussion

No comments yet. Be the first!