EECS 484 Projects | B+ Tree and Query Optimizer
Project 4: B+ Tree and Query Optimizer
| Worth | Released | Due |
|---|---|---|
| 177 points | Fall 2026 | December 01, 2026 |
Introduction
There are two parts to this project. The first part will require you to implement certain B+ tree functions. The second part will give you hands-on experience in creating indexes and understanding query optimizers in PostgreSQL. The project zip archive will provide the starter files and the exact files, prototypes, and build commands for Part 1.
This page is the project specification. PostgreSQL installation and local-server troubleshooting are documented separately in the Local PostgreSQL Setup Guide.
Submissions
This project is to be done in teams of 2 students. Both members of a team receive the same score. Be sure to create your team on the Autograder.
The starter archive will be posted with the project materials.
Honor Code
By submitting this project, you are agreeing to abide by the Honor Code: “I have neither given nor received unauthorized aid on this assignment, nor have I concealed any violations of the Honor Code.” You may not share answers with other students actively enrolled in the course outside of your teammate, nor may you consult with students who took the course in previous semesters. You are, however, allowed to discuss general approaches and class concepts with other students, and you are also permitted and encouraged to post questions on Piazza.
If you are retaking the class, you must work alone for the projects you worked on in previous semesters. For projects that you have not worked on in previous semesters, you are free to find a teammate.
Part 1: B+ Tree Implementation (77 points)
For this part of the project, you are expected to implement basic functionality to a B+ tree using the algorithms discussed in class. The required operations are:
Btree::insert()Btree::remove()Btree::search_range(), returning every item in the inclusive range
Duplicates should not be stored in this B+ tree. We have provided skeleton code as well as implementations of some basic functions so that you do not have to start from scratch. It is advised that you familiarize yourself with B+ tree operations thoroughly before starting.
Download the P4 starter files before beginning Part 1.
We have provided you with an implementation of Btree::search() as a simple example of how you can interface with the skeleton code. We have also provided basic operations for the B+ tree node classes. The starter archive identifies which functions are given and which functions you must implement.
What you need to do
- Implement
Btree::insert()as described in lecture. Prefer splitting nodes over redistribution. - Implement
Btree::remove()as described in lecture. Prefer redistribution over merging. - Implement
Btree::search_range(). Include allData*values between the given range, inclusive.
Specific rules for splitting, redistribution, and merging
Follow these general rules when implementing the above functions:
- When splitting:
- Push the smallest value of the newly split right node up to the parent.
- For leaf nodes, first split existing nodes evenly between the left and right node. Then insert the new value into the appropriate, valid node based on the existing values and the insert value. There are cases where both nodes are valid. In these cases, add the value to the left node.
- When redistributing:
- For leaf nodes, update the appropriate parent node with the smallest value in the right node. Redistribute with any valid left or right nodes.
- For inner nodes, only redistribute with sibling nodes.
- Prefer redistribution with the right node over the left node.
- The right-hand side will always have more values than the left-hand side, if not equal. The right-hand side and left-hand side should have the same number of values. When this is impossible due to an odd number of values, the right-hand side should have one more value than the left-hand side.
- When merging:
- For leaf nodes, merge with any valid left or right nodes.
- For inner nodes, only merge with a sibling node.
- Prefer merging with the right node over the left node.
- Always merge the right node values into the left node.
Remember to maintain the private variable size while implementing the above functions. The capacity of each inner node must always be between (BTREE_FANOUT - 1) / 2 and BTREE_FANOUT - 1, except when it is the root node. The capacity of leaf nodes must be between BTREE_LEAF_SIZE / 2 and BTREE_LEAF_SIZE, except when the leaf is the root node.
BTREE_FANOUT is guaranteed to be odd and BTREE_LEAF_SIZE is guaranteed to be even. Always use the constants defined in constants.h, such as BTREE_LEAF_SIZE and BTREE_FANOUT. The B+ tree should initially start empty, with its root node being a Bnode_leaf*. When this leaf node has to split, change the root node to a Bnode_inner. The root should turn back into a Bnode_leaf when its size is less than BTREE_LEAF_SIZE.
Test cases
We have provided you with a printing function that prints your B+ tree to an output stream. The grader will compare the required output to the solution's output. The required comparison lines begin with @@@; these are the only lines that will be compared during grading.
We have provided a main test driver and an equivalent expected output as a starting point for determining whether your B+ tree is correct. It is highly recommended that you create your own test cases and parse the output yourself to see if you have implemented the algorithms correctly.
An Btree::isValid() function is provided to test whether your B+ tree has maintained ordering correctly. This does not check whether your B+ tree is implemented correctly; it serves merely as a sanity check and catches obvious errors.
Part 1 submission and grading
Download the P4 starter files before beginning Part 1.
Please make a group submission if you have a partner. Submit to the Autograder the files required by the starter archive, including the implementation source files, headers, and Makefile. Once unzipped, the project must build using the documented command. The grader will supply its own test driver when required.
You will receive points based on how many of the Autograder test cases you pass. The Autograder submission policy is described on the assignment page.
Up to 7 points may be deducted for style problems such as obfuscated or uncommented code, unnecessary repetition, avoidable extra I/O, or debug output that violates the required output contract.
Part 2: PostgreSQL Query Optimizer (100 points)
The starter file can be found here: P4 Part 2
The second part of the project will give you some hands-on experience in creating indexes and understanding query optimizers in PostgreSQL. This part uses PostgreSQL; it is not a SQL*Plus, Oracle, or SQLite assignment.
Environment
Use a supported local PostgreSQL installation, preferably the current stable release available from the official PostgreSQL download page. The Local PostgreSQL Setup Guide covers Windows, macOS, and Linux.
Dataset and exercises
In this assignment, we will work with a small subset of the Dell DVD Store e-commerce dataset. This dataset has information about customers, products, and orders. Although the dataset contains eight tables, the exercises focus on the following two tables:
- Customers (
customerid,firstname,lastname,city,state,country, and other attributes) - Orders (
orderid,orderdate,customerid,netamount,tax,totalamount)
Download the Dell DVD Store data and load it into your local PostgreSQL database using the project materials and the Local PostgreSQL Setup Guide. You can inspect a table's schema and indexes with \\d+ tablename.
The exercises will ask you to create and remove indexes, run SQL queries, and inspect the query optimizer's choices using PostgreSQL EXPLAIN commands. Bitmap scans are not covered in this class, so the driver file setup_db.sql ends with SET enable_bitmapscan = off;. A SET only lasts for the current session, so run SET enable_bitmapscan = off; again every time you open a new psql session, and include it at the top of P3queries.sql.
Answers and query-plan output may differ slightly across different runs because of database statistics, cache state, data size, and other local execution conditions.
Part 2 submission and grading
Submit one document to Gradescope Project 4 Query Optimization. Only one partner needs to submit, and be sure to add your partner to the submission. Be sure to include all operations on the database, output, and answer as requested on the spec.
If you are working with a partner, make one group submission. The current course submission policy applies to this part of the project.
Helpful Links
The following are links to Postgres documentation relevant to this assignment. Be prepared to look up the documentation as you work on the exercises.
-
Full PostgreSQL 18 documentation:
https://www.postgresql.org/docs/18/index.html -
Statistics used by the query planner:
https://www.postgresql.org/docs/18/planner-stats.html -
How to manipulate the query planner (such as disabling the use of a join algorithm):
https://www.postgresql.org/docs/18/runtime-config-query.html -
Syntax of the
EXPLAINcommand:
https://www.postgresql.org/docs/18/sql-explain.html -
How to use the
EXPLAINcommand and interpret its output:
https://www.postgresql.org/docs/18/using-explain.html -
Creating an index:
https://www.postgresql.org/docs/18/sql-createindex.html -
Creating a clustered index:
https://www.postgresql.org/docs/18/sql-cluster.html