Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Notes #8.

Similar presentations


Presentation on theme: "CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Notes #8."— Presentation transcript:

1 CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Email: chen@cse.tamu.edu Notes #8

2 Prepare a collection C of efficient algorithms for operations in relational algebra; For a given database program P: 1. understand the program P; 2. translate the program P into an expression E in relational algebra; 3. convert E into an algorithm using algorithms in the collection C; 4. take care of issues in optimization and security. What Does DBMS Do?

3 An input database program P understand the program P translate the program P into an expression E in relational algebra convert E into an algorithm using algorithms in the collection C Machine executable code Prepare a collection C of efficient algorithms for operations in relational algebra; take care of issues in optimization and security. parse tree logic query plan physical query plan

4 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code parse tree logic query plan physical query plan

5 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code parse tree logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4;

6 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code parse tree logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4

7 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code parse tree logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4

8 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code parse tree logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 ScanTable(S(a,b)) ScanTable(T(b,c)) Alg-CrossProd Select(S.b=T.b & a>4) Project(c) output

9 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 ScanTable(S(a,b)) ScanTable(T(b,c)) Alg-CrossProd Select(S.b=T.b & a>4) Project(c) output parse tree preprocessing parse tree View processing, Semantic checking

10 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 ScanTable(S(a,b)) ScanTable(T(b,c)) Alg-CrossProd Select(S.b=T.b & a>4) Project(c) output parse tree preprocessing parse tree View processing, Semantic checking

11 Parse tree – logic plan conversion

12 If only simple relations and conditions are involved.

13 Parse tree – logic plan conversion SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 If only simple relations and conditions are involved.

14 Parse tree – logic plan conversion SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 If only simple relations and conditions are involved. What if there are complicated relations (subqueries) ?

15 Parse tree – logic plan conversion SELECT c FROM S(a,b), (SELECT * FROM T(b,c) WHERE c = 10) t WHERE S.b = t.b AND a>4; subqueries in the FROM clause

16 Parse tree – logic plan conversion SELECT c FROM S(a,b), (SELECT * FROM T(b,c) WHERE c = 10) t WHERE S.b = t.b AND a>4; select from where select, S(a,b) and = S.b T.b > a 4 subqueries in the FROM clause parse tree for (SELECT * FROM T(b,c) WHERE c = 10) t

17 Parse tree – logic plan conversion SELECT c FROM S(a,b), (SELECT * FROM T(b,c) WHERE c = 10) t WHERE S.b = t.b AND a>4; select from where select, S(a,b) and = S.b T.b > a 4 S(a,b) t c × π σ S.b=t.b AND a>4 subqueries in the FROM clause parse tree for (SELECT * FROM T(b,c) WHERE c = 10) t logic plan for (SELECT * FROM T(b,c) WHERE c = 10) t

18 Parse tree – logic plan conversion subqueries in the WHERE clause

19 Parse tree – logic plan conversion SELECT c FROM S(a,b), T(b,c) WHERE S.a > ALL (SELECT b FROM Y(b,c) WHERE c = 10) ; subqueries in the WHERE clause

20 Parse tree – logic plan conversion SELECT c FROM S(a,b), T(b,c) WHERE S.a > ALL (SELECT b FROM Y(b,c) WHERE c = 10) ; subqueries in the WHERE clause EXIST R s IN R s > ALL R s > ANY R

21 Parse tree – logic plan conversion SELECT c FROM S(a,b), T(b,c) WHERE S.a > ALL (SELECT b FROM Y(b,c) WHERE c = 10) ; subqueries in the WHERE clause EXIST R s IN R s > ALL R s > ANY R Each operation has a different conversion procedure. In general, 1.Convert the subquery into a logic plan; 2.Collect the attributes for the condition; 3.Make a cross product with the “main” relations; 4.Apply the conditions in the cross product.

22 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 ScanTable(S(a,b)) ScanTable(T(b,c)) Alg-CrossProd Select(S.b=T.b & a>4) Project(c) output parse tree preprocessing parse tree View processing, Semantic checking

23 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 ScanTable(S(a,b)) ScanTable(T(b,c)) Alg-CrossProd Select(S.b=T.b & a>4) Project(c) In general A pretty bad algorithm output parser parse tree preprocessing parse tree View processing, Semantic checking

24 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 ScanTable(S(a,b)) ScanTable(T(b,c)) Alg-CrossProd Select(S.b=T.b & a>4) Project(c) In general A pretty bad algorithm output parser parse tree preprocessing parse tree View processing, Semantic checking

25 What Does DBMS Do? Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code logic query plan physical query plan SELECT c FROM S(a,b), T(b,c) WHERE S.b = T.b AND a>4; select from where select, S(a,b) and T(b,c) = S.b T.b > a 4 S(a,b) T(b,c) c × π σ S.b=T.b AND a>4 ScanTable(S(a,b)) ScanTable(T(b,c)) Alg-CrossProd Select(S.b=T.b & a>4) Project(c) In general A pretty bad algorithm output parser parse tree preprocessing parse tree View processing, Semantic checking

26 Query Optimization Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code logic query plan physical query plan parser parse tree preprocessing parse tree View processing, Semantic checking

27 Query Optimization Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code physical query plan parse tree preprocessing parse tree View processing, Semantic checking logic query plan apply logic laws push selections, group joins

28 Query Optimization Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code physical query plan parse tree preprocessing parse tree View processing, Semantic checking logic query plan Optimization via logic and size apply logic laws push selections, group joins reduce the size of intermediate results

29 Query Optimization Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code physical query plan parse tree preprocessing parse tree View processing, Semantic checking logic query plan apply logic laws logic query plan Optimization via logic and size Optimization via algorithms and cost push selections, group joins reduce the size of intermediate results choices of algorithms, data structures, and computational modes

30 Query Optimization Prepare a collection C of efficient algorithms for operations in relational algebra; An input database program P parser parse tree-lqp convertor Lqp-pqp convertor take care of issues in optimization and security. Machine executable code physical query plan parse tree preprocessing parse tree View processing, Semantic checking logic query plan apply logic laws logic query plan Optimization via logic and size Optimization via algorithms and cost push selections, group joins reduce the size of intermediate results choices of algorithms, data structures, and computational modes


Download ppt "CPSC-608 Database Systems Fall 2015 Instructor: Jianer Chen Office: HRBB 315C Phone: 845-4259 Notes #8."

Similar presentations


Ads by Google