Skip to content

Commit

Permalink
Replace BwTree with BPlusTree (cmu-db#1506)
Browse files Browse the repository at this point in the history
* Replacing BwTree with BPlusTree

* Format

* Change in postgres parser

* Remove BwTree test in tpcc_test

Co-authored-by: Matt Butrovich <[email protected]>
Co-authored-by: Lin Ma <[email protected]>
  • Loading branch information
3 people authored Mar 11, 2021
1 parent a34360a commit af3816b
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 85 deletions.
2 changes: 1 addition & 1 deletion benchmark/catalog/catalog_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class CatalogBenchmark : public benchmark::Fixture {
const catalog::Schema::Column &col) {
std::vector<catalog::IndexSchema::Column> key_cols{catalog::IndexSchema::Column{
col.Name(), type::TypeId::INTEGER, false, parser::ColumnValueExpression(db_, table_oid, col.Oid())}};
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);
const auto idx_oid = accessor->CreateIndex(accessor->GetDefaultNamespace(), table_oid, index_name, index_schema);
NOISEPAGE_ASSERT(idx_oid != catalog::INVALID_INDEX_OID, "index creation should not fail");
auto true_schema = accessor->GetIndexSchema(idx_oid);
Expand Down
14 changes: 7 additions & 7 deletions benchmark/storage/index_wrapper_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class IndexBenchmark : public benchmark::Fixture {
storage::ProjectedRowInitializer tuple_initializer_ =
storage::ProjectedRowInitializer::Create(std::vector<uint16_t>{1}, std::vector<uint16_t>{1}); // This is a dummy

// HashIndex or BwTreeIndex
// HashIndex or BPlusTreeIndex
common::ManagedPointer<storage::index::Index> index_;
transaction::TimestampManager *timestamp_manager_;
transaction::DeferredActionManager *deferred_action_manager_;
Expand Down Expand Up @@ -116,7 +116,7 @@ class IndexBenchmark : public benchmark::Fixture {
}

// Table is populated with sequentially increasing keys, which will not make performance difference on hash index, but
// may on the BwTree structure
// may on the BPlusTree structure
void PopulateTableAndIndex() {
// Set up keystore and transaction manager for insert actions
auto *const insert_key = index_->GetProjectedRowInitializer().InitializeRow(key_buffer_);
Expand Down Expand Up @@ -168,11 +168,11 @@ class IndexBenchmark : public benchmark::Fixture {
}
};

// Determine required time to run key lookup with BwTree structure for index
// Determine required time to run key lookup with BplusTree structure for index
// NOLINTNEXTLINE
BENCHMARK_DEFINE_F(IndexBenchmark, BwTreeIndexRandomScanKey)(benchmark::State &state) {
// Create index using BwTree and populate associated table
CreateIndex(storage::index::IndexType::BWTREE);
BENCHMARK_DEFINE_F(IndexBenchmark, BPlusTreeIndexRandomScanKey)(benchmark::State &state) {
// Create index using BPlusTree and populate associated table
CreateIndex(storage::index::IndexType::BPLUSTREE);
PopulateTableAndIndex();
// NOLINTNEXTLINE
for (auto _ : state) {
Expand Down Expand Up @@ -203,7 +203,7 @@ BENCHMARK_DEFINE_F(IndexBenchmark, HashIndexRandomScanKey)(benchmark::State &sta
// BENCHMARK REGISTRATION
// ----------------------------------------------------------------------------
// clang-format off
BENCHMARK_REGISTER_F(IndexBenchmark, BwTreeIndexRandomScanKey)
BENCHMARK_REGISTER_F(IndexBenchmark, BPlusTreeIndexRandomScanKey)
->UseManualTime()
->Unit(benchmark::kMillisecond);
BENCHMARK_REGISTER_F(IndexBenchmark, HashIndexRandomScanKey)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/storage/recovery_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ BENCHMARK_DEFINE_F(RecoveryBenchmark, IndexRecovery)(benchmark::State &state) {
auto index_col =
catalog::IndexSchema::Column("index_col", type::TypeId::INTEGER, false,
parser::ColumnValueExpression(db_oid, table_oid, schema.GetColumn(0).Oid()));
catalog::IndexSchema index_schema({index_col}, storage::index::IndexType::BWTREE, true, false, false, true);
catalog::IndexSchema index_schema({index_col}, storage::index::IndexType::BPLUSTREE, true, false, false, true);
auto index_oid =
catalog_accessor->CreateIndex(namespace_oid, table_oid, index_name + std::to_string(i), index_schema);
auto *index = storage::index::IndexBuilder().SetKeySchema(index_schema).Build();
Expand Down
8 changes: 4 additions & 4 deletions src/catalog/postgres/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,8 @@ IndexSchema Builder::GetColumnOidIndexSchema(db_oid_t db) {
parser::ColumnValueExpression(db, PgAttribute::COLUMN_TABLE_OID, PgAttribute::ATTNUM.oid_));
columns.back().SetOid(indexkeycol_oid_t(2));

// Primary, must be a BWTREE due to ScanAscending usage
IndexSchema schema(columns, storage::index::IndexType::BWTREE, true, true, false, true);
// Primary, must be a BPLUSTREE due to ScanAscending usage
IndexSchema schema(columns, storage::index::IndexType::BPLUSTREE, true, true, false, true);

return schema;
}
Expand Down Expand Up @@ -830,7 +830,7 @@ IndexSchema Builder::GetProcNameIndexSchema(db_oid_t db) {
columns.back().SetOid(indexkeycol_oid_t(2));

// Non-Unique, not primary
IndexSchema schema(columns, storage::index::IndexType::BWTREE, false, false, false, false);
IndexSchema schema(columns, storage::index::IndexType::BPLUSTREE, false, false, false, false);

return schema;
}
Expand All @@ -848,7 +848,7 @@ IndexSchema Builder::GetStatisticOidIndexSchema(db_oid_t db) {
columns.back().SetOid(indexkeycol_oid_t(2));

// Primary
IndexSchema schema(columns, storage::index::IndexType::BWTREE, true, true, false, true);
IndexSchema schema(columns, storage::index::IndexType::BPLUSTREE, true, true, false, true);

return schema;
}
Expand Down
4 changes: 2 additions & 2 deletions src/execution/sql/ddl_executors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool DDLExecutors::CreateTableExecutor(const common::ManagedPointer<planner::Cre
parser::ColumnValueExpression(connection_db, table_oid, table_col.Oid()));
}
}
catalog::IndexSchema index_schema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
catalog::IndexSchema index_schema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);

// Create the index, and use its return value as overall success result
result = result &&
Expand All @@ -87,7 +87,7 @@ bool DDLExecutors::CreateTableExecutor(const common::ManagedPointer<planner::Cre
parser::ColumnValueExpression(connection_db, table_oid, table_col.Oid()));
}
}
catalog::IndexSchema index_schema(key_cols, storage::index::IndexType::BWTREE, true, false, false, true);
catalog::IndexSchema index_schema(key_cols, storage::index::IndexType::BPLUSTREE, true, false, false, true);

// Create the index, and use its return value as overall success result
result = result && CreateIndex(accessor, node->GetNamespaceOid(), unique_constraint.constraint_name_, table_oid,
Expand Down
2 changes: 1 addition & 1 deletion src/optimizer/rules/implementation_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ void LogicalCreateIndexToPhysicalCreateIndex::Transform(
cols.emplace_back(name, type, nullable, *attr);
}

storage::index::IndexType idx_type = storage::index::IndexType::BWTREE;
storage::index::IndexType idx_type = storage::index::IndexType::BPLUSTREE;
switch (ci_op->GetIndexType()) {
case parser::IndexType::BWTREE:
idx_type = storage::index::IndexType::BWTREE;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/postgresparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,9 @@ std::unique_ptr<SQLStatement> PostgresParser::CreateIndexTransform(ParseResult *
// TODO(WAN): do we need to do case conversion?
if (strcmp(access_method, "invalid") == 0) {
index_type = IndexType::INVALID;
} else if ((strcmp(access_method, "btree") == 0) || (strcmp(access_method, "bwtree") == 0)) {
} else if (strcmp(access_method, "bwtree") == 0) {
index_type = IndexType::BWTREE;
} else if ((strcmp(access_method, "b+tree") == 0) || (strcmp(access_method, "bplustree") == 0)) {
} else if ((strcmp(access_method, "btree") == 0) || (strcmp(access_method, "bplustree") == 0)) {
index_type = IndexType::BPLUSTREE;
} else if (strcmp(access_method, "hash") == 0) {
index_type = IndexType::HASH;
Expand Down
12 changes: 6 additions & 6 deletions test/catalog/catalog_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ TEST_F(CatalogTests, UserIndexTest) {
// Create the index
std::vector<catalog::IndexSchema::Column> key_cols{catalog::IndexSchema::Column{
"id", type::TypeId::INTEGER, false, parser::ColumnValueExpression(db_, table_oid, schema.GetColumn("id").Oid())}};
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);
auto idx_oid = accessor->CreateIndex(accessor->GetDefaultNamespace(), table_oid,
"test_table_index_mabobberwithareallylongnamethatstillneedsmore", index_schema);
EXPECT_NE(idx_oid, catalog::INVALID_INDEX_OID);
Expand Down Expand Up @@ -379,7 +379,7 @@ TEST_F(CatalogTests, CascadingDropTableTest) {
EXPECT_NE(accessor, nullptr);
std::vector<catalog::IndexSchema::Column> key_cols{catalog::IndexSchema::Column{
"id", type::TypeId::INTEGER, false, parser::ColumnValueExpression(db_, table_oid, schema.GetColumn("id").Oid())}};
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);
auto idx_oid = accessor->CreateIndex(accessor->GetDefaultNamespace(), table_oid, "test_index", index_schema);
EXPECT_NE(idx_oid, catalog::INVALID_INDEX_OID);
auto true_schema = accessor->GetIndexSchema(idx_oid);
Expand Down Expand Up @@ -443,7 +443,7 @@ TEST_F(CatalogTests, CascadingDropNamespaceTest) {
EXPECT_NE(accessor, nullptr);
std::vector<catalog::IndexSchema::Column> key_cols{catalog::IndexSchema::Column{
"id", type::TypeId::INTEGER, false, parser::ColumnValueExpression(db_, table_oid, schema.GetColumn("id").Oid())}};
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);
auto idx_oid = accessor->CreateIndex(ns_oid, table_oid, "test_index", index_schema);
EXPECT_NE(idx_oid, catalog::INVALID_INDEX_OID);
auto true_schema = accessor->GetIndexSchema(idx_oid);
Expand Down Expand Up @@ -508,7 +508,7 @@ TEST_F(CatalogTests, CascadingDropNamespaceWithIndexOnOtherNamespaceTest) {
EXPECT_NE(accessor, nullptr);
std::vector<catalog::IndexSchema::Column> key_cols{catalog::IndexSchema::Column{
"id", type::TypeId::INTEGER, false, parser::ColumnValueExpression(db_, table_oid, schema.GetColumn("id").Oid())}};
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);
auto idx_oid = accessor->CreateIndex(ns_oid, table_oid, "test_index", index_schema);
EXPECT_NE(idx_oid, catalog::INVALID_INDEX_OID);
auto true_schema = accessor->GetIndexSchema(idx_oid);
Expand Down Expand Up @@ -689,7 +689,7 @@ TEST_F(CatalogTests, GetIndexesTest) {
// Create the index
std::vector<catalog::IndexSchema::Column> key_cols{catalog::IndexSchema::Column{
"id", type::TypeId::INTEGER, false, parser::ColumnValueExpression(db_, table_oid, schema.GetColumn("id").Oid())}};
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);
auto idx_oid = accessor->CreateIndex(accessor->GetDefaultNamespace(), table_oid, "test_table_idx", index_schema);
EXPECT_NE(idx_oid, catalog::INVALID_INDEX_OID);
auto true_schema = accessor->GetIndexSchema(idx_oid);
Expand Down Expand Up @@ -736,7 +736,7 @@ TEST_F(CatalogTests, GetIndexObjectsTest) {
std::vector<catalog::IndexSchema::Column> key_cols{
catalog::IndexSchema::Column{"id", type::TypeId::INTEGER, false,
parser::ColumnValueExpression(db_, table_oid, schema.GetColumn("id").Oid())}};
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, true, true, false, true);
auto index_schema = catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, true, true, false, true);
auto idx_oid = accessor->CreateIndex(accessor->GetDefaultNamespace(), table_oid,
"test_table_idx" + std::to_string(i), index_schema);
EXPECT_NE(idx_oid, catalog::INVALID_INDEX_OID);
Expand Down
2 changes: 1 addition & 1 deletion test/execution/ddl_executors_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DDLExecutorsTests : public TerrierTest {
catalog::col_oid_t(1)));
StorageTestUtil::ForceOid(&(keycols[0]), catalog::indexkeycol_oid_t(1));
index_schema_ =
std::make_unique<catalog::IndexSchema>(keycols, storage::index::IndexType::BWTREE, true, true, false, true);
std::make_unique<catalog::IndexSchema>(keycols, storage::index::IndexType::BPLUSTREE, true, true, false, true);

txn_ = txn_manager_->BeginTransaction();
accessor_ = catalog_->GetAccessor(common::ManagedPointer(txn_), db_, DISABLED);
Expand Down
6 changes: 3 additions & 3 deletions test/execution/index_create_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TEST_F(IndexCreateTest, SimpleIndexCreate) {
parser::ColumnValueExpression col_expr(table_oid, table_col.Oid(), table_col.Type());
index_cols.emplace_back("index_colA", type::TypeId::INTEGER, false, col_expr);

catalog::IndexSchema tmp_index_schema{index_cols, storage::index::IndexType::BWTREE, false, false, false, false};
catalog::IndexSchema tmp_index_schema{index_cols, storage::index::IndexType::BPLUSTREE, false, false, false, false};

CreateIndex(table_oid, "indexA", std::make_unique<catalog::IndexSchema>(tmp_index_schema));

Expand All @@ -126,7 +126,7 @@ TEST_F(IndexCreateTest, SimpleIndexCreate2) {
parser::ColumnValueExpression col_expr(table_oid, table_col.Oid(), table_col.Type());
index_cols.emplace_back("index_colE", type::TypeId::INTEGER, false, col_expr);

catalog::IndexSchema tmp_index_schema{index_cols, storage::index::IndexType::BWTREE, false, false, false, false};
catalog::IndexSchema tmp_index_schema{index_cols, storage::index::IndexType::BPLUSTREE, false, false, false, false};

CreateIndex(table_oid, "indexE", std::make_unique<catalog::IndexSchema>(tmp_index_schema));

Expand All @@ -150,7 +150,7 @@ TEST_F(IndexCreateTest, MultiColumnIndexCreate) {
parser::ColumnValueExpression col_expr_b(table_oid, table_col_b.Oid(), table_col_b.Type());
index_cols.emplace_back("index_colB", type::TypeId::INTEGER, false, col_expr_b);

catalog::IndexSchema tmp_index_schema{index_cols, storage::index::IndexType::BWTREE, false, false, false, false};
catalog::IndexSchema tmp_index_schema{index_cols, storage::index::IndexType::BPLUSTREE, false, false, false, false};

CreateIndex(table_oid, "indexAB", std::make_unique<catalog::IndexSchema>(tmp_index_schema));

Expand Down
4 changes: 2 additions & 2 deletions test/include/test_util/storage_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class StorageTestUtil {
ForceOid(&(key_cols.back()), key_oid);
}

return catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, false, false, false, true);
return catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, false, false, false, true);
}

/**
Expand Down Expand Up @@ -555,7 +555,7 @@ class StorageTestUtil {
bytes_used = static_cast<uint16_t>(bytes_used + type::TypeUtil::GetTypeSize(type));
}

return catalog::IndexSchema(key_cols, storage::index::IndexType::BWTREE, false, false, false, true);
return catalog::IndexSchema(key_cols, storage::index::IndexType::BPLUSTREE, false, false, false, true);
}

private:
Expand Down
2 changes: 1 addition & 1 deletion test/integration/tpcc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class TPCCTests : public TerrierTest {
TEST_F(TPCCTests, WithoutLoggingHashIndexes) { RunTPCC(false, false, storage::index::IndexType::HASHMAP); }

// NOLINTNEXTLINE
TEST_F(TPCCTests, WithoutLoggingBwTreeIndexes) { RunTPCC(false, false, storage::index::IndexType::BWTREE); }
TEST_F(TPCCTests, WithoutLoggingBPlusTreeIndexes) { RunTPCC(false, false, storage::index::IndexType::BPLUSTREE); }

// NOLINTNEXTLINE
TEST_F(TPCCTests, WithLogging) { RunTPCC(true, false, storage::index::IndexType::HASHMAP); }
Expand Down
Loading

0 comments on commit af3816b

Please sign in to comment.