Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,33 @@ jobs:
matrix:
config:
- {
name: "Ubuntu 22.04 GCC",
os: "ubuntu-22.04",
name: "Ubuntu 24.04 GCC",
os: "ubuntu-24.04",
cc: "/usr/bin/gcc",
cxx: "/usr/bin/g++",
format: "/usr/bin/clang-format-14",
tidy: "/usr/bin/clang-tidy-14",
format: "/usr/bin/clang-format-15",
tidy: "/usr/bin/clang-tidy-15",
}
- {
name: "Ubuntu 22.04 Clang",
os: "ubuntu-22.04",
cc: "/usr/bin/clang-14",
cxx: "/usr/bin/clang++-14",
format: "/usr/bin/clang-format-14",
tidy: "/usr/bin/clang-tidy-14",
name: "Ubuntu 24.04 Clang",
os: "ubuntu-24.04",
cc: "/usr/bin/clang-15",
cxx: "/usr/bin/clang++-15",
format: "/usr/bin/clang-format-15",
tidy: "/usr/bin/clang-tidy-15",
}
- {
name: "macOS 13 (Ventura) AppleClang",
os: macos-13,
format: "/usr/local/opt/llvm@14/bin/clang-format",
tidy: "/usr/local/opt/llvm@14/bin/clang-tidy",
name: "macOS 14 (Sonoma) AppleClang",
os: macos-14,
format: "/opt/homebrew/opt/llvm@15/bin/clang-format",
tidy: "/opt/homebrew/opt/llvm@15/bin/clang-tidy",
}
- {
name: "macOS 15 (Sequoia) AppleClang",
os: macos-15,
format: "/opt/homebrew/opt/llvm@15/bin/clang-format",
tidy: "/opt/homebrew/opt/llvm@15/bin/clang-tidy",
}
steps:
- uses: actions/checkout@v2

Expand Down Expand Up @@ -75,13 +81,6 @@ jobs:
working-directory: ${{github.workspace}}/build
run: make check-clang-tidy

- name: Check Tests (Ubuntu)
if: runner.os == 'Linux'
working-directory: ${{github.workspace}}/build
run: make build-tests && make check-public-ci-tests

- name: Check Tests (OSX)
if: runner.os == 'macOS'
- name: Check Tests
working-directory: ${{github.workspace}}/build
# Disable container overflow checks on OSX
run: make build-tests && make check-public-ci-tests
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,6 @@ docs/dev

# Submission zip files
*.zip

# LLM Stuff
.aider*
19 changes: 10 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # For clang-tidy.
set(BUILD_SHARED_LIBS OFF) # We expect external libraries to be linked statically.
set(CMAKE_CXX_STANDARD 17) # Compile as C++17.
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Require C++17 support.
set(CLANG_VERSION 15) # If you change this, make sure you change `packages.sh`

project(BusTub
VERSION 2023.1
VERSION 2025.8
DESCRIPTION "The BusTub Relational Database Management System (Educational) @ https://github.com/cmu-db/bustub"
LANGUAGES C CXX
)
Expand Down Expand Up @@ -38,19 +39,19 @@ endif()

