Computer Science 4611
Database Management Systems

Programming Assignment 4
System Catalog (80 points)
Due Tuesday, April 17 2001


In programming assignments 2-5, you will implement a simple DBMS. For an overview of how you will construct the DBMS, read this page. For this assignment you will implement the system catalog. You will use the previously provided code for the Disk Space Manager, your code for the Buffer Manager layer, and your code for Heap Files from previous assignment.s

You can find your team assignment here. You should begin by reviewing the book information on system catalogs. This material has also be covered in class. Your Catalog code will make extensive use of your Heap File code (the two main relations in the Catalog, the Relation relation and the Attribute relation will both be maintained as specializations of Heap File objects.

To make a local copy of the code you need to implement you should download the file cat.tar.Z. This is a tared archive file. To unpack this file you should do the following:

  % uncompress cat.tar
  % tar xvf cat.tar

This will create a directory Catalog that contains the code provided to you as well as skeletons for the code you need to write. This code comes with a provided make file makefile. It is unlikely you will need to modify this file (the only files you should need to change are attrcatalog.C, relcatalog.C, and catalogutil.C). The directory also includes a number of files that you will likely not need to change (though you may adjust things as you need). These will be discussed below. The code also comes with a testing program cat_tester. This test program is a menu oriented program that allows you to perform various commands to your database. Note that you must include the name of the database as an argument to cat_tester in order for the database to exist once you quit (otherwise, a temporary database is created and deleted at the end). This test program is automatically constructed by the makefile by simply typing "make". To recompile all of the code you first type "make clean" which will eliminate all current .o and executable files and then type "make" again to recompile. Note that you will have to copy your buf.h, buf.C, hfpage.h, hfpage.C, heapfile.h, heapfile.C, scan.h and scan.C files to this directory for it to compile.

For those who did not get the first two parts of the project working, you can download the archive cata.tar.Z. This has two libraries with working copies of the earlier code.

The System Catalog Interface

For our database, the system Catalog will consist of two basic relations, the Relation relation and the Attributes relation. Note that in a real system with indexes there would likely be at least one more relation, an Index relation. The files catalog.h and catalog.C contain the basic pieces for creating a system catalog -- the code attempts to create a Relation relation and an Attributes relation.

The Relation relation is implemented with the files relcatalog.h and relcatalog.C. These files have a partial set of code which you may or may not find useful. If it is not useful, you may discard what is there and replace it with your own code (though you may need to adjust the file cat_tester accordingly).

The Relation relation has tuples with four fields, a field relName (corresponding to the name of the relation and its corresponding file), attrCnt (the count of the number of attributes), and numTuples and numPages (which may be used in a future project on optimization, for now, set the values of these attributes to 100 and 20 initially).

The Attributes relation is implemented with the files attrcatalog.h and attrcatalog.C. These files have a partial set of code which you may or may not find useful. If it is not useful, you may discard what is there and replace it with your own code (though you may need to adjust the file cat_tester accordingly).

The Attributes relation has tuples with six fields, a field relName (the relation the attribute is part of), attrName (the name of the attribute), attrOffset (the offset of the attribute in the actual file), attrPos (the position of the attribute, counting from 1), attrType (the type of the attribute), and attrLen (the length of the attribute in bytes).

It may help to look at the files batter1, 2, and 3.out which show the results of some sample commands to cat_tester (see below). These files output the contents of the Relation and Attributes relations periodically and should make these files fairly clear.

Another file you will need to complete is catalogutil.C. This file contains routines that are used by the catalog tester program for (1) inserting a record into a relation, (2) deleting a record from a relation, and (3) loading a set of data from a file into a relation.

Finally, the directory includes two files, tuple.h and tuple.C. These files contain low level routines for manipulating the memory retrieved from a file and treating that memory as a tuple. Some examples of how this routine is used can be seen in attrcatalog.C and relcatalog.C. You are welcome to rewrite these routines and discard these files if you wish to perform the low level operations involving memory yourself.

Error Protocol and Debugging

Be sure to follow the error protocol described in new_error.h. Note that you will likely want to add new error codes and new error messages to the tables provided for you.

The make file compiles the code using the -g flag. This means that you can debug the executables produced using gdb. I have also set up the code with a command line debugging system. When running either of the test programs you can add command line arguments of db, bm, hf, or gory. These turn on debugging flags in the Disk Space module (db), Buffer Manager module (bm), HeapFile (hf) and some extended (gory details) flags (gory). Note that you may want to add debugging commands in your Buffer Manager code following this protocol.

What to Turn In, and When

Print out your versions of all of the files you changed. You should test your code using the test routine cat_tester and print out the results. Try to completely test your code. In your test directory I have included a set of files menu_commands.batter1, 2, and 3, that have a set of commands you can try. These command sets are meant to be run initially on a new database (set 1) and then on the successive resulting databases (2 and 3). Note that these tests are not comprehensive, you should plan on running more tests.

Once you have completed testing, write up a team report of how your code is implemented. This report should give an overview of how you completed the classes for the system Catalog. 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.