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

Commit 9ba691e

Browse files
committed
More fixes for recent refactors
1 parent 8373fd9 commit 9ba691e

File tree

6 files changed

+48
-51
lines changed

6 files changed

+48
-51
lines changed

Diff for: src/catalog/table_catalog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ void TableCatalogEntry::EvictAllIndexCatalogEntries() {
140140
* @param is_valid
141141
*/
142142
void TableCatalogEntry::SetValidIndexCatalogEntries(bool is_valid) {
143-
valid_index_entries = is_valid;
143+
valid_index_catalog_entries_ = is_valid;
144144
}
145145

146146
/* @brief get all index objects of this table into cache

Diff for: src/include/catalog/table_catalog.h

-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ class TableCatalogEntry {
117117
oid_t database_oid;
118118
uint32_t version_id;
119119
oid_t default_layout_oid;
120-
bool valid_index_entries;
121120

122121
// Insert layout catalog entry into table catalog entry
123122
bool InsertLayout(std::shared_ptr<const storage::Layout> layout);

Diff for: src/include/planner/plan_util.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace peloton {
2929

3030
namespace catalog {
3131
class CatalogCache;
32+
class ConstraintCatalogEntry;
3233
} // namespace catalog
3334

3435
namespace parser {
@@ -60,11 +61,10 @@ class PlanUtil {
6061
* @param CatalogCache
6162
* @param SQLStatement
6263
* @return vector of affected index ids with triplet format
63-
* TODO(saatviks): fix
6464
*/
6565
static const std::vector<col_triplet> GetAffectedIndexes(
6666
catalog::CatalogCache &catalog_cache,
67-
const parser::SQLStatement &sql_stmt, UNUSED_ATTRIBUTE const bool ignore_primary = false);
67+
const parser::SQLStatement &sql_stmt, const bool ignore_primary = false);
6868

