Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit 1599922

Browse files
committed
make changes according to pooja's reviews
1 parent 088fde4 commit 1599922

24 files changed

+102
-95
lines changed

src/catalog/abstract_catalog.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ bool AbstractCatalog::UpdateWithIndexScan(
317317
auto index = catalog_table_->GetIndex(index_offset);
318318
std::vector<oid_t> key_column_offsets =
319319
index->GetMetadata()->GetKeySchema()->GetIndexedColumns();
320+
321+
// NOTE: For indexed scan on catalog tables, we expect it not to be "partial
322+
// indexed scan"(efficiency purpose).That being said, indexed column number
323+
// must be equal to passed in "scan_values" size
320324
PELOTON_ASSERT(scan_values.size() == key_column_offsets.size());
321325
std::vector<ExpressionType> expr_types(scan_values.size(),
322326
ExpressionType::COMPARE_EQUAL);

src/catalog/catalog.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ Catalog::Catalog() : pool_(new type::EphemeralPool()) {
7474
txn_manager.CommitTransaction(txn);
7575
}
7676

77-
/* This function *MUST* be called after a new database is created to bootstrap
78-
* all system catalog tables for that database.
79-
* The system catalog tables must be created in certain order to make sure
80-
* all tuples are indexed (actually this might be fine now after Paulo's fix)
77+
/*@brief This function *MUST* be called after a new database is created to
78+
* bootstrap all system catalog tables for that database. The system catalog
79+
* tables must be created in certain order to make sure all tuples are indexed
80+
*
81+
* @param database database which this system catalogs belong to
82+
* @param txn transaction context
8183
*/
8284
void Catalog::BootstrapSystemCatalogs(storage::Database *database,
8385
concurrency::TransactionContext *txn) {

src/catalog/column_catalog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ std::unique_ptr<catalog::Schema> ColumnCatalog::InitializeSchema() {
137137

138138
bool ColumnCatalog::InsertColumn(oid_t table_oid,
139139
const std::string &column_name,
140-
uint32_t column_id, uint32_t column_offset,
140+
oid_t column_id, oid_t column_offset,
141141
type::TypeId column_type, bool is_inlined,
142142
const std::vector<Constraint> &constraints,
143143
type::AbstractPool *pool,

src/catalog/system_catalogs.cpp

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,23 @@
2121
namespace peloton {
2222
namespace catalog {
2323

24+
/*@brief system catalog constructor, create core catalog tables and manually
25+
* insert records into pg_attribute
26+
* @param database the database which the catalog tables belongs to
27+
* @param txn TransactionContext
28+
*/
2429
SystemCatalogs::SystemCatalogs(storage::Database *database,
2530
type::AbstractPool *pool,
2631
concurrency::TransactionContext *txn)
27-
: pg_trigger(nullptr),
28-
pg_table_metrics(nullptr),
29-
pg_index_metrics(nullptr),
30-
pg_query_metrics(nullptr) {
32+
: pg_trigger_(nullptr),
33+
pg_table_metrics_(nullptr),
34+
pg_index_metrics_(nullptr),
35+
pg_query_metrics_(nullptr) {
3136
oid_t database_oid = database->GetOid();
32-
pg_attribute = new ColumnCatalog(database, pool, txn);
33-
pg_namespace = new SchemaCatalog(database, pool, txn);
34-
pg_table = new TableCatalog(database, pool, txn);
35-
pg_index = new IndexCatalog(database, pool, txn);
37+
pg_attribute_ = new ColumnCatalog(database, pool, txn);
38+
pg_namespace_ = new SchemaCatalog(database, pool, txn);
39+
pg_table_ = new TableCatalog(database, pool, txn);
40+
pg_index_ = new IndexCatalog(database, pool, txn);
3641

3742
// TODO: can we move this to BootstrapSystemCatalogs()?
3843
// insert column information into pg_attribute
@@ -49,52 +54,53 @@ SystemCatalogs::SystemCatalogs(storage::Database *database,
4954
->GetTableWithOid(shared_tables[i].first, shared_tables[i].second)
5055
->GetSchema()
5156
->GetColumns()) {
52-
pg_attribute->InsertColumn(shared_tables[i].second, column.GetName(),
53-
column_id, column.GetOffset(),
54-
column.GetType(), column.IsInlined(),
55-
column.GetConstraints(), pool, txn);
57+
pg_attribute_->InsertColumn(shared_tables[i].second, column.GetName(),
58+
column_id, column.GetOffset(),
59+
column.GetType(), column.IsInlined(),
60+
column.GetConstraints(), pool, txn);
5661
column_id++;
5762
}
5863
}
5964
}
6065

6166
SystemCatalogs::~SystemCatalogs() {
62-
delete pg_index;
63-
delete pg_table;
64-
delete pg_attribute;
65-
delete pg_namespace;
66-
if (pg_trigger) delete pg_trigger;
67+
delete pg_index_;
68+
delete pg_table_;
69+
delete pg_attribute_;
70+
delete pg_namespace_;
71+
if (pg_trigger_) delete pg_trigger_;
6772
// if (pg_proc) delete pg_proc;
68-
if (pg_table_metrics) delete pg_table_metrics;
69-
if (pg_index_metrics) delete pg_index_metrics;
70-
if (pg_query_metrics) delete pg_query_metrics;
73+
if (pg_table_metrics_) delete pg_table_metrics_;
74+
if (pg_index_metrics_) delete pg_index_metrics_;
75+
if (pg_query_metrics_) delete pg_query_metrics_;
7176
}
7277

73-
/*
74-
* @brief using sql create statement to create secondary catalog tables
78+
/*@brief using sql create statement to create secondary catalog tables
79+
* @param database_name the database which the namespace belongs to
80+
* @param txn TransactionContext
7581
*/
7682
void SystemCatalogs::Bootstrap(const std::string &database_name,
7783
concurrency::TransactionContext *txn) {
7884
LOG_DEBUG("Bootstrapping database: %s", database_name.c_str());
7985

80-
if (!pg_trigger) {
81-
pg_trigger = new TriggerCatalog(database_name, txn);
86+
if (!pg_trigger_) {
87+
pg_trigger_ = new TriggerCatalog(database_name, txn);
8288
}
8389

8490
// if (!pg_proc) {
8591
// pg_proc = new ProcCatalog(database_name, txn);
8692
// }
8793

88-
if (!pg_table_metrics) {
89-
pg_table_metrics = new TableMetricsCatalog(database_name, txn);
94+
if (!pg_table_metrics_) {
95+
pg_table_metrics_ = new TableMetricsCatalog(database_name, txn);
9096
}
9197

92-
if (!pg_index_metrics) {
93-
pg_index_metrics = new IndexMetricsCatalog(database_name, txn);
98+
if (!pg_index_metrics_) {
99+
pg_index_metrics_ = new IndexMetricsCatalog(database_name, txn);
94100
}
95101

96-
if (!pg_query_metrics) {
97-
pg_query_metrics = new QueryMetricsCatalog(database_name, txn);
102+
if (!pg_query_metrics_) {
103+
pg_query_metrics_ = new QueryMetricsCatalog(database_name, txn);
98104
}
99105
}
100106

src/catalog/table_catalog.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ bool TableCatalog::InsertTable(oid_t table_oid, const std::string &table_name,
410410
/*@brief delete a tuple about table info from pg_table(using index scan)
411411
* @param table_oid
412412
* @param txn TransactionContext
413-
* @return Whether deletion is Successful
413+
* @return Whether deletion is successful
414414
*/
415415
bool TableCatalog::DeleteTable(oid_t table_oid,
416416
concurrency::TransactionContext *txn) {
@@ -561,6 +561,12 @@ TableCatalog::GetTableObjects(concurrency::TransactionContext *txn) {
561561
return database_object->GetTableObjects();
562562
}
563563

564+
/*@brief update version id column within pg_table
565+
* @param update_val the new(updated) version id
566+
* @param table_oid which table to be updated
567+
* @param txn TransactionContext
568+
* @return Whether update is successful
569+
*/
564570
bool TableCatalog::UpdateVersionId(oid_t update_val, oid_t table_oid,
565571
concurrency::TransactionContext *txn) {
566572
std::vector<oid_t> update_columns({ColumnId::VERSION_ID}); // version_id

src/include/catalog/catalog_defaults.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace catalog {
3535

3636
// Local oids from START_OID = 0 to START_OID + OID_OFFSET are reserved
3737
#define OID_OFFSET 100
38+
#define CATALOG_TABLES_COUNT 8
3839

3940
// Oid mask for each type
4041
#define DATABASE_OID_MASK (static_cast<oid_t>(catalog::CatalogType::DATABASE))

src/include/catalog/column_catalog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ColumnCatalog : public AbstractCatalog {
8181
// write Related API
8282
//===--------------------------------------------------------------------===//
8383
bool InsertColumn(oid_t table_oid, const std::string &column_name,
84-
uint32_t column_id, uint32_t column_offset,
84+
oid_t column_id, oid_t column_offset,
8585
type::TypeId column_type, bool is_inlined,
8686
const std::vector<Constraint> &constraints,
8787
type::AbstractPool *pool,

src/include/catalog/query_metrics_catalog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class QueryMetricsCatalog : public AbstractCatalog {
7070
int64_t GetNumParams(const std::string &name,
7171
concurrency::TransactionContext *txn);
7272
// TODO: In theory, we don't need database_oid
73-
// but now we store all the query metrics under default database "pelton"
73+
// but now we store all the query metrics under default database "peloton"
7474
enum ColumnId {
7575
NAME = 0,
7676
DATABASE_OID = 1,

src/include/catalog/system_catalogs.h

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,73 +47,77 @@ class SystemCatalogs {
4747
void Bootstrap(const std::string &database_name,
4848
concurrency::TransactionContext *txn);
4949

50+
//===--------------------------------------------------------------------===//
51+
// GET FUNCTIONS
52+
// get catalog tables with name
53+
//===--------------------------------------------------------------------===//
5054
ColumnCatalog *GetColumnCatalog() {
51-
if (!pg_attribute) {
55+
if (!pg_attribute_) {
5256
throw CatalogException("Column catalog has not been initialized");
5357
}
54-
return pg_attribute;
58+
return pg_attribute_;
5559
}
5660

5761
SchemaCatalog *GetSchemaCatalog() {
58-
if (!pg_namespace) {
62+
if (!pg_namespace_) {
5963
throw CatalogException("schema catalog has not been initialized");
6064
}
61-
return pg_namespace;
65+
return pg_namespace_;
6266
}
6367

6468
TableCatalog *GetTableCatalog() {
65-
if (!pg_table) {
69+
if (!pg_table_) {
6670
throw CatalogException("Table catalog has not been initialized");
6771
}
68-
return pg_table;
72+
return pg_table_;
6973
}
7074

7175
IndexCatalog *GetIndexCatalog() {
72-
if (!pg_index) {
76+
if (!pg_index_) {
7377
throw CatalogException("Index catalog has not been initialized");
7478
}
75-
return pg_index;
79+
return pg_index_;
7680
}
7781

7882
TriggerCatalog *GetTriggerCatalog() {
79-
if (!pg_trigger) {
83+
if (!pg_trigger_) {
8084
throw CatalogException("Trigger catalog has not been initialized");
8185
}
82-
return pg_trigger;
86+
return pg_trigger_;
8387
}
8488

8589
TableMetricsCatalog *GetTableMetricsCatalog() {
86-
if (!pg_table_metrics) {
90+
if (!pg_table_metrics_) {
8791
throw CatalogException("Table metrics catalog has not been initialized");
8892
}
89-
return pg_table_metrics;
93+
return pg_table_metrics_;
9094
}
9195

9296
IndexMetricsCatalog *GetIndexMetricsCatalog() {
93-
if (!pg_index_metrics) {
97+
if (!pg_index_metrics_) {
9498
throw CatalogException("Index metrics catalog has not been initialized");
9599
}
96-
return pg_index_metrics;
100+
return pg_index_metrics_;
97101
}
98102

99103
QueryMetricsCatalog *GetQueryMetricsCatalog() {
100-
if (!pg_query_metrics) {
104+
if (!pg_query_metrics_) {
101105
throw CatalogException("Query metrics catalog has not been initialized");
102106
}
103-
return pg_query_metrics;
107+
return pg_query_metrics_;
104108
}
105109

106110
private:
107-
ColumnCatalog *pg_attribute;
108-
SchemaCatalog *pg_namespace;
109-
TableCatalog *pg_table;
110-
IndexCatalog *pg_index;
111+
ColumnCatalog *pg_attribute_;
112+
SchemaCatalog *pg_namespace_;
113+
TableCatalog *pg_table_;
114+
IndexCatalog *pg_index_;
111115

112-
TriggerCatalog *pg_trigger;
116+
TriggerCatalog *pg_trigger_;
113117
// ProcCatalog *pg_proc;
114-
TableMetricsCatalog *pg_table_metrics;
115-
IndexMetricsCatalog *pg_index_metrics;
116-
QueryMetricsCatalog *pg_query_metrics;
118+
TableMetricsCatalog *pg_table_metrics_;
119+
IndexMetricsCatalog *pg_index_metrics_;
120+
QueryMetricsCatalog *pg_query_metrics_;
117121
};
118122

119123
} // namespace catalog

src/include/planner/plan_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class PlanUtil {
5555

5656
/**
5757
* @brief Get the indexes affected by a given query
58+
* @param CatalogCache
5859
* @param SQLStatement
5960
* @return set of affected index object ids
6061
*/

0 commit comments

Comments
 (0)