# Expected directory structure.
set(BUSTUB_BUILD_SUPPORT_DIR "${CMAKE_SOURCE_DIR}/build_support")
set(BUSTUB_CLANG_SEARCH_PATH "/usr/local/bin" "/usr/bin" "/usr/local/opt/llvm/bin" "/usr/local/opt/llvm@14/bin"
"/opt/homebrew/opt/llvm@14/bin/")
set(BUSTUB_CLANG_SEARCH_PATH "/usr/local/bin" "/usr/bin" "/usr/local/opt/llvm/bin" "/usr/local/opt/llvm@${CLANG_VERSION}/bin"
"/opt/homebrew/opt/llvm@${CLANG_VERSION}/bin/")

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION MATCHES "^14.")
if(CMAKE_CXX_COMPILER_VERSION MATCHES "^${CLANG_VERSION}.")
message(STATUS "You're using ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
else()
message(WARNING "!! We recommend that you use clang-14 for developing BusTub. You're using ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, a different version.")
message(WARNING "!! We recommend that you use clang-${CLANG_VERSION} for developing BusTub. You're using ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, a different version.")
endif()
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
message(STATUS "You're using ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
else()
message(WARNING "!! We recommend that you use clang-14 for developing BusTub. You're using ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, which is not clang.")
message(WARNING "!! We recommend that you use clang-${CLANG_VERSION} for developing BusTub. You're using ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}, which is not clang.")
endif()

# #####################################################################################################################
Expand All @@ -64,7 +65,7 @@ enable_testing()

# attempt to find the binary if user did not specify
find_program(CLANG_FORMAT_BIN
NAMES clang-format clang-format-14
NAMES clang-format clang-format-${CLANG_VERSION}
HINTS ${BUSTUB_CLANG_SEARCH_PATH})

if("${CLANG_FORMAT_BIN}" STREQUAL "CLANG_FORMAT_BIN-NOTFOUND")
Expand All @@ -75,7 +76,7 @@ endif()

# attempt to find the binary if user did not specify
find_program(CLANG_TIDY_BIN
NAMES clang-tidy clang-tidy-14
NAMES clang-tidy clang-tidy-${CLANG_VERSION}
HINTS ${BUSTUB_CLANG_SEARCH_PATH})

if("${CLANG_TIDY_BIN}" STREQUAL "CLANG_TIDY_BIN-NOTFOUND")
Expand All @@ -87,7 +88,7 @@ else()
endif()

find_program(CLANG_APPLY_REPLACEMENTS_BIN
NAMES clang-apply-replacements clang-apply-replacements-14
NAMES clang-apply-replacements clang-apply-replacements-${CLANG_VERSION}
HINTS ${BUSTUB_CLANG_SEARCH_PATH})

if("${CLANG_APPLY_REPLACEMENTS_BIN}" STREQUAL "CLANG_APPLY_REPLACEMENTS_BIN-NOTFOUND")
Expand Down
15 changes: 8 additions & 7 deletions build_support/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
## build and run the DBMS.
##
## Supported environments:
## * Ubuntu 22.04 (x86-64)
## * Ubuntu 24.04 (x86-64)
## * macOS 13 Ventura (x86-64 or ARM)
## =================================================================

CLANG_VERSION=15

main() {
set -o errexit

Expand Down Expand Up @@ -41,9 +43,8 @@ install() {
LINUX)
version=$(cat /etc/os-release | grep VERSION_ID | cut -d '"' -f 2)
case $version in
18.04) install_linux ;;
20.04) install_linux ;;
22.04) install_linux ;;
24.04) install_linux ;;
*) give_up ;;
esac
;;
Expand Down Expand Up @@ -77,7 +78,7 @@ install_mac() {
brew ls --versions coreutils || brew install coreutils
brew ls --versions doxygen || brew install doxygen
brew ls --versions git || brew install git
(brew ls --versions llvm | grep 14) || brew install llvm@14
(brew ls --versions llvm | grep ${CLANG_VERSION}) || brew install llvm@${CLANG_VERSION}
brew ls --versions libelf || brew install libelf
}

