Minibase Assignment #3: Index Nested Loops Join

Assigned on Wednesday, May 15.
Due on Wednesday, May 22 at 5 PM.

Introduction

In this assignment, you will implement the index nested loops join algorithm for equijoins. You will be given libraries for the lower layers (Disk Space Manager, Buffer Manager, Heap File, and B+ Tree), and some driver routines to test the code.

You should begin by reading Chapter 12 of the textbook, particularly the description of Index Nested Loops Join in Section 12.5.1.


Getting Started

Create a directory for the assignment, and change to that directory. Copy the file /usr/local/mini_hwk/assign/INL_Join/src/Makefile to your current directory. To obtain the rest of the files that you will need, type make setup. The files are:

You can find other useful header files in /usr/local/mini_hwk/assign/INL_Join/include .


What You Have to Implement

class index_nested_loop{
public:
index_nested_loop(
char* filename1, // Name of heap file for relation R
int len_in1, // # of columns in R
AttrType in1[], // Array containing field types of R
short t1_str_sizes[], // Array containing size of columns in R
int join_col_in1, // The join column of R

char* filename2, // Name of heap file for relation S
int len_in2, // # of columns in S
AttrType in2[], // Array containing field types of S
short t2_str_sizes[], // Array containing size of columns in S
int join_col_in2, // The join column of S

char* filename3, // Name of heap file for join results
IndexType in_type, // Index type for inner relation (S)
Status& s // Status of constructor
);

~index_nested_loop();
};

The index_nested_loop constructor joins two relations R and S, represented by the heap files filename1 and filename2, respectively, using the index nested loops join algorithm. The columns for relations R (S) are numbered from 0 to len_in1-1 (len_in2-1). You should concatenate each matching pair of records and write the concatenated records into the heap file filename3.

You will need to use the following classes, which are given: HeapFile, Scan, BTreeFile and BTreeFileScan. You will call BTreeFile methods to build a B+ tree index for the inner heap file S. Then you scan the outer heap file R; for each tuple in the outer heap file R, retrieve the matching tuples in S by scanning the B+ tree on the inner heap file S.

You can assume that the value of the input parameter in_type will always be B_Index.

The parameter s is a return parameter. If all goes well, the constructor will finish and return s==OK. If an error occurs, you should exit the constructor and return an error code in s.

The index_nested_loop destructor should destroy the B+ tree index that you created for S, in addition to the usual clean up of local and temporary state.

You are expected to handle variable length keys in this assignment. You do not need to worry about alignment (if you do not understand what alignment is, you can safely ignore the rest of this paragraph). You may assume that the length of all columns will be a multiple of four, so that all columns are aligned on a four-byte boundary.


Notes on Some of the Functions You Will Use


Error Reporting in the Code

As in previous project assignments, you should follow the Minibase Error Protocol . The subsystem code for the index_nested_loop class is JOINS.

Handing in Your Code

Handing in Your Code

Use hsp to hand in the entire directory containing your code. Do not submit the individual files, but rather submit the directory as a whole. For example, if I am sitting in the directory above INL_Join, I would execute the following command:

hsp musicant CS395 INL_Join

Good luck!