1 / 31

Informationsintegration Dynamische Programmierung

Informationsintegration Dynamische Programmierung. 8.12.2005 Felix Naumann. Überblick. Dynamische Programmierung (DP) zur Anfrageoptimierung Grundlagen der DP Das Grundproblem der Anfrageoptimierung DP für Anfrageoptimierung DP für verteilte DBMS. Richard Bellman. 1920 – 1984

rana-vance
Download Presentation

Informationsintegration Dynamische Programmierung

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. InformationsintegrationDynamische Programmierung 8.12.2005 Felix Naumann

  2. Überblick • Dynamische Programmierung (DP) zur Anfrageoptimierung • Grundlagen der DP • Das Grundproblem der Anfrageoptimierung • DP für Anfrageoptimierung • DP für verteilte DBMS Felix Naumann, VL Informationsintegration, WS 05/06

  3. Richard Bellman • 1920 – 1984 • PhD Princeton (3 Monate) • Los Alamos (1944-1946) • 1953 Rand Corporation: Erfindung der Dynamischen Programmierung • Viele andere Beiträge zur Mathematik • Bellman-Ford Algorithmus Felix Naumann, VL Informationsintegration, WS 05/06

  4. B E H A C F J I D G The Stagecoach story • some 150 years ago there was a salesman travelling west by stagecoach .. New York San Francisco Quelle: Folien Ioana Popescu http://faculty.insead.edu/popescu/ioana/ Felix Naumann, VL Informationsintegration, WS 05/06

  5. 7 1 2 4 4 6 3 3 B E 6 4 2 H 3 4 4 A C F J 4 3 3 I 1 3 D G 5 Versicherungskosten Frage: Welches ist der beste (billigste) Weg? Quelle: Folien Ioana Popescu http://faculty.insead.edu/popescu/ioana/ Felix Naumann, VL Informationsintegration, WS 05/06

  6. Billigster Weg – Greedy Suche 7 1 B E 2 4 4 6 H 3 3 6 4 2 A C F J 3 4 4 4 I 3 3 1 D G 3 5 Greedy: A-B-F-I-J = 13 Frage: Gibt es einen besseren Weg? Quelle: Folien Ioana Popescu http://faculty.insead.edu/popescu/ioana/ Felix Naumann, VL Informationsintegration, WS 05/06

  7. Billigster Weg – Vollständige Suche 7 1 B E 2 4 4 6 H 3 3 6 4 2 A C F J 3 4 4 4 I 3 3 1 D G 3 5 Anzahl der möglichen Wege: 3 x 3 x 2 = 18 Besser: A-D-F-I-J = 11 Quelle: Folien Ioana Popescu http://faculty.insead.edu/popescu/ioana/ Felix Naumann, VL Informationsintegration, WS 05/06

  8. The Stagecoach Solution • Idee der Dynamischen Programmierung • Hier: “Rückwärtsberechnung” • Voraussetzung: Prinzip der Optimalität • Teilplan eines optimalen Plans ist ebenfalls optimal • Idee • Ausgehend vom Zielknoten stufenweise rückwärts beste Teilpfade berechnen • F(X) := minimale Kosten von X nach J Quelle: Folien Ioana Popescu http://faculty.insead.edu/popescu/ioana/ Felix Naumann, VL Informationsintegration, WS 05/06

  9. 7 1 2 4 4 6 3 3 B E 6 4 2 H 3 4 4 A C F J 4 3 3 I 1 3 D G 5 Billigster Weg - DP F(E)=4 F(B)=11 F(H)=3 F(A)=11 F(J)=0 F(F)=7 F(C)=7 F(I)=4 F(G)=6 F(D)=8 F(X) : = min Kosten von X nach J Quelle: Folien Ioana Popescu http://faculty.insead.edu/popescu/ioana/ Felix Naumann, VL Informationsintegration, WS 05/06

  10. Dynamische Programmierung • Optimaler Algorithmus • „Schwierigkeiten“ • Prinzip der Optimalität muss gelten. • Aufteilung des Problems in Teilprobleme • Aufwand kann exponentiell sein • Klassische Anwendungen • Knapsack Problem • Traveling Salesman Problem • Maschinenbelegung • Transportproblem Felix Naumann, VL Informationsintegration, WS 05/06

  11. Überblick • Dynamische Programmierung (DP) zur Anfrageoptimierung • Grundlagen der DP • Das Grundproblem der Anfrageoptimierung • DP für Anfrageoptimierung • DP für verteilte DBMS Felix Naumann, VL Informationsintegration, WS 05/06

  12. Architektur zur Anfragebearbeitung Logische Optimierung (unabhängig von System und Konfiguration): Entschachtelung, redundante Prädikate,... Wandelt Plan (Baum) in ausführbaren Plan (Code) um. Anfrage- ergebnis Anfrage Anfrage- optimierung Code Generierung Anfragebearbeitung (Engine) Parser Anfrage- umschreibung Katalog/ Metadaten Optimierung für System und Konfiguration: Indices, Joinreihenfolge, Selektion der Datenquelle Daten Syntax und etwas Semantik Erzeugt Anfragegraph Schema, Statistik, Partitionierung, Lage der Daten,... Felix Naumann, VL Informationsintegration, WS 05/06

  13. Anfrageoptimierung • Suchraum • Alle gültigen Anfragepläne • Kostenmodell • Join-Operator • Netzwerkkosten • Optimierungsproblem • Finde im Suchraum den kostenoptimalen Anfrageplan. Felix Naumann, VL Informationsintegration, WS 05/06

  14. Anfrageplanung • Heuristische Einschränkung des Suchraums • Keine Kreuzprodukte • Außer explizite Kreuzprodukte in der Anfrage • Prädikate so früh wie möglich • Nur links-tiefe (left-deep) Bäume ⋈ ⋈ Left-Deep Bushy Zig-Zag Pipelined Execution ⋈ ⋈ ⋈ ⋈ ⋈ ⋈ ⋈ R S T U T R S U R S T U Felix Naumann, VL Informationsintegration, WS 05/06

  15. Überblick • Dynamische Programmierung (DP) zur Anfrageoptimierung • Grundlagen der DP • Das Grundproblem der Anfrageoptimierung • DP für Anfrageoptimierung • DP für verteilte DBMS Felix Naumann, VL Informationsintegration, WS 05/06

  16. Dynamische Programmierung: Optimierung im System-R • A.k.a. “Selinger-style query optimization” • Der klassische Artikel zur Anfrageoptimierung: [SAC+79] • Ursprünglich im IBM System-R • Heutzutage weit verbreitet • Grundidee: • Nur “Left-deep” Anfragebäume • D.h. nur Joinreihenfolge interessant • Innere und äußere Relation unberücksichtigt • Bottom-up Generierung von Anfrageplänen • Dynamische Programmierung (DP) • Zusätzlich: interesting orders (interessante Sortierungen) • Zusätzlich: interesting sites (interessante Ausführungsorte) • Literatur mit Beispiel: [GMUW00] Quelle: u.a. Folien Prof. Chen Li Felix Naumann, VL Informationsintegration, WS 05/06

  17. Felix Naumann, VL Informationsintegration, WS 05/06

  18. Bottom-up Anfrageplangenerierung • Grundannahme 1:Nach dem Join über k Relationen ist die Join-Methode die k+1te Relation um hinzuzujoinen unabhängig von den vorigen Join-Methoden. • Joinmethoden: Nested Loops, Hashjoin, Sort-Merge Join usw. • Grundannahme 2:Jeder Teilplan eines optimalen Plans ist ebenfalls optimal. • Entspricht dem Prinzip der Optimalität: Wenn sich zwei Pläne nur in einem Teilplan unterscheiden, so ist der Plan mit dem besseren Teilplan auch der bessere Gesamtplan • Bottom-up Anfrageplangenerierung: • Berechne die optimalen Pläne für den Join über (jede Kombination von) k Relationen • Suboptimale Pläne werden verworfen • Erweitere diese Pläne zu optimalen Plänen für k+1 Relationen. • usw. bis k = n Felix Naumann, VL Informationsintegration, WS 05/06

  19. Dynamische Programmierung {} {R} {S} {T} {U} {R S} {R T} {R U} {S T} {S U} {T U} {R S T} {R S U} {S T U} {R T U} {R S T U} Felix Naumann, VL Informationsintegration, WS 05/06

  20. DP – Grundidee für Anfrageoptimierung • Für jede Kombination merke (in einer Hilfstabelle): • Geschätzte Größe des Ergebnisses (Kardinalität) • Geschätzte minimale Kosten • Hier zur Vereinfachung: Größe des Zwischenergebnisses • Joinreihenfolge, die diese Kosten verursacht (= optimaler Teilplan) • Induktion über Anzahl der Relationen im Plan • N=1: Für jede Relation • Kardinalität = Kardinalität der Relation • Kosten = 0 (zur Vereinfachung) • Joinreihenfolge: n/a • N=2: Für jedes Relationenpaar R, S • Kardinalität = |R| x |S| x sf • Kosten = 0 • Joinreihenfolge: kleinere Relation links • Clou: R und S jeweils mit besten access-path • N=3: Für jedes Tripel R, S, T • Clou: Nur bestes Relationenpaar aus dem Tripel wird um dritte Relation ergänzt • ... Felix Naumann, VL Informationsintegration, WS 05/06

  21. DP – Beispiel S T • Anfrage über Relationen R, S, T, U. • Vier Join-Bedingungen Anfragegraph R U u.U. auch IndexScan(...) Felix Naumann, VL Informationsintegration, WS 05/06

  22. DP – Beispiel X X Kreuzprodukte nicht berücksichtigen! S T R U Besser als z.B. S ⋈ (T ⋈ R) oder (R ⋈ S) ⋈ T Felix Naumann, VL Informationsintegration, WS 05/06

  23. DP – Beispiel S T Anfragegraph R U Bisher unberücksichtigt: Wahl des Join-Algorithmus Optimaler (left-deep) Plan Felix Naumann, VL Informationsintegration, WS 05/06

  24. Felix Naumann, VL Informationsintegration, WS 05/06

  25. DP - interesting orders (Interessante Sortierung) • WdH.: Prinzip der Optimalität: Wenn sich zwei Pläne nur in einem Teilplan unterscheiden, so ist der Plan mit dem besseren Teilplan auch der bessere Gesamtplan. • Gegenbeispiel: • R(A,B) ⋈ S(A,C) ⋈ T(A,D) • Bester (lokaler) Plan für R ⋈ S: Hash-Join • Best (globaler) Gesamtplan: • 1. Sort-merge Join über R und S • 2. Sort-merge Join mit T • Warum könnte dies so sein? • Das Zwischenergebnis von R ⋈sort-mergeS ist nach Join-Attribut A sortiert. • Dies ist eine interesting order, die später ausgenutzt werden kann: • Spätere sort-merge Joins • Gruppierung (GROUP BY) • Sortierung (ORDER BY) • Eindeutige Tupel (DISTINCT) Felix Naumann, VL Informationsintegration, WS 05/06

  26. DP - interesting orders (Interessante Sortierung) • Bei Auswahl des besten Teilplans: • Kostenvergleich genügt nicht. • Es gibt keine vollständige Ordnung der Teilpläne nach Kosten. • Auch Sortierungen müssen berücksichtigt werden. • Lösung: Für jede Kombination von Relationen, speichere mehrere Sortiervarianten: • Nach jeder Variante der beteiligten Teilpläne • Die “leere” Sortierung • DP Tabellen werden „breiter“. • Merke außerdem Join- und Sortieroperationen, die diese Sortierung erzeugen. Felix Naumann, VL Informationsintegration, WS 05/06

  27. DP – Algorithmus Alle Zugriffspläne für jede Relation Schlechtere Zugriffs-pläne verwerfen Achtung: Nicht left-deep! Quelle: [Ko00] Felix Naumann, VL Informationsintegration, WS 05/06

  28. Überblick • Dynamische Programmierung (DP) zur Anfrageoptimierung • Grundlagen der DP • Das Grundproblem der Anfrageoptimierung • DP für Anfrageoptimierung • DP für verteilte DBMS Felix Naumann, VL Informationsintegration, WS 05/06

  29. DP in verteilten Systemen • Entscheidungen des Optimierers • Zugriffpfade auf Relationen • Table-scan, Index-scan • Joinreihenfolge • Art der Join-Berechnung • Nested loops, sort-merge usw. • Neu: Ort der Join-Berechnung • Am Speicherort der inneren Relation / des Zwischenergebnisses • Am Speicherort der äußere Relation / des Zwischenergebnisses • Am Ort der Weiterverarbeitung • Anderswo, z.B. Ort der schnellsten CPU Felix Naumann, VL Informationsintegration, WS 05/06

  30. DP in verteilten Systemen Berücksichtigung (und Repräsentation) mehrerer Speicherorte ⇒ mehr Zugrifspläne Berücksichtigung (und Repräsentation) des Ausführungsortes des Joins ⇒ interesting order und interesting site ⇒ mehr Zugrifspläne Am Ende gegebenenfalls noch ship Operator anfügen. Felix Naumann, VL Informationsintegration, WS 05/06

  31. Literatur • Das grundlegende Paper • [SAC+79] Patricia G. Selinger, Morton M. Astrahan, Donald D. Chamberlin, Raymond A. Lorie, Thomas G. Price: Access Path Selection in a Relational Database Management System. SIGMOD Conference 1979: 23-34 • Englisches Lehrbuch • [GMUW00] Hector Garcia-Molina, Jeffrey D. Ullman, Jennifer Widom: Database System Implementation Prentice-Hall 2000 • Weiteres • [Ko00] The State of the Art in Distributed Query Processing, Donald Kossmann, ACM Computing Surveys 32(4), pages 422-469. (Link auf WWW) • [OK00] Kiyoshi Ono, Guy M. Lohman: Measuring the Complexity of Join Enumeration in Query Optimization. VLDB 1990: 314-325 • [HFLP89] Laura M. Haas, Johann Christoph Freytag, Guy M. Lohman, Hamid Pirahesh: Extensible Query Processing in Starburst. SIGMOD Conference 1989: 377-388 • [Graefe93] Goetz Graefe: Query Evaluation Techniques for Large Databases. ACM Comput. Surv. 25(2): 73-170 (1993) Felix Naumann, VL Informationsintegration, WS 05/06

More Related