@@ -947,7 +947,7 @@ std::shared_ptr<SystemCatalogs> Catalog::GetSystemCatalogs(
947
947
* @param txn the transaction Context
948
948
* @return TransactionContext ResultType(SUCCESS or FAILURE)
949
949
*/
950
- ResultType Catalog::AlterTable (oid_t database_oid, oid_t table_oid,
950
+ ResultType Catalog::AlterTable (oid_t database_oid, oid_t table_oid, const std::string &schema_name,
951
951
std::unique_ptr<catalog::Schema> &new_schema,
952
952
concurrency::TransactionContext *txn) {
953
953
LOG_TRACE (" AlterTable in Catalog" );
@@ -960,6 +960,7 @@ ResultType Catalog::AlterTable(oid_t database_oid, oid_t table_oid,
960
960
try {
961
961
auto old_table = database->GetTableWithOid (table_oid);
962
962
auto old_schema = old_table->GetSchema ();
963
+ auto pg_index = catalog_map_[database_oid]->GetIndexCatalog ();
963
964
964
965
// Step 1: build empty table with new schema
965
966
bool own_schema = true ;
@@ -968,14 +969,12 @@ ResultType Catalog::AlterTable(oid_t database_oid, oid_t table_oid,
968
969
database_oid, table_oid,
969
970
catalog::Schema::CopySchema (new_schema.get ()), old_table->GetName (),
970
971
DEFAULT_TUPLES_PER_TILEGROUP, own_schema, adapt_table);
971
-
972
972
// Step 2: Copy indexes
973
- auto old_index_oids =
974
- IndexCatalog::GetInstance ()->GetIndexObjects (table_oid, txn);
973
+ auto old_index_oids = pg_index->GetIndexObjects (table_oid, txn);
975
974
for (auto index_oid_pair : old_index_oids) {
976
975
oid_t index_oid = index_oid_pair.first ;
977
976
// delete record in pg_index
978
- IndexCatalog::GetInstance () ->DeleteIndex (index_oid, txn);
977
+ pg_index ->DeleteIndex (index_oid, txn);
979
978
// Check if all indexed columns still exists
980
979
auto old_index = old_table->GetIndexWithOid (index_oid);
981
980
bool index_exist = true ;
@@ -1014,14 +1013,13 @@ ResultType Catalog::AlterTable(oid_t database_oid, oid_t table_oid,
1014
1013
new_table->AddIndex (new_index);
1015
1014
1016
1015
// reinsert record into pg_index
1017
- IndexCatalog::GetInstance () ->InsertIndex (
1018
- index_oid, old_index->GetName (), table_oid,
1016
+ pg_index ->InsertIndex (
1017
+ index_oid, old_index->GetName (), table_oid, schema_name,
1019
1018
old_index->GetMetadata ()->GetIndexType (),
1020
1019
old_index->GetMetadata ()->GetIndexConstraintType (),
1021
1020
old_index->GetMetadata ()->HasUniqueKeys (), new_key_attrs,
1022
1021
pool_.get (), txn);
1023
1022
}
1024
-
1025
1023
std::unique_ptr<executor::ExecutorContext> context (
1026
1024
new executor::ExecutorContext (txn, {}));
1027
1025
// Step 3: build column mapping between old table and new table
@@ -1089,10 +1087,12 @@ ResultType Catalog::AlterTable(oid_t database_oid, oid_t table_oid,
1089
1087
// Step 5: delete all the column(attribute) records in pg_attribute
1090
1088
// and reinsert them using new schema(column offset needs to change
1091
1089
// accordingly)
1092
- catalog::ColumnCatalog::GetInstance ()->DeleteColumns (table_oid, txn);
1090
+ auto pg_attributes =
1091
+ catalog_map_[database_oid]->GetColumnCatalog ();
1092
+ pg_attributes->DeleteColumns (table_oid, txn);
1093
1093
oid_t column_offset = 0 ;
1094
1094
for (auto new_column : new_schema->GetColumns ()) {
1095
- catalog::ColumnCatalog::GetInstance () ->InsertColumn (
1095
+ pg_attributes ->InsertColumn (
1096
1096
table_oid, new_column.GetName (), column_offset,
1097
1097
new_column.GetOffset (), new_column.GetType (),
1098
1098
new_column.IsInlined (), new_column.GetConstraints (), pool_.get (),
@@ -1143,20 +1143,10 @@ ResultType Catalog::AddColumn(
1143
1143
* @return TransactionContext ResultType(SUCCESS or FAILURE)
1144
1144
*/
1145
1145
1146
- ResultType Catalog::DropColumn (const std::string &database_name,
1147
- const std::string &table_name,
1148
- const std::vector<std::string> &columns,
1149
- concurrency::TransactionContext *txn) {
1150
- try {
1151
- oid_t table_oid = Catalog::GetInstance ()
1152
- ->GetTableObject (database_name, table_name, txn)
1153
- ->GetTableOid ();
1154
- for (std::string name : columns) {
1155
- catalog::ColumnCatalog::GetInstance ()->DeleteColumn (table_oid, name, txn);
1156
- }
1157
- } catch (CatalogException &e) {
1158
- return ResultType::FAILURE;
1159
- }
1146
+ ResultType Catalog::DropColumn (UNUSED_ATTRIBUTE const std::string &database_name,
1147
+ UNUSED_ATTRIBUTE const std::string &table_name,
1148
+ UNUSED_ATTRIBUTE const std::vector<std::string> &columns,
1149
+ UNUSED_ATTRIBUTE concurrency::TransactionContext *txn) {
1160
1150
return ResultType::SUCCESS;
1161
1151
}
1162
1152
@@ -1172,6 +1162,7 @@ ResultType Catalog::RenameColumn(const std::string &database_name,
1172
1162
const std::string &table_name,
1173
1163
const std::string &old_name,
1174
1164
const std::string &new_name,
1165
+ const std::string &schema_name,
1175
1166
concurrency::TransactionContext *txn) {
1176
1167
if (txn == nullptr ) {
1177
1168
throw CatalogException (" Change Column requires transaction." );
@@ -1185,7 +1176,7 @@ ResultType Catalog::RenameColumn(const std::string &database_name,
1185
1176
1186
1177
try {
1187
1178
// Get table from the name
1188
- auto table = Catalog::GetInstance ()->GetTableWithName (database_name,
1179
+ auto table = Catalog::GetInstance ()->GetTableWithName (database_name, schema_name,
1189
1180
table_name, txn);
1190
1181
auto schema = table->GetSchema ();
1191
1182
@@ -1206,10 +1197,15 @@ ResultType Catalog::RenameColumn(const std::string &database_name,
1206
1197
1207
1198
// Modify the pg_table
1208
1199
oid_t table_oid = Catalog::GetInstance ()
1209
- ->GetTableObject (database_name, table_name, txn)
1200
+ ->GetTableObject (database_name, schema_name, table_name, txn)
1210
1201
->GetTableOid ();
1211
- bool res = catalog::ColumnCatalog::GetInstance ()->RenameColumn (
1212
- table_oid, old_name, new_name, txn);
1202
+ oid_t database_oid = Catalog::GetInstance ()
1203
+ ->GetTableObject (database_name, schema_name, table_name, txn)
1204
+ ->GetDatabaseOid ();
1205
+ auto pg_attributes =
1206
+ catalog_map_[database_oid]->GetColumnCatalog ();
1207
+ bool res = pg_attributes->RenameColumn (
1208
+ database_oid, table_oid, old_name, new_name, txn);
1213
1209
if (!res) {
1214
1210
throw CatalogException (" Change Column name failed." );
1215
1211
}
0 commit comments