6969
/**
7070
* @brief Get the columns affected by a given query
@@ -83,6 +83,9 @@ class PlanUtil {
8383
/// Helpers for GetInfo() and GetTablesReferenced()
8484
///
8585

86+
static const std::set<oid_t> GetPrimaryKeyColumns(std::unordered_map<oid_t, std::shared_ptr<catalog::ConstraintCatalogEntry>>
87+
table_constraint_entries);
88+
8689
static void GetInfo(const planner::AbstractPlan *plan, std::ostringstream &os,
8790
int num_indent);
8891

Diff for: src/planner/plan_util.cpp

+38-20
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <string>
1616
#include "catalog/catalog_cache.h"
1717
#include "catalog/column_catalog.h"
18+
#include "catalog/constraint_catalog.h"
1819
#include "catalog/database_catalog.h"
1920
#include "catalog/index_catalog.h"
2021
#include "catalog/table_catalog.h"
@@ -33,9 +34,23 @@
3334
namespace peloton {
3435
namespace planner {
3536

37+
const std::set<oid_t> PlanUtil::GetPrimaryKeyColumns(
38+
std::unordered_map<oid_t, std::shared_ptr<catalog::ConstraintCatalogEntry>>
39+
table_constraint_entries) {
40+
std::set<oid_t> pkey_set;
41+
for(const auto &kv: table_constraint_entries) {
42+
if(kv.second->GetConstraintType() == ConstraintType::PRIMARY) {
43+
for(const auto& col_oid: kv.second->GetColumnIds()) {
44+
pkey_set.insert(col_oid);
45+
}
46+
}
47+
}
48+
return pkey_set;
49+
}
50+
3651
const std::vector<col_triplet> PlanUtil::GetAffectedIndexes(
3752
catalog::CatalogCache &catalog_cache, const parser::SQLStatement &sql_stmt,
38-
UNUSED_ATTRIBUTE const bool ignore_primary) {
53+
const bool ignore_primary) {
3954
std::vector<col_triplet> index_triplets;
4055
std::string db_name, table_name, schema_name;
4156
std::shared_ptr<catalog::DatabaseCatalogEntry> db_object;
@@ -73,16 +88,16 @@ const std::vector<col_triplet> PlanUtil::GetAffectedIndexes(
7388
for (auto &index : indexes_map) {
7489
bool add_index = true;
7590

76-
// TODO(saatviks): Find a way to check for PKey
77-
// if (ignore_primary) {
78-
// const auto col_oids = index.second->GetKeyAttrs();
79-
// for (const auto col_oid : col_oids) {
80-
// if (table_object->GetConstraintCatalogEntries()GetCGetColumnCatalogEntry(col_oid)->) {
81-
// add_index = false;
82-
// break;
83-
// }
84-
// }
85-
// }
91+
if (ignore_primary) {
92+
auto pkey_cols_table = GetPrimaryKeyColumns(table_object->GetConstraintCatalogEntries());
93+
const auto col_oids = index.second->GetKeyAttrs();
94+
for (const auto col_oid : col_oids) {
95+
if(pkey_cols_table.find(col_oid) != pkey_cols_table.end()) {
96+
add_index = false;
97+
break;
98+
}
99+
}
100+
}
86101

87102
if (add_index) {
88103
index_triplets.emplace_back(db_oid, table_oid, index.first);
@@ -96,9 +111,11 @@ const std::vector<col_triplet> PlanUtil::GetAffectedIndexes(
96111
db_name = update_stmt.table->GetDatabaseName();
97112
table_name = update_stmt.table->GetTableName();
98113
db_object = catalog_cache.GetDatabaseObject(db_name);
114+
db_oid = db_object->GetDatabaseOid();
99115
schema_name = update_stmt.table->GetSchemaName();
100116
auto table_object = catalog_cache.GetDatabaseObject(db_name)
101117
->GetTableCatalogEntry(table_name, schema_name);
118+
table_oid = table_object->GetTableOid();
102119

103120
auto &update_clauses = update_stmt.updates;
104121
std::set<oid_t> update_oids;
@@ -122,15 +139,16 @@ const std::vector<col_triplet> PlanUtil::GetAffectedIndexes(
122139
index.second->GetIndexName().c_str());
123140
bool add_index = true;
124141

125-
// TODO(saatviks): Find a way to check for PKey
126-
// if (ignore_primary) {
127-
// for (const auto col_oid : key_attrs) {
128-
// if (table_object->GetColumnObject(col_oid)->IsPrimary()) {
129-
// add_index = false;
130-
// break;
131-
// }
132-
// }
133-
// }
142+
if (ignore_primary) {
143+
auto pkey_cols_table = GetPrimaryKeyColumns(table_object->GetConstraintCatalogEntries());
144+
const auto col_oids = index.second->GetKeyAttrs();
145+
for (const auto col_oid : col_oids) {
146+
if(pkey_cols_table.find(col_oid) != pkey_cols_table.end()) {
147+
add_index = false;
148+
break;
149+
}
150+
}
151+
}
134152

135153
if (add_index) {
136154
index_triplets.emplace_back(db_oid, table_oid, index.first);

Diff for: test/brain/compressed_idx_config_test.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class CompressedIdxConfigTest : public PelotonTest {
4141
*/
4242
oid_t GetTableOid(const std::string &db_name, const std::string &table_name) {
4343
auto txn = txn_manager_->BeginTransaction();
44-
const auto table_oid = catalog_->GetDatabaseObject(db_name, txn)
45-
->GetTableObject(table_name, DEFAULT_SCHEMA_NAME)
44+
const auto table_oid = catalog_->GetDatabaseCatalogEntry(txn, db_name)
45+
->GetTableCatalogEntry(table_name, DEFAULT_SCHEMA_NAME)
4646
->GetTableOid();
4747
txn_manager_->CommitTransaction(txn);
4848
return table_oid;

Diff for: test/planner/plan_util_test.cpp

+2-25
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,8 @@ TEST_F(PlanUtilTests, GetAffectedIndexesTest) {
3838

3939
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
4040
auto txn = txn_manager.BeginTransaction();
41-
42-
<<<<<<< HEAD
43-
catalog->CreateDatabase(TEST_DB_NAME, txn);
44-
auto db = catalog->GetDatabaseWithName(TEST_DB_NAME, txn);
45-
=======
4641
catalog->CreateDatabase(txn, TEST_DB_NAME);
47-
>>>>>>> upstream/master
42+
auto db = catalog->GetDatabaseWithName(txn, TEST_DB_NAME);
4843
// Insert a table first
4944
auto id_column = catalog::Column(
5045
type::TypeId::INTEGER, type::Type::GetTypeSize(type::TypeId::INTEGER),
@@ -73,13 +68,9 @@ TEST_F(PlanUtilTests, GetAffectedIndexesTest) {
7368
txn_manager.CommitTransaction(txn);
7469

7570
txn = txn_manager.BeginTransaction();
76-
<<<<<<< HEAD
7771
oid_t db_oid = db->GetOid();
7872
oid_t table_oid = source_table->GetOid();
79-
oid_t col_id = source_table->GetSchema()->GetColumnID(id_column.column_name);
80-
=======
8173
oid_t col_id = source_table->GetSchema()->GetColumnID(id_column.GetName());
82-
>>>>>>> upstream/master
8374
std::vector<oid_t> source_col_ids;
8475
source_col_ids.push_back(col_id);
8576

@@ -215,18 +206,10 @@ TEST_F(PlanUtilTests, GetIndexableColumnsTest) {
215206
auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
216207

217208
auto txn = txn_manager.BeginTransaction();
218-
<<<<<<< HEAD
219-
catalog->CreateDatabase(TEST_DB_COLUMNS, txn);
220-
auto db_object = catalog->GetDatabaseObject(TEST_DB_COLUMNS, txn);
221-
oid_t database_id = db_object->GetDatabaseOid();
222-
int table_count = db_object->GetTableObjects().size();
223-
=======
224209
catalog->CreateDatabase(txn, TEST_DB_COLUMNS);
225-
auto db = catalog->GetDatabaseWithName(txn, TEST_DB_COLUMNS);
226-
oid_t database_id = db->GetOid();
227210
auto db_object = catalog->GetDatabaseCatalogEntry(txn, TEST_DB_COLUMNS);
211+
oid_t database_id = db_object->GetDatabaseOid();
228212
int table_count = db_object->GetTableCatalogEntries().size();
229-
>>>>>>> upstream/master
230213
txn_manager.CommitTransaction(txn);
231214

232215
// Insert a 'test_table' with 'id', 'first_name' and 'last_name'
@@ -252,16 +235,10 @@ TEST_F(PlanUtilTests, GetIndexableColumnsTest) {
252235

253236
// Obtain ids for the table and columns
254237
txn = txn_manager.BeginTransaction();
255-
<<<<<<< HEAD
256-
257-
auto source_table = catalog->GetTableWithName(
258-
TEST_DB_COLUMNS, DEFAULT_SCHEMA_NAME, "test_table", txn);
259-
=======
260238
auto source_table = catalog->GetTableWithName(txn,
261239
TEST_DB_COLUMNS,
262240
DEFAULT_SCHEMA_NAME,
263241
"test_table");
264-
>>>>>>> upstream/master
265242
txn_manager.CommitTransaction(txn);
266243

267244
oid_t table_id = source_table->GetOid();

0 commit comments

Comments
 (0)