Computer Science 4611
Database Management Systems

Programming Assignment 5
Query Evaluation (70 points)
Due Friday, May 9, 2003 (NO LATE PROGRAMS!!)


In this last part of the assignment you will complete the query language you have been building in programs 3 and 4. In this assignment you should build on the code you have been completing. In the routine evaluate_query you should set up a mechanism to output the result of each type of query.

The Query Language

Queries come in four basic forms:

  1. [ RelationName RelationVariable ] - this is the most basic form. This type of query simply establishes a connection between a named relation and a corresponding relation variable. This type of query should mostly appear as a part of a more complex query (see below). It should establish a connection to that particular relation through the relation variable. If this query is used at the top level the resulting relation should simply be printed in full in a nice form.
  2. PROJECT ( RelVar1.AttrName1 , RelVar2.AttrName2, ... ) ( QueryItem ) - a project should take a subquery item QueryItem (the result of a project, select or join query or a connection to a relation (1) above) and project down to these fields (note that duplicates need not be eliminated). The fields to be projected to should appear as a list. Each attribute is indicated using relation variables (from QueryItem) and corresponding attribute names separated by a period.
  3. SELECT ( Condition ) ( QueryItem ) - a select has a similar syntax to the previous DELETE item, except that rather than deleting the matching tuples, the matching tuples should simply be shown in a nice table.
  4. JOIN ( Condition ) ( QueryItem1 ) ( QueryItem2 ) - a join is applied to all pairings of tuples from the tuples generated by query items QueryItem1 and QueryItem2. A pair should appear in the output when the condition Condition is true about the tuples being considered from QueryItem1 and QueryItem2. Note that the join condition may mention relation variables from both QueryItem1 and QueryItem2.

What To Add

You should complete the code you worked on in program 4. The basic pieces for the queries are already attached to the code. You will likely want to add evaluation routines to the nodes corresponding to PROJECT, SELECT and JOIN queries.

NOTE NOTE:In order to make this project easier and because it is coming at the end of the semester, you will only be responsible for implementing each operation indenpendently. You do not need to implement operators such that they can be composed. For example, you will need to implement code to work on queries like this:

  PROJECT (S.sid, S.sname) ([Sailors S]);
  SELECT (S.sid == 5) ([Sailors S]);
  JOIN (S.sid == R.sid) ([Sailors S]) ([Reserves R]);

but not for a query like this:

  PROJECT (S.sname) (SELECT (S.sid == 5) ([Sailors S]));

You are only responsible for implementing queries that have one PROJECT, SELECT or JOIN operation.

Implementation Requirements

There are no special implementation requirements. You may implement any access method you like for resolving project and select queries and any join mechanism.

Extra Credit

This program will include a number of opportunities for extra credit. You may complete any of the following (note that extra credit points will not be considered when assigning grade breakpoints, but will be used in final grade assignment).

What to Turn In, and When

Print out your versions of all the code you add. You should test your code by showing examples of the various query commands. Note that you should test your code extensively considering many possible combinations of commands. You should hand in copies of all of your tests. Next, write up a team report of how your code is implemented. This report should give an overview of how you completed the various sections of this project. It should also discuss the algorithms you used to solve the problem. This report should be at least two pages long but no longer than four pages. Each team member should also write up an individual report (at least half a page but no more than a page) discussing their contributions to the coding process and how the overall team interaction went.

You must also submit your code electronically (but only once for each team). To do this go to the link d.cgi and follow the directions for uploading a file.

To make your code easier to check and grade please use the following procedure for collecting the code before uploading it: