Tuples

Introduction

Each record in a relation is a collection of bytes that is cast as an object of type Tuple. Only implementors of access methods, heap files and relational operators need to worry about how the bytes are utilized . Others can treat them as just a collection of bytes.

Tuples may have attributes of three types: strings (up to 255 characters), integers, and real numbers (floats, in C++).

Because padding of bytes is needed to align integers and floats, the exact number of bytes in a Tuple is not known ahead of time. When tuples are created, a large number of bytes must be allocated. Then the attributes list (for example: string, int, float) is passed to the tuple and the tuple is constructed. During the Tuple construction, padding is performed and the actual size of the Tuple with those attributes is determined.

For our (string,int,float) example tuple, with the maximum length of the string being 5, and the architecture having 4-byte ints and floats, both requiring 4-byte alignment, the tuple internals would look like:

Tuple Representation In Memory
string padding int float
5 bytes 3 bytes 4 bytes 4 bytes

The padding was added after the string to allow the int field to be placed at an offset that is a multiple of 4, as required by the example machine's architecture.

Design Decisions

Padding was chosen over copying for no particular reason. The amount of space wasted due to padding may not offset the time that is needed to copy the data into aligned space when it is needed; thus, a variant that uses copying could be used instead.

In Minibase, a tuple must fit on a single page.

Click here for the public interface.

Back to the List of Components
Back to the Minibase Home Page