Presentation is loading. Please wait.

Presentation is loading. Please wait.

October 31, 2012.  The RDBMS steps in executing SQL query:  Checks query syntax  Validates query-checks data dictionary; verifies objects referred.

Similar presentations


Presentation on theme: "October 31, 2012.  The RDBMS steps in executing SQL query:  Checks query syntax  Validates query-checks data dictionary; verifies objects referred."— Presentation transcript:

1 October 31, 2012

2  The RDBMS steps in executing SQL query:  Checks query syntax  Validates query-checks data dictionary; verifies objects referred to are database objects and requested operations are valid  Translates query into relational algebra (or relational calculus)  Rearranges relational algebra operations into most efficient form  Uses its knowledge of table size, indexes, order of tuples, distribution of values, to determine how the query will be processed-estimates the "cost" of alternatives and chooses the plan with the least estimated cost-considers the number of disk accesses, amount of memory, processing time, and communication costs, if any  Execution plan is then coded and executed

3

4 SalesPerson salesIdlastNamefirstNameaddressphone S101SmithTom123 Oak333-4444 S102ChinAnn456 Elm555-1212 S105LeePerry789 Main545-3333 S109SmithBetty123 Oak333-4444 Customer custIdlastNamefirstNameemail C1001SmithBobbobsmith@gmail.com C1003DoeJohnjdoe@tacosalad.lssu.edu C1007BogerTomtboger@lssu.edu Invoice salesIdcustIddescriptiondateamount S101C1001Blouse10/15/2012$45.89 S101C1007End table10/18/2012$205.00 S105C1007Miscellaneous10/18/2012$95.99 S101C1003Blouse10/21/2012$55.99

5  Theoretical language with operators that apply to one or two relations to produce another relation  Both operands and results are tables  Can assign name to resulting table (rename)  SELECT, PROJECT, JOIN allow many data retrieval operations

6  Applied to a single table, returns rows that meet a specified predicate, copying them to new table  Returns a horizontal subset of original table SELECT tableName WHERE condition [GIVING newTableName] Symbolically, [newTableName = ]  predicate (table-name)  Predicate is called theta-condition, as in   (table-name)  Result table is horizontal subset of operand  Predicate can have operators,  (AND),  (OR),  (NOT)

7  Example: SELECT SalesPerson WHERE lastName=‘Smith’ GIVING Answer  Symbolic version: Answer =  lastName=‘Smith’ (salesPerson)  Result: Answer salesIdlastNamefirstNameaddressphone S101SmithTom123 Oak333-4444 S109SmithBetty123 Oak333-4444

8  Example with more complex predicate: SELECT Invoice WHERE salesId=‘S101’ AND date = ‘10/18/2012’  Symbolic version:  salesId=‘S101’  date=’10/18/2012’ (Invoice)  Result: salesIdcustIddescriptiondateamount S101C1007End table10/18/2012$205.00

9  Operates on single table  Returns unique values in a column or combination of columns PROJECT tableName OVER (colName,...,colName) [GIVING newTableName] Symbolically [newTableName =]  colName,...,colName (tableName)  Can compose SELECT and PROJECT, using result of first as argument for second

10  Example: PROJECT Invoice OVER description GIVING Temp  Symbolically: Temp =  description (Invoice)  Result: Temp description Blouse End table Miscellaneous

11  Example of multiple column projection: PROJECT Invoice OVER salesId, custId  Symbolically:  salesId, custId (Invoice)  Result: salesIdcustId S101C1001 S101C1007 S105C1007 S101C1003

12  Example: SELECT Invoice WHERE salesId=‘S101’ GIVING Temp PROJECT Temp OVER date, amount GIVING Result  Symbolically:  date, amount (  salesId=‘S101’ (Invoice))  Temp:Result: Temp salesIdcustIddescriptiondateamount S101C1001Blouse10/15/2012$45.89 S101C1007End table10/18/2012$205.00 S101C1003Blouse10/21/2012$55.99 Result dateamount 10/15/2012$45.89 10/18/2012$205.00 10/21/2012$55.99

13  Requires two tables with common column(s) (at least with same domain)  combines the matching rows-rows of the two tables that have the same values in the common column(s)  symbolized by |x| as in  [newTableName = ] Table1 |x| Table2, or  Table1 JOIN Table2 [GIVING newTableName]

14  Example: SalesPerson JOIN Invoice GIVING Result  Symbolically: Result = SalesPerson |x| Invoice  Result: Invoice salesIdlastNamefirstNameaddressphonecustIddescriptiondateamount S101SmithTom123 Oak333-4444C1001Blouse10/15/2012$45.89 S101SmithTom123 Oak333-4444C1007End table10/18/2012$205.00 S105LeePerry789 Main545-3333C1007Miscellaneous10/18/2012$95.99 S101SmithTom123 Oak333-4444C1003Blouse10/21/2012$55.99

15

16  Graphical representation of the operations and operands in a relational algebra expression  a leaf node is created for each relation (table) in the expression  For each unary or binary operation on a relation, an upward branch is drawn from the node  Reading upward from the leaves, as each operation is included, an internal, non-leaf node is created to represent the result of the operation  Root node represents the entire expression  See next slide for an example

17 Query: “Find the schedules and rooms of all courses taken by any Math major.” Relational algebra: Student JOIN Enroll GIVING Temp1 Temp1 JOIN Class GIVING Temp2 SELECT Temp2 WHERE major=‘Math’ GIVING Temp3 PROJECT Temp3 OVER schedule, room

18  An internal node can be executed when its operands are available  Node is replaced by the result of the operation it represents  Process continues until root node is reached  Root node is executed last, and is replaced by the result of the entire query

19  Same SQL statement can be translated to different relational algebra statements  Performing SELECT early reduces size of intermediate nodes-See next slide

20 Relational algebra: SELECT Student WHERE major=‘Math’ GIVING T1 T1 JOIN Enroll GIVING T2 T2 JOIN Class GIVING T3 PROJECT T3 OVER schedule, room


Download ppt "October 31, 2012.  The RDBMS steps in executing SQL query:  Checks query syntax  Validates query-checks data dictionary; verifies objects referred."

Similar presentations


Ads by Google