CS357: Database System Implementation
Homework Assignment 8 -- Parsing and Planning
| Given: |
Monday, 31 March |
| Due Date: |
Wednesday, 9 April |
1. Do problem 17.4 in the text.
2. Do problem 17.5 in the text.
3. Do problem 18.3 in the text.
4. A select query in standard SQL can use the AS keyword
to rename the fields of the output table. For example, consider
the following query:
select sname, dname as major from student, dept where majorid = did
The output table of this query contains the name of students and their
majors; the renaming means that the schema of the output table is (sname, major) instead of (sname, dname). In general, any field of the output table can be renamed, which means
that the AS keyword is optional for each field of the select clause.
a) What changes are needed to the SimpleDB SQL grammar?
Write the new grammar rules, as well as any existing rules that
need changing.
b) Modify the SimpleDB parser to correspond to your revised
grammar. You will need to find a way to pass the names of the renamed
fields to the planner. Currently, class QueryData has a method fields
that returns a collection of all field names in the select clause. You
need to revise the method fields
so that the collection contains both the field names and their
renamings. (NOTE: The best way by far to do this is to
create a new class whose objects hold the old and new fieldnames.)
c) Modify the SimpleDB class BasicQueryPlanner to handle the renaming. Currently, the method createPlan creates a project plan on top of a select plan on top of zero or more product plans. Your modification should create some rename plans on top of the project plan, one for each field that is getting renamed. Use the classes RenamePlan and RenameScan
that you wrote in the previous assignment. (If you didn't get
those classes to work, then email me and I will send you my
versions.)
d) Test your code. For example, run the SQLInterpreter
and give it some interesting renaming queries to execute. I don't
want you to hand in any test program, but you should have fun trying
out the changes to the system. This is one of the best parts of
modifying the database system -- you actually get to change SQL!
Please hand in your responses to questions 1, 2, 3, and 4a, plus a
hardcopy of any file you create or modify for questions 4b and 4c, with
changes clearly marked.