forked from cmu-db/noisepage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of catalog support.
- Loading branch information
Showing
53 changed files
with
4,755 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ADD_TERRIER_BENCHMARKS() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "benchmark/benchmark.h" | ||
#include "catalog/catalog.h" | ||
#include "catalog/catalog_defs.h" | ||
#include "common/scoped_timer.h" | ||
#include "transaction/transaction_manager.h" | ||
#include "util/transaction_benchmark_util.h" | ||
|
||
namespace terrier { | ||
|
||
class CatalogBenchmark : public benchmark::Fixture { | ||
public: | ||
void SetUp(const benchmark::State &state) final { | ||
txn_manager_ = new transaction::TransactionManager(&buffer_pool_, true, LOGGING_DISABLED); | ||
|
||
txn_ = txn_manager_->BeginTransaction(); | ||
catalog_ = new catalog::Catalog(txn_manager_, txn_); | ||
} | ||
|
||
void TearDown(const benchmark::State &state) final { | ||
txn_manager_->Commit(txn_, TestCallbacks::EmptyCallback, nullptr); | ||
|
||
delete catalog_; // need to delete catalog_first | ||
delete txn_manager_; | ||
delete txn_; | ||
} | ||
|
||
// transaction manager | ||
transaction::TransactionManager *txn_manager_; | ||
storage::RecordBufferSegmentPool buffer_pool_{100, 100}; | ||
|
||
transaction::TransactionContext *txn_; | ||
|
||
catalog::Catalog *catalog_; | ||
|
||
const int num_lookups = 100000; | ||
}; | ||
|
||
// NOLINTNEXTLINE | ||
BENCHMARK_DEFINE_F(CatalogBenchmark, DatabaseLookupTime)(benchmark::State &state) { | ||
std::vector<type::TransientValue> search_vec, ret_row; | ||
// setup search vector, lookup the default database | ||
search_vec.push_back(type::TransientValueFactory::GetNull(type::TypeId::INTEGER)); | ||
search_vec.push_back(type::TransientValueFactory::GetVarChar("terrier")); | ||
|
||
catalog::DatabaseCatalogTable db_handle = catalog_->GetDatabaseHandle(); | ||
|
||
// NOLINTNEXTLINE | ||
for (auto _ : state) { | ||
for (int32_t iter = 0; iter < num_lookups; iter++) { | ||
// TODO(pakhtar): replace with GetDatabaseEntry(from name); | ||
// ret_row = db_handle.pg_database_rw_->FindRow(txn_, search_vec); | ||
auto entry = db_handle.GetDatabaseEntry(txn_, "terrier"); | ||
} | ||
} | ||
state.SetItemsProcessed(state.iterations() * num_lookups); | ||
} | ||
|
||
BENCHMARK_REGISTER_F(CatalogBenchmark, DatabaseLookupTime)->Unit(benchmark::kMillisecond)->MinTime(2); | ||
|
||
} // namespace terrier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "catalog/attr_def_handle.h" | ||
#include "catalog/catalog.h" | ||
#include "catalog/catalog_defs.h" | ||
#include "storage/sql_table.h" | ||
#include "transaction/transaction_context.h" | ||
|
||
namespace terrier::catalog { | ||
|
||
const std::vector<SchemaCol> AttrDefCatalogTable::schema_cols_ = {{0, true, "oid", type::TypeId::INTEGER}, | ||
{1, true, "adrelid", type::TypeId::INTEGER}, | ||
{2, true, "adnum", type::TypeId::INTEGER}, | ||
{3, true, "adbin", type::TypeId::VARCHAR}, | ||
{4, false, "adsrc", type::TypeId::VARCHAR}}; | ||
|
||
// Find entry with (row) oid and return it | ||
std::shared_ptr<AttrDefCatalogEntry> AttrDefCatalogTable::GetAttrDefEntry(transaction::TransactionContext *txn, | ||
col_oid_t oid) { | ||
std::vector<type::TransientValue> search_vec, ret_row; | ||
search_vec.push_back(type::TransientValueFactory::GetInteger(!oid)); | ||
ret_row = pg_attrdef_rw_->FindRow(txn, search_vec); | ||
if (ret_row.empty()) { | ||
return nullptr; | ||
} | ||
return std::make_shared<AttrDefCatalogEntry>(oid, pg_attrdef_rw_, std::move(ret_row)); | ||
} | ||
|
||
void AttrDefCatalogTable::DeleteEntries(transaction::TransactionContext *txn, table_oid_t table_oid) { | ||
// auto layout = pg_attrdef_rw_->GetLayout(); | ||
int32_t col_index = pg_attrdef_rw_->ColNameToIndex("adrelid"); | ||
|
||
auto it = pg_attrdef_rw_->begin(txn); | ||
while (it != pg_attrdef_rw_->end(txn)) { | ||
// storage::ProjectedColumns::RowView row_view = it->InterpretAsRow(layout, 0); | ||
storage::ProjectedColumns::RowView row_view = it->InterpretAsRow(0); | ||
// check if a matching row, delete if it is | ||
byte *col_p = row_view.AccessWithNullCheck(pg_attrdef_rw_->ColNumToOffset(col_index)); | ||
if (col_p == nullptr) { | ||
continue; | ||
} | ||
auto col_int_value = *(reinterpret_cast<int32_t *>(col_p)); | ||
if (static_cast<uint32_t>(col_int_value) == !table_oid) { | ||
// delete the entry | ||
pg_attrdef_rw_->GetSqlTable()->Delete(txn, *(it->TupleSlots())); | ||
} | ||
++it; | ||
} | ||
} | ||
|
||
SqlTableHelper *AttrDefCatalogTable::Create(transaction::TransactionContext *txn, Catalog *catalog, db_oid_t db_oid, | ||
const std::string &name) { | ||
catalog::SqlTableHelper *pg_attrdef; | ||
|
||
// get an oid | ||
table_oid_t pg_attrdef_oid(catalog->GetNextOid()); | ||
|
||
// uninitialized storage | ||
pg_attrdef = new catalog::SqlTableHelper(pg_attrdef_oid); | ||
|
||
for (auto col : AttrDefCatalogTable::schema_cols_) { | ||
pg_attrdef->DefineColumn(col.col_name, col.type_id, false, col_oid_t(catalog->GetNextOid())); | ||
} | ||
|
||
// now actually create, with the provided schema | ||
pg_attrdef->Create(); | ||
catalog->AddToMap(db_oid, CatalogTableType::ATTRDEF, pg_attrdef); | ||
return pg_attrdef; | ||
} | ||
|
||
} // namespace terrier::catalog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "catalog/attribute_handle.h" | ||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
#include "catalog/catalog.h" | ||
#include "catalog/schema.h" | ||
#include "common/exception.h" | ||
#include "loggers/catalog_logger.h" | ||
#include "storage/block_layout.h" | ||
#include "storage/sql_table.h" | ||
#include "storage/storage_defs.h" | ||
#include "type/type_id.h" | ||
|
||
namespace terrier::catalog { | ||
|
||
// note that this is not identical to Postgres's column sequence | ||
|
||
const std::vector<SchemaCol> AttributeCatalogTable::schema_cols_ = { | ||
{0, true, "oid", type::TypeId::INTEGER}, {1, true, "attrelid", type::TypeId::INTEGER}, | ||
{2, true, "attname", type::TypeId::VARCHAR}, {3, true, "atttypid", type::TypeId::INTEGER}, | ||
{4, true, "attlen", type::TypeId::INTEGER}, {5, true, "attnum", type::TypeId::INTEGER}}; | ||
|
||
// TODO(pakhtar): add unused columns | ||
|
||
std::shared_ptr<AttributeCatalogEntry> AttributeCatalogTable::GetAttributeEntry(transaction::TransactionContext *txn, | ||
table_oid_t table_oid, | ||
col_oid_t col_oid) { | ||
std::vector<type::TransientValue> search_vec, ret_row; | ||
search_vec.push_back(type::TransientValueFactory::GetInteger(!col_oid)); | ||
search_vec.push_back(type::TransientValueFactory::GetInteger(!table_oid)); | ||
ret_row = pg_attribute_hrw_->FindRow(txn, search_vec); | ||
if (ret_row.empty()) { | ||
return nullptr; | ||
} | ||
col_oid_t oid(type::TransientValuePeeker::PeekInteger(ret_row[0])); | ||
return std::make_shared<AttributeCatalogEntry>(oid, pg_attribute_hrw_, std::move(ret_row)); | ||
} | ||
|
||
std::shared_ptr<AttributeCatalogEntry> AttributeCatalogTable::GetAttributeEntry(transaction::TransactionContext *txn, | ||
table_oid_t table_oid, | ||
const std::string &name) { | ||
std::vector<type::TransientValue> search_vec, ret_row; | ||
search_vec.push_back(type::TransientValueFactory::GetNull(type::TypeId::INTEGER)); | ||
search_vec.push_back(type::TransientValueFactory::GetInteger(!table_oid)); | ||
search_vec.push_back(type::TransientValueFactory::GetVarChar(name)); | ||
ret_row = pg_attribute_hrw_->FindRow(txn, search_vec); | ||
if (ret_row.empty()) { | ||
return nullptr; | ||
// throw CATALOG_EXCEPTION("attribute doesn't exist"); | ||
} | ||
col_oid_t oid(type::TransientValuePeeker::PeekInteger(ret_row[0])); | ||
return std::make_shared<AttributeCatalogEntry>(oid, pg_attribute_hrw_, std::move(ret_row)); | ||
} | ||
|
||
void AttributeCatalogTable::DeleteEntries(transaction::TransactionContext *txn, table_oid_t table_oid) { | ||
// auto layout = pg_attribute_hrw_->GetLayout(); | ||
int32_t col_index = pg_attribute_hrw_->ColNameToIndex("attrelid"); | ||
|
||
auto it = pg_attribute_hrw_->begin(txn); | ||
while (it != pg_attribute_hrw_->end(txn)) { | ||
// storage::ProjectedColumns::RowView row_view = it->InterpretAsRow(layout, 0); | ||
storage::ProjectedColumns::RowView row_view = it->InterpretAsRow(0); | ||
// check if a matching row, delete if it is | ||
byte *col_p = row_view.AccessWithNullCheck(pg_attribute_hrw_->ColNumToOffset(col_index)); | ||
if (col_p == nullptr) { | ||
continue; | ||
} | ||
auto col_int_value = *(reinterpret_cast<int32_t *>(col_p)); | ||
if (static_cast<uint32_t>(col_int_value) == !table_oid) { | ||
// delete the entry | ||
pg_attribute_hrw_->GetSqlTable()->Delete(txn, *(it->TupleSlots())); | ||
} | ||
++it; | ||
} | ||
} | ||
|
||
SqlTableHelper *AttributeCatalogTable::Create(transaction::TransactionContext *txn, Catalog *catalog, db_oid_t db_oid, | ||
const std::string &name) { | ||
catalog::SqlTableHelper *pg_attr; | ||
|
||
// get an oid | ||
table_oid_t pg_attr_oid(catalog->GetNextOid()); | ||
|
||
// uninitialized storage | ||
pg_attr = new catalog::SqlTableHelper(pg_attr_oid); | ||
|
||
for (auto col : AttributeCatalogTable::schema_cols_) { | ||
pg_attr->DefineColumn(col.col_name, col.type_id, false, col_oid_t(catalog->GetNextOid())); | ||
} | ||
|
||
// now actually create, with the provided schema | ||
pg_attr->Create(); | ||
catalog->AddToMap(db_oid, CatalogTableType::ATTRIBUTE, pg_attr); | ||
return pg_attr; | ||
} | ||
|
||
} // namespace terrier::catalog |
Oops, something went wrong.