SlideServe
Menu
Préférences
© SlideServe · v2026

Overview of Advanced Database Query Processing

preston-donovan avatar
30 diapositives · 417 Views · Nov 20, 2014

Learn about query processing, query optimization, and execution in relational database systems with SQL examples and relational algebra. Understand how to translate queries and generate the best execution plan for optimal performance.

Overview of Advanced Database Query Processing - slide 1
01 / 30Overview of Advanced Database Query Processing
1 / 17

Télécharger la présentation

Overview of Advanced Database Query Processing
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Advanced Database SystemsNotes:Query Processing (Overview) Shivnath Babu

  2. High-level Query Q Answer Translates Q into best execution plan for current conditions, runs plan DataBase Management System (DBMS) DBMS Data

  3. Query Processing Declarative SQL Query  Query Plan NOTE: You will not be tested on how well you know SQL. Focus: Relational System (i.e., data is organized as tables, or relations)

  4. SQL Primer We will focus on SPJ, or Select-Project-Join Queries Select <attribute list> From <relation list> Where <condition list> Example Filter Query over R(A,B,C): Select B From R Where R.A = “c”  R.C > 10

  5. SQL Primer (contd.) We will focus on SPJ, or Select-Project-Join-Queries Select <attribute list> From <relation list> Where <condition list> Example Join Query over R(A,B,C) and S(C,D,E): Select B, D From R, S Where R.A = “c”  S.E = 2  R.C = S.C

  6. Answer B D 2 x R A B C S C D E a 1 10 10 x 2 b 1 20 20 y 2 c 2 10 30 z 2 d 2 35 40 x 1 e 3 45 50 y 3 Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

  7. How do we execute this query? Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C - Do Cartesian product - Select tuples - Do projection One idea

  8. Bingo! Got one... R X S R.A R.B R.C S.C S.D S.E a 1 10 10 x 2 a 1 10 20 y 2 . . c 2 10 10 x 2 . . Select B,D From R,S Where R.A = “c” S.E = 2  R.C=S.C

  9. Relational Algebra - can be used to describe plans Ex: Plan I B,D sR.A=“c” S.E=2  R.C=S.C X R S

  10. Relational Algebra Primer Select:sR.A=“c” R.C=10 Project: B,D Cartesian Product: R XS Natural Join: R S

  11. Relational Algebra - can be used to describe plans Ex: Plan I B,D sR.A=“c” S.E=2  R.C=S.C X R S OR: B,D [sR.A=“c” S.E=2  R.C = S.C (RXS)]

  12. Another idea: B,D sR.A = “c”sS.E = 2 R(A,B,C) S(C,D,E) Plan II natural join Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

  13. R S A B C s (R) s(S) C D E a 1 10 A B C C D E 10 x 2 b 1 20 c 2 10 10 x 2 20 y 2 c 2 10 20 y 2 30 z 2 d 2 35 30 z 2 40 x 1 e 3 45 50 y 3 Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

  14. Plan III Use R.A and S.C Indexes (1) Use R.A index to select R tuples with R.A = “c” (2) For each R.C value found, use S.C index to find matching tuples (3) Eliminate S tuples S.E  2 (4) Join matching R,S tuples, project B,D attributes, and place in result

  15. =“c” <c,2,10> <10,x,2> check=2? output: <2,x> next tuple: <c,7,15> R S A B C C D E a 1 10 10 x 2 b 1 20 20 y 2 c 2 10 30 z 2 d 2 35 40 x 1 e 3 45 50 y 3 c 7 15 A C I1 I2

  16. Overview of Query Processing SQL query parse parse tree Query rewriting Query Optimization statistics logical query plan Physical plan generation physical query plan execute Query Execution result

  17. Example Query Select B,D From R,S Where R.A = “c”  R.C=S.C

  18. Example: Parse Tree <Query> <SFW> SELECT <SelList> FROM <FromList> WHERE <Cond> <Attribute> <SelList> <RelName> <FromList> <Cond> AND <Cond> B <Attribute> R <RelName> <Attr> <Op> <Const> D S R.A = “c” Select B,D From R,S Where R.A = “c”  R.C=S.C <Attr> <Op> <Attr> R.C = S.C

  19. Along with Parsing … • Semantic checks • Do the projected attributes exist in the relations in the From clause? • Ambiguous attributes? • Type checking, ex: R.A > 17.5 • Expand views

  20. SQL query Initial logical plan parse Rewrite rules parse tree Query rewriting Logical plan statistics logical query plan Physical plan generation “Best” logical plan physical query plan execute result

  21. Initial Logical Plan B,D Select B,D From R,S Where R.A = “c”  R.C=S.C R.A = “c” Λ R.C = S.C X R S Relational Algebra: B,D [sR.A=“c” R.C = S.C (RXS)]

  22. Apply Rewrite Rule (1) B,D B,D R.C = S.C R.A = “c” Λ R.C = S.C R.A = “c” X X R S R S B,D [sR.C=S.C [R.A=“c”(R X S)]]

  23. Apply Rewrite Rule (2) B,D B,D R.C = S.C R.C = S.C R.A = “c” X R.A = “c” S X R S R B,D [sR.C=S.C [R.A=“c”(R)] X S]

  24. Apply Rewrite Rule (3) B,D B,D R.C = S.C Natural join R.A = “c” X S R.A = “c” S R R B,D [[R.A=“c”(R)] S]

  25. SQL query Initial logical plan parse Rewrite rules parse tree Query rewriting Logical plan statistics logical query plan Physical plan generation “Best” logical plan physical query plan execute result

  26. SQL query parse parse tree Query rewriting statistics Best logical query plan Physical plan generation Best physical query plan execute result

  27. Physical Plan Generation B,D Project Natural join Hash join R.A = “c” S Index scan Table scan R R S Best logical plan

  28. SQL query parse parse tree Enumerate possible physical plans Query rewriting statistics Best logical query plan Find the cost of each plan Physical plan generation Best physical query plan Pick plan with minimum cost execute result

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

  30. SQL query parse parse tree Query rewriting statistics logical query plan Physical plan generation physical query plan execute result Query Processing - In class order