Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPS216: Data-Intensive Computing Systems Query Processing (Overview)

Similar presentations


Presentation on theme: "CPS216: Data-Intensive Computing Systems Query Processing (Overview)"— Presentation transcript:

1 CPS216: Data-Intensive Computing Systems Query Processing (Overview)
Shivnath Babu

2 Query Processing Declarative SQL Query  Query Plan
NOTE: You will not be tested on how well you know SQL. Understanding the SQL introduced in class will be sufficient (a primer follows). SQL is described in Chapter 6, GMUW. Focus: Relational System (i.e., data is organized as tables, or relations)

3 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

4 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

5 R A B C S C D E a x 2 b y 2 c z 2 d x 1 e y 3 Answer B D x Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

6 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

7 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 Select B,D .
c x 2 Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C Bingo! Got one...

8 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

9 Relational Algebra Primer (Chapter 5, GMUW)
Select: sR.A=“c” R.C=10 Project: B,D Cartesian Product: R X S Natural Join: R S

10 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)]

11 Another idea: Plan II B,D sR.A = “c” sS.E = 2 Select B,D
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

12 Select B,D 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 c x y 2 c y z 2 d z x 1 e y 3 Select B,D From R,S Where R.A = “c”  S.E = 2  R.C=S.C

13 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

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

15 Physical plan generation
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

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

17 SELECT <SelList> FROM <FromList> WHERE <Cond>
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

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

19 Physical plan generation
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

20 B,D R.A = “c” Λ R.C = S.C Initial Logical Plan X R S
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)]

21 B,D B,D R.C = S.C R.A = “c” Λ R.C = S.C R.A = “c”
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)]]

22 B,D B,D R.C = S.C R.C = S.C R.A = “c” R.A = “c”
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]

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

24 Physical plan generation
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


Download ppt "CPS216: Data-Intensive Computing Systems Query Processing (Overview)"

Similar presentations


Ads by Google