Die Präsentation wird geladen. Bitte warten

Die Präsentation wird geladen. Bitte warten

Informationsintegration Dynamische Programmierung

Ähnliche Präsentationen


Präsentation zum Thema: "Informationsintegration Dynamische Programmierung"—  Präsentation transkript:

1 Informationsintegration Dynamische Programmierung
Felix Naumann

2 Felix Naumann, VL Informationsintegration, WS 05/06
Ü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 Felix Naumann, VL Informationsintegration, WS 05/06
Richard Bellman 1920 – 1984 PhD Princeton (3 Monate) Los Alamos ( ) 1953 Rand Corporation: Erfindung der Dynamischen Programmierung Viele andere Beiträge zur Mathematik Bellman-Ford Algorithmus Felix Naumann, VL Informationsintegration, WS 05/06

4 Felix Naumann, VL Informationsintegration, WS 05/06
The Stagecoach story some 150 years ago there was a salesman travelling west by stagecoach .. A J I H G D F C E B ..at the time there was a serious danger of attack by marauders.. Although his starting point and destination were fixed he had considerable choice as to which states or territories that subsequently became states) to travel through en route. How to determine safest route? Life insurance policies were offered to stagecoach passengers, based on careful evaluation of the safety of the run. The safest route must be that with cheapest total life insurance policy. New York San Francisco Quelle: Folien Ioana Popescu Felix Naumann, VL Informationsintegration, WS 05/06

5 Versicherungskosten A J I H G D F C E B 2 4 3 7 6 1 5
Frage: Welches ist der beste (billigste) Weg? Quelle: Folien Ioana Popescu 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 4 3 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 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 4 3 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 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 Dijkstra’s Algorithm Also A-D-E-H-J =11 And A-C-E-H-J=11 Quelle: Folien Ioana Popescu Felix Naumann, VL Informationsintegration, WS 05/06

9 Billigster Weg - DP A J I H G D F C E B 2 4 3 7 6 1 5 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 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 Felix Naumann, VL Informationsintegration, WS 05/06
Ü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 Parser Anfrage- umschreibung Anfrage- optimierung Code Generierung Anfragebearbeitung (Engine) 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 Felix Naumann, VL Informationsintegration, WS 05/06
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 Felix Naumann, VL Informationsintegration, WS 05/06
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 Felix Naumann, VL Informationsintegration, WS 05/06
Ü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
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 Felix Naumann, VL Informationsintegration, WS 05/06
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 X X DP – Beispiel S T R U Kreuzprodukte nicht berücksichtigen!
Besser als z.B. S ⋈ (T ⋈ R) oder (R ⋈ S) ⋈ T Felix Naumann, VL Informationsintegration, WS 05/06

23 DP – Beispiel Bisher unberücksichtigt: Wahl des Join-Algorithmus S T R
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
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 Felix Naumann, VL Informationsintegration, WS 05/06
Ü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 Felix Naumann, VL Informationsintegration, WS 05/06
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 (Link auf WWW) [OK00] Kiyoshi Ono, Guy M. Lohman: Measuring the Complexity of Join Enumeration in Query Optimization. VLDB 1990: [HFLP89] Laura M. Haas, Johann Christoph Freytag, Guy M. Lohman, Hamid Pirahesh: Extensible Query Processing in Starburst. SIGMOD Conference 1989: [Graefe93] Goetz Graefe: Query Evaluation Techniques for Large Databases. ACM Comput. Surv. 25(2): (1993) Felix Naumann, VL Informationsintegration, WS 05/06


Herunterladen ppt "Informationsintegration Dynamische Programmierung"

Ähnliche Präsentationen


Google-Anzeigen