The Databases Course

Exercise No. 9

Transitive Closure - Practical

Due on January 25th by midnight

The Example Database Schema: A manufacturing firm buys basic parts and builds composite parts out of them. There is a cost to every basic part, and a cost to assembling a composite part out of all its basic parts (which doesn't include the cost of the basic components). Composite parts may be composed from other composite parts as well. The information about parts is stored in the Base_Parts and Composite_Parts tables, and the Made_From relation specifies which and how many basic parts each composite part needs. Made_from(car, wheel, 4) indicates that a car is made using four wheels.

Base_Parts (pno, cost)
Composite_Parts (pno, assembly_cost)
Made_From (pno1, pno2, qty)

Standard assumptions can be made about the database:

Write a C program with embedded SQL statements to do the following:

You should compute the relation Costs(pno, total_cost), where total_cost is the total cost for making part pno - including the costs of all the base parts and the costs of assembling the composite parts. This relation should contain a record for every part (both basic and composite). The Costs table should be created as a new table - pno is of type varchar(15) and total_cost is of type number(10). These are also the types that are used by the existing tables. Your program should create and fill the Costs table, print it to the screen, and destroy it.

Your should use a reasonable amount of main memory space, since the above relations can be very large. You may use tables to store intermediate results. Tuples containing null values should be ignored - such parts needn't be used in your computations, and shouldn't appear in the final Costs table.

The input size of this problem is the total number of parts n. Your algorithm should use at most O(log n) queries. Every SELECT statement counts as one query; when using cursors, every time you OPEN the cursor it counts as one query.

When encountering any type of error you should print a detailed message to the standard error stream, and terminate the program emmidiately with an error code 1. If the program ends without an error, it should return an error code 0.

Your program should be superbly documented. Your README file, along with the usual information, must also include the pseudo-code for the algorithm you use, and an analysis of the number of queries it performs.

You should submit: