15
15
#include < string>
16
16
#include " catalog/catalog_cache.h"
17
17
#include " catalog/column_catalog.h"
18
+ #include " catalog/constraint_catalog.h"
18
19
#include " catalog/database_catalog.h"
19
20
#include " catalog/index_catalog.h"
20
21
#include " catalog/table_catalog.h"
33
34
namespace peloton {
34
35
namespace planner {
35
36
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
+
36
51
const std::vector<col_triplet> PlanUtil::GetAffectedIndexes (
37
52
catalog::CatalogCache &catalog_cache, const parser::SQLStatement &sql_stmt,
38
- UNUSED_ATTRIBUTE const bool ignore_primary) {
53
+ const bool ignore_primary) {
39
54
std::vector<col_triplet> index_triplets;
40
55
std::string db_name, table_name, schema_name;
41
56
std::shared_ptr<catalog::DatabaseCatalogEntry> db_object;
@@ -73,16 +88,16 @@ const std::vector<col_triplet> PlanUtil::GetAffectedIndexes(
73
88
for (auto &index : indexes_map) {
74
89
bool add_index = true ;
75
90
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
+ }
86
101
87
102
if (add_index) {
88
103
index_triplets.emplace_back (db_oid, table_oid, index.first );
@@ -96,9 +111,11 @@ const std::vector<col_triplet> PlanUtil::GetAffectedIndexes(
96
111
db_name = update_stmt.table ->GetDatabaseName ();
97
112
table_name = update_stmt.table ->GetTableName ();
98
113
db_object = catalog_cache.GetDatabaseObject (db_name);
114
+ db_oid = db_object->GetDatabaseOid ();
99
115
schema_name = update_stmt.table ->GetSchemaName ();
100
116
auto table_object = catalog_cache.GetDatabaseObject (db_name)
101
117
->GetTableCatalogEntry (table_name, schema_name);
118
+ table_oid = table_object->GetTableOid ();
102
119
103
120
auto &update_clauses = update_stmt.updates ;
104
121
std::set<oid_t > update_oids;
@@ -122,15 +139,16 @@ const std::vector<col_triplet> PlanUtil::GetAffectedIndexes(
122
139
index.second ->GetIndexName ().c_str ());
123
140
bool add_index = true ;
124
141
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
+ }
134
152
135
153
if (add_index) {
136
154
index_triplets.emplace_back (db_oid, table_oid, index.first );
0 commit comments