Expand All @@ -87,9 +88,9 @@ install_linux() {
# Install packages.
apt-get -y install \
build-essential \
clang-14 \
clang-format-14 \
clang-tidy-14 \
clang-${CLANG_VERSION} \
clang-format-${CLANG_VERSION} \
clang-tidy-${CLANG_VERSION} \
cmake \
doxygen \
git \
Expand Down
2 changes: 1 addition & 1 deletion src/binder/bind_insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ auto Binder::BindUpdate(duckdb_libpgquery::PGUpdateStmt *stmt) -> std::unique_pt
for (auto cell = root->head; cell != nullptr; cell = cell->next) {
auto target = reinterpret_cast<duckdb_libpgquery::PGResTarget *>(cell->data.ptr_value);
auto column = ResolveColumnRefFromBaseTableRef(*table, std::vector{std::string{target->name}});
target_expr.emplace_back(std::make_pair(std::move(column), BindExpression(target->val)));
target_expr.emplace_back(std::move(column), BindExpression(target->val));
}

return std::make_unique<UpdateStatement>(std::move(table), std::move(filter_expr), std::move(target_expr));
Expand Down
6 changes: 3 additions & 3 deletions src/binder/fmt_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ auto BoundCTERef::ToString() const -> std::string {
}

auto BoundSubqueryRef::ToString() const -> std::string {
std::vector<std::string> columns;
std::vector<std::string> columns(select_list_name_.size());
for (const auto &name : select_list_name_) {
columns.push_back(fmt::format("{}", fmt::join(name, ".")));
}
Expand All @@ -54,12 +54,12 @@ auto BoundSubqueryRef::ToString() const -> std::string {
}

auto BoundWindow::ToString() const -> std::string {
std::vector<std::string> partition_by;
std::vector<std::string> partition_by(partition_by_.size());
for (const auto &expr : partition_by_) {
partition_by.push_back(expr->ToString());
}

std::vector<std::string> order_bys;
std::vector<std::string> order_bys(order_bys_.size());
for (const auto &expr : order_bys_) {
order_bys.push_back(expr->ToString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/catalog/table_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void TableGenerator::FillTable(const std::shared_ptr<TableInfo> &info, TableInse
uint32_t num_inserted = 0;
uint32_t batch_size = 128;
while (num_inserted < table_meta->num_rows_) {
std::vector<std::vector<Value>> values;
std::vector<std::vector<Value>> values(table_meta->col_meta_.size());
uint32_t num_values = std::min(batch_size, table_meta->num_rows_ - num_inserted);
for (auto &col_meta : table_meta->col_meta_) {
values.emplace_back(MakeValues(&col_meta, num_values));
Expand Down
2 changes: 1 addition & 1 deletion src/execution/hash_join_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ HashJoinExecutor::HashJoinExecutor(ExecutorContext *exec_ctx, const HashJoinPlan
std::unique_ptr<AbstractExecutor> &&left_child,
std::unique_ptr<AbstractExecutor> &&right_child)
: AbstractExecutor(exec_ctx) {
if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) {
if (plan->GetJoinType() != JoinType::LEFT && plan->GetJoinType() != JoinType::INNER) {
// Note for Spring 2025: You ONLY need to implement left join and inner join.
throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/execution/nested_index_join_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace bustub {
NestedIndexJoinExecutor::NestedIndexJoinExecutor(ExecutorContext *exec_ctx, const NestedIndexJoinPlanNode *plan,
std::unique_ptr<AbstractExecutor> &&child_executor)
: AbstractExecutor(exec_ctx) {
if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) {
if (plan->GetJoinType() != JoinType::LEFT && plan->GetJoinType() != JoinType::INNER) {
// Note for Spring 2025: You ONLY need to implement left join and inner join.
throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/execution/nested_loop_join_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ NestedLoopJoinExecutor::NestedLoopJoinExecutor(ExecutorContext *exec_ctx, const
std::unique_ptr<AbstractExecutor> &&left_executor,
std::unique_ptr<AbstractExecutor> &&right_executor)
: AbstractExecutor(exec_ctx) {
if (!(plan->GetJoinType() == JoinType::LEFT || plan->GetJoinType() == JoinType::INNER)) {
if (plan->GetJoinType() != JoinType::LEFT && plan->GetJoinType() != JoinType::INNER) {
// Note for Spring 2025: You ONLY need to implement left join and inner join.
throw bustub::NotImplementedException(fmt::format("join type {} not supported", plan->GetJoinType()));
}
Expand Down
4 changes: 2 additions & 2 deletions src/include/binder/table_ref/bound_base_table_ref.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class BoundBaseTableRef : public BoundTableRef {
schema_(std::move(schema)) {}

auto ToString() const -> std::string override {
if (alias_ == std::nullopt) {
if (alias_ == std::nullopt || !alias_.has_value()) {
return fmt::format("BoundBaseTableRef {{ table={}, oid={} }}", table_, oid_);
}
return fmt::format("BoundBaseTableRef {{ table={}, oid={}, alias={} }}", table_, oid_, *alias_);
}

auto GetBoundTableName() const -> std::string {
if (alias_ != std::nullopt) {
if (alias_ != std::nullopt && alias_.has_value()) {
return *alias_;
}
return table_;
Expand Down
2 changes: 1 addition & 1 deletion src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ class Catalog {
}

auto GetTableNames() -> std::vector<std::string> {
std::vector<std::string> result;
std::vector<std::string> result(table_names_.size());
for (const auto &x : table_names_) {
result.push_back(x.first);
}
Expand Down
4 changes: 2 additions & 2 deletions src/include/execution/expressions/arithmetic_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ArithmeticExpression : public AbstractExpression {
Value lhs = GetChildAt(0)->Evaluate(tuple, schema);
Value rhs = GetChildAt(1)->Evaluate(tuple, schema);
auto res = PerformComputation(lhs, rhs);
if (res == std::nullopt) {
if (res == std::nullopt || !res.has_value()) {
return ValueFactory::GetNullValueByType(TypeId::INTEGER);
}
return ValueFactory::GetIntegerValue(*res);
Expand All @@ -62,7 +62,7 @@ class ArithmeticExpression : public AbstractExpression {
Value lhs = GetChildAt(0)->EvaluateJoin(left_tuple, left_schema, right_tuple, right_schema);
Value rhs = GetChildAt(1)->EvaluateJoin(left_tuple, left_schema, right_tuple, right_schema);
auto res = PerformComputation(lhs, rhs);
if (res == std::nullopt) {
if (res == std::nullopt || !res.has_value()) {
return ValueFactory::GetNullValueByType(TypeId::INTEGER);
}
return ValueFactory::GetIntegerValue(*res);
Expand Down
2 changes: 1 addition & 1 deletion src/include/primer/hyperloglog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "common/util/hash_util.h"

/** @brief Capacity of the bitset stream. */
#define BITSET_CAPACITY 64
static constexpr int BITSET_CAPACITY = 64;

namespace bustub {

Expand Down
6 changes: 3 additions & 3 deletions src/include/primer/hyperloglog_presto.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
#include "common/util/hash_util.h"

/** @brief Dense bucket size. */
#define DENSE_BUCKET_SIZE 4
static constexpr int DENSE_BUCKET_SIZE = 4;
/** @brief Overflow bucket size. */
#define OVERFLOW_BUCKET_SIZE 3
static constexpr int OVERFLOW_BUCKET_SIZE = 3;

/** @brief Total bucket size. */
#define TOTAL_BUCKET_SIZE (DENSE_BUCKET_SIZE + OVERFLOW_BUCKET_SIZE)
static constexpr int TOTAL_BUCKET_SIZE = (DENSE_BUCKET_SIZE + OVERFLOW_BUCKET_SIZE);

namespace bustub {

Expand Down
2 changes: 1 addition & 1 deletion src/include/storage/page/hash_table_page_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
* Extending the directory implementation to span multiple pages would be a meaningful improvement to the
* implementation.
*/
#define DIRECTORY_ARRAY_SIZE 512
static constexpr int DIRECTORY_ARRAY_SIZE = 512;
4 changes: 2 additions & 2 deletions src/optimizer/nlj_as_index_join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ auto Optimizer::OptimizeNLJAsIndexJoin(const AbstractPlanNodeRef &plan) -> Abstr
const auto &right_seq_scan = dynamic_cast<const SeqScanPlanNode &>(*nlj_plan.GetRightPlan());
if (left_expr->GetTupleIdx() == 0 && right_expr->GetTupleIdx() == 1) {
if (auto index = MatchIndex(right_seq_scan.table_name_, right_expr->GetColIdx());
index != std::nullopt) {
index != std::nullopt && index.has_value()) {
auto [index_oid, index_name] = *index;
return std::make_shared<NestedIndexJoinPlanNode>(
nlj_plan.output_schema_, nlj_plan.GetLeftPlan(), std::move(left_expr_tuple_0),
Expand All @@ -88,7 +88,7 @@ auto Optimizer::OptimizeNLJAsIndexJoin(const AbstractPlanNodeRef &plan) -> Abstr
}
if (left_expr->GetTupleIdx() == 1 && right_expr->GetTupleIdx() == 0) {
if (auto index = MatchIndex(right_seq_scan.table_name_, left_expr->GetColIdx());
index != std::nullopt) {
index != std::nullopt && index.has_value()) {
auto [index_oid, index_name] = *index;
return std::make_shared<NestedIndexJoinPlanNode>(
nlj_plan.output_schema_, nlj_plan.GetLeftPlan(), std::move(right_expr_tuple_0),
Expand Down
2 changes: 1 addition & 1 deletion src/optimizer/order_by_index_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ auto Optimizer::OptimizeOrderByAsIndexScan(const AbstractPlanNodeRef &plan) -> A
std::vector<uint32_t> order_by_column_ids;
for (const auto &[order_type, expr] : order_bys) {
// Order type is asc or default
if (!(order_type == OrderByType::ASC || order_type == OrderByType::DEFAULT)) {
if (order_type != OrderByType::ASC && order_type != OrderByType::DEFAULT) {
return optimized_plan;
}

Expand Down
7 changes: 4 additions & 3 deletions src/planner/plan_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ auto Planner::PlanSelect(const SelectStatement &statement) -> AbstractPlanNodeRe
for (const auto &order_by : statement.sort_) {
auto [_, expr] = PlanExpression(*order_by->expr_, {plan});
auto abstract_expr = std::move(expr);
order_bys.emplace_back(std::make_pair(order_by->type_, abstract_expr));
order_bys.emplace_back(order_by->type_, abstract_expr);
}
plan = std::make_shared<SortPlanNode>(std::make_shared<Schema>(plan->OutputSchema()), plan, std::move(order_bys));
}
Expand Down Expand Up @@ -174,8 +174,9 @@ auto Planner::PlanSelect(const SelectStatement &statement) -> AbstractPlanNodeRe
if (offset != std::nullopt) {
throw NotImplementedException("OFFSET clause is not supported yet.");
}

plan = std::make_shared<LimitPlanNode>(std::make_shared<Schema>(plan->OutputSchema()), plan, *limit);
if (limit.has_value()) {
plan = std::make_shared<LimitPlanNode>(std::make_shared<Schema>(plan->OutputSchema()), plan, *limit);
}
}

return plan;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/page/table_page.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ auto TablePage::GetNextTupleOffset(const TupleMeta &meta, const Tuple &tuple) co
*/
auto TablePage::InsertTuple(const TupleMeta &meta, const Tuple &tuple) -> std::optional<uint16_t> {
auto tuple_offset = GetNextTupleOffset(meta, tuple);
if (tuple_offset == std::nullopt) {
if (tuple_offset == std::nullopt || !tuple_offset.has_value()) {
return std::nullopt;
}
auto tuple_id = num_tuples_;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/table/table_heap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ auto TableHeap::InsertTuple(const TupleMeta &meta, const Tuple &tuple, LockManag
auto last_page_id = last_page_id_;

auto page = page_guard.AsMut<TablePage>();
auto slot_id = *page->InsertTuple(meta, tuple);
auto slot_id = *page->InsertTuple(meta, tuple); // NOLINT

// only allow one insertion at a time, otherwise it will deadlock.
guard.unlock();
Expand Down
Loading
Loading