School of Computing, Engineering and Information Sciences CM0036 Advanced Databases (Level 6) January 2006 Time allowed: 3 hours + 15 mins reading time Instructions: This is an OPEN BOOK/OPEN NOTES examination. Items allowed include any of the following: One or two database related books Lecture Notes Seminar handouts and their solutions THREE questions are set – candidates must attempt TWO questions. In case three questions are attempted, the question that attracts least marks will be disregarded. All questions are of equal value (25 marks). Allocation of marks is as shown. Students are allowed to use a calculator. All questions refer to the attached appendix: The description of a scenario based on Oil and Grease Ltd (OGL) database. Page 1 of 8 January 2006 CM0036 Advanced Databases Question 1 Part A (Query Optimization) Consider the following SQL query that joins the IndustrialUnit, Product and WorkOrder tables: SELECT FROM WHERE AND AND AND AND AND i.Location, p.Desc, w.WorkOrderId, w.OrderDate IndustrialUnit i, Product p, WorkOrder w, IndUnitProduct ip i.UnitId = ip.UnitId ip.ProdId = p.ProdId p.ProdId = w.ProdId w.Qty > 100 w.Status = ‘C’ i.Country = ‘UK’ Assume the following information: The page size for the database is 1024 bytes. The size of the IndustrialUnit table is 20 pages: o There are 180 records; each record is of 106 bytes; and 9 records occupy one page on disk. The size of the Product table is 2600 pages: o There are 36,400 records; each record is of 72 bytes; and 14 records occupy one page on disk. The size of the WorkOrder table is 21,000 pages: o There are 357,000 records; each record is of 65 bytes; and 15 records occupy one page on disk. The size of the IndUnitProduct table is 4300 pages: o There are 360,000 records; each record is of 12 bytes; and 85 records occupy one page on disk. There are 30,600 records in the WorkOrder table with Qty > 100, and the number of records in the same table with Status = ‘C’ is 10,200. However, the number of records satisfying both conditions is 7500. There are 36 records in the IndustrialUnit table with Country = ‘UK’. There are 52 buffer pages available during the query processing. There is a Hash Index (clustered) available on Country and Status columns for the corresponding tables. The cost of the projection (i.e. the attributes mentioned in the SELECT clause in the SQL query) can be ignored. The initial non-optimized relational algebra query tree that represents the above SQL query is given in Figure 1 (on the next page). During the query processing, any intermediate results should be written to disk first before other operators use them. Page 2 of 8 January 2006 CM0036 Advanced Databases Answer the following questions: (I) What logical optimization techniques can be applied to the query tree in Figure 1 below? Suggest a logically optimized version of the query tree. [Note: You are free to change the join order or the sequence of operators in the query tree.] (5 marks) (II) What physical optimization techniques can be applied to the query tree resulting from your answer to part (I)? Suggest a physically optimized query tree (i.e. evaluation plan) for executing the relational operations involved in the query tree by indicating which method will be used for evaluating each separate operator. [Note: You are free to choose the order in which different operators in the query tree should be evaluated keeping in mind the main objective is to reduce the number of I/Os.] (5 marks) (III) Compute the I/O cost for evaluating the first join (i.e. left most at a lowest level in the tree) in your physically optimized query tree from your answer to part (II) using any of the four join algorithms taught on the module giving the least possible cost. (5 marks) (IV) What would be the lowest possible I/O cost for evaluating the last join (i.e. top most at a highest level in the tree) in your physically optimized query tree using any join algorithm with which you are familiar or which you can devise yourself? State how many buffer pages would be required to achieve the lowest possible cost. Provide a brief explanation in support of your answer. (5 marks) FIGURE 1: Relational Algebra tree for the given SQL query. Page 3 of 8 January 2006 CM0036 Advanced Databases Part B (Relational Algebra) You have been asked by the management of OGL to get the answers to the following queries from the database. In each case, consult the database schema, compose the query, and write it as a relational algebra expression that returns the required data. (I) List the Ids and Descriptions of the Products with StdCostPerUnit more than StdLabCostPerUnit. (1 mark) (II) List the Ids and Names of those Employees who work on orders that are in progress. (2 marks) (III) List the Ids and Descriptions of the Products that are neither produced at any industrial unit nor have been ordered by customers. (2 marks) Page 4 of 8 January 2006 CM0036 Advanced Databases Question 2 Part A (I) (Object-Oriented Databases) Using ODL, define an object-oriented representation of the following classes together with the association classes and the associations in which these classes participate: (a) (b) (c) (d) IndustrialUnit Product WorkOrder Employee [Note: You may omit non-key attributes of the above classes in your answer.] (8 marks) (II) This part requires you to write queries using both SQL and OQL and compare them. (a) Write a query in OQL over the ODL representation from your answer to part (I) for listing the Ids and Descriptions of the Products, which have 5 or more orders placed on 20 DEC 2005. (4 marks) (b) Express the same query over the equivalent relational representation (given in the Appendix) using SQL. (2 marks) (c) Compare and contrast the OQL and SQL queries from your answers to sub-parts (a) and (b) above. (2 marks) Part B (I) (Object-Relational Databases) The development team of the OGL database system is undertaking an investigation into whether to adopt the object-relational features of Oracle 9i or rely on the core relational technology. In order to carry out the investigation, some of the classes in the UML class diagram in the Appendix need to be implemented as an object-relational subset of the OGL database. Using the object-relational features of Oracle 9i, define an object-relational representation of the following classes together with the association classes and the associations in which these classes participate: (a) IndustrialUnit (b) Materials [Note: You omit non-key attributes of the above classes in your answer.] (4 marks) (II) Write a query in object-relational SQL over the object-relational representation from your answer to part (I) for listing Ids and Descriptions of the Materials that are kept at 5 or more Industrial Units such that the stocklevel is high (i.e. ‘H’). (3 marks) (III) Discuss briefly the advantages and disadvantages of using the object-relational representation from your answer to part (I) compared to its relational equivalent in the Appendix. (2 marks) Page 5 of 8 January 2006 CM0036 Advanced Databases Question 3 Part A (Triggers) The OGL database needs some improvements. A number of update commands were originally encoded into the application software; however, it has been decided to use triggers in place of this coding. Triggers are required to automatically update Status column of WorkOrder table according to the following rules: Whenever a new order is entered into the database then the value of Status column should be set to ‘A’. (II) Whenever a labour usage is recorded for the first time against an order then the value of Status column should be set to ‘P’. (III) Whenever the CompDate column is assigned any value that is greater than the value of the corresponding OrderDate column then the value of Status column should be set to ‘C’. (IV) Whenever the ShipDate column is assigned any value that is equal to or greater than the value of the corresponding CompDate column then the value of Status column should be set to ‘S’. (I) Define triggers for implementing each of the above rules (one trigger for each rule) using either: SQL Plain English Part B (Max. of 13 marks) (Max. of 9 marks) (PL/SQL procedures) Oil and Grease Ltd process weekly wages of employees once a week. The process only involves those rows from the LabourUsage table that have ‘N’ value under the Posted column. For each such row, first the value of the Posted column is set to ‘Y’. Then the year to date earnings, tax and national insurance contributions of the corresponding employees are updated as follows: Column YtdTax YtdNICont YtdEarnings What needs doing? From the gross weekly wage (i.e. based on Hours x HourlyRate), calculate tax depending on the value TaxCode and add it to the value of the corresponding YtdTax column as follows: 10%, 20%, 30% and 40% for the TaxCode of 1, 2, 3 and 4 respectively. From the remaining gross weekly wage, take out national insurance contributions at the rate of 10% and add it to the corresponding value of YtdNICont column. Add the net weekly wage (i.e., after taking out tax and national insurance contribution from the weekly gross wage) to the corresponding value of YtdEarnings column. Write a PL/SQL procedure for implementing the above process. Note that you must make use of cursor(s). (12 marks) Page 6 of 8 January 2006 CM0036 Advanced Databases APPENDIX Oil and Grease Limited (OGL) Database System OGL is a company that produces bespoke components for the auto trade industry within Europe. The company produces (built to order) a number of mechanical products and components at various industrial units. Materials that can be used in manufacturing products are held in an inventory register. Customers’ order details are held in work order. What materials are used on what products are held in a material usage register. Information about which employees work on which orders is kept in a labour usage register. In order to access information quickly and to ensure that all past records are available for audit purposes, the company developed a database. Figure 2 shows a UML class diagram, which provides a conceptual model of the database. Table 1 details the relations/tables used in an implementation of the database using a relational database system. Figure 2: UML Class Diagram for the OGL Database Page 7 of 8 January 2006 CM0036 Advanced Databases Domains/Data Types: ID = CHAR(6) LTXT = VARCHAR(50) STXT = VARCHAR(30) DEC = Decimal(8, 2) INT = Number(6) Note: The size of Date column or attribute is 8 bytes. IndustrialUnit (UnitId: ID, Location: LTXT, Country: LTXT) Product (ProdId: ID, Desc: LTXT, StdCostPerUnit: DEC, StdLabCostPerUnit: DEC) IndUnitProduct (UnitId*: ID, ProdId*: ID) Employee (EmpId: ID, EmpName: STXT, YtdEarnings: DEC, YtdTax: DEC, YtdNICont: DEC, UnitId*: ID, TaxCode: INT) Materials (MatId: ID, Desc: LTXT) Inventory (UnitId*: ID, MatId*: ID, CostPerUnitCurrent: DEC, QtyAtHand: INT, StockLevel: CHAR) WorkOrder (WorkOrderId: ID, Qty: INT, UnitPrice: DEC, OrderDate: Date, PromiseDate: Date, CompDate: Date, ShipDate: Date, Status: CHAR, CustID*: ID, ProdID*: ID) NOTE: The main purpose of including the Status column in WorkOrder table/class was to enable smooth handling of orders. The possible values for the Status column are: ‘A’ for acknowledged; ‘P’ for in progress; ‘C’ for completed; and ‘S’ for shipped. LabourUsage (EmpId*: ID, WorkOrderId*: ID, WorkDate: Date, Hours: INT, HourlyRate: DEC, Posted: CHAR) MaterialUsage (MatId*: ID, WorkOrderId*: ID, WorkDate: Date, MatQty: INT, CostPerUnitActual: DEC) Customer (CustId: ID, CustName: STXT, Address: LTXT, PostCode: CHAR(8), City: STXT, Country: STXT) Table 1: Relational Schema for the OGL Database Page 8 of 8 January 2006 CM0036 Advanced Databases
© Copyright 2026 Paperzz