|
13 | 13 | #include <cstdio>
|
14 | 14 |
|
15 | 15 | #include "gtest/gtest.h"
|
| 16 | + |
16 | 17 | #include "catalog/index_catalog.h"
|
17 | 18 | #include "catalog/catalog.h"
|
18 | 19 | #include "catalog/database_catalog.h"
|
@@ -224,46 +225,62 @@ TEST_F(DropTests, DroppingIndexByName) {
|
224 | 225 | catalog->Bootstrap();
|
225 | 226 |
|
226 | 227 | auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance();
|
227 |
| - |
228 | 228 | auto txn = txn_manager.BeginTransaction();
|
| 229 | + |
229 | 230 | catalog->CreateDatabase(TEST_DB_NAME, txn);
|
230 | 231 | auto db = catalog->GetDatabaseWithName(TEST_DB_NAME, txn);
|
231 |
| - |
232 | 232 | // Insert a table first
|
233 | 233 | auto id_column = catalog::Column(
|
234 | 234 | type::TypeId::INTEGER, type::Type::GetTypeSize(type::TypeId::INTEGER),
|
235 | 235 | "dept_id", true);
|
236 | 236 | auto name_column =
|
237 | 237 | catalog::Column(type::TypeId::VARCHAR, 32, "dept_name", false);
|
238 | 238 |
|
239 |
| - |
240 | 239 | std::unique_ptr<catalog::Schema> table_schema(
|
241 | 240 | new catalog::Schema({id_column, name_column}));
|
242 | 241 | std::unique_ptr<catalog::Schema> table_schema2(
|
243 | 242 | new catalog::Schema({id_column, name_column}));
|
| 243 | + txn_manager.CommitTransaction(txn); |
244 | 244 |
|
245 |
| - catalog->CreateTable(TEST_DB_NAME, "department_table_01", std::move(table_schema), |
246 |
| - txn); |
| 245 | + txn = txn_manager.BeginTransaction(); |
| 246 | + catalog->CreateTable(TEST_DB_NAME, "department_table_01", |
| 247 | + std::move(table_schema), txn); |
| 248 | + txn_manager.CommitTransaction(txn); |
247 | 249 |
|
| 250 | + txn = txn_manager.BeginTransaction(); |
248 | 251 | auto source_table = db->GetTableWithName("department_table_01");
|
249 |
| - oid_t col_id = source_table->GetSchema()->GetColumnID(id_column.column_name); |
| 252 | + oid_t col_id = source_table->GetSchema()->GetColumnID( |
| 253 | + id_column.column_name); |
250 | 254 | std::vector<oid_t> source_col_ids;
|
251 | 255 | source_col_ids.push_back(col_id);
|
252 |
| - std::string index_name1 = "pg_table_pkey"; |
| 256 | + std::string index_name1 = "Testing_Drop_Index_By_Name"; |
253 | 257 | catalog->CreateIndex(TEST_DB_NAME, "department_table_01",
|
254 | 258 | source_col_ids, index_name1, false,
|
255 | 259 | IndexType::BWTREE, txn);
|
| 260 | + txn_manager.CommitTransaction(txn); |
256 | 261 |
|
257 |
| - auto index_catalog = catalog::IndexCatalog::GetInstance()->GetIndexObject(index_name1, txn); |
258 |
| - auto index_oid = index_catalog->GetIndexOid(); |
259 |
| - catalog->DropIndex(index_oid,txn); |
| 262 | + txn = txn_manager.BeginTransaction(); |
| 263 | + auto index_catalog = catalog::IndexCatalog::GetInstance()->GetIndexObject( |
| 264 | + index_name1, txn); |
| 265 | + // Check the effect of drop |
| 266 | + // Most major check in this test case |
| 267 | + EXPECT_EQ(catalog::IndexCatalog::GetInstance()->GetIndexObject( |
| 268 | + index_name1, txn), index_catalog); |
260 | 269 |
|
261 |
| - std::string index_name2 = "pg_database_pkey"; |
262 |
| - catalog->CreateIndex(TEST_DB_NAME, "department_table_01", |
263 |
| - source_col_ids, index_name2, false, |
264 |
| - IndexType::BWTREE, txn); |
265 |
| - catalog->DropIndex(index_name2,txn); |
| 270 | + // Now dropping the index using the DropIndex functionality |
| 271 | + catalog->DropIndex(index_name1,txn); |
| 272 | + EXPECT_EQ(catalog::IndexCatalog::GetInstance()->GetIndexObject( |
| 273 | + index_name1, txn), nullptr); |
| 274 | + txn_manager.CommitTransaction(txn); |
266 | 275 |
|
| 276 | + // Drop the table just created |
| 277 | + txn = txn_manager.BeginTransaction(); |
| 278 | + catalog->DropTable(TEST_DB_NAME, "department_table_01", txn); |
| 279 | + txn_manager.CommitTransaction(txn); |
| 280 | + |
| 281 | + // free the database just created |
| 282 | + txn = txn_manager.BeginTransaction(); |
| 283 | + catalog->DropDatabaseWithName(TEST_DB_NAME, txn); |
267 | 284 | txn_manager.CommitTransaction(txn);
|
268 | 285 | }
|
269 | 286 | } // namespace test
|
|
0 commit comments