| 486 | } |
| 487 | |
| 488 | static void process_utility(PlannedStmt* pstmt, |
| 489 | const char* queryString, |
| 490 | bool readOnlyTree, |
| 491 | ProcessUtilityContext context, |
| 492 | ParamListInfo params, |
| 493 | QueryEnvironment* queryEnv, |
| 494 | DestReceiver* dest, |
| 495 | QueryCompletion* completionTag) |
| 496 | { |
| 497 | pg::runtime_printer printer("Process Utility Hook"); |
| 498 | pg::init_deeplake(); |
| 499 | if (nodeTag(pstmt->utilityStmt) == T_DropStmt) { |
| 500 | DropStmt* stmt = (DropStmt*)pstmt->utilityStmt; |
| 501 | if (stmt->removeType == OBJECT_EXTENSION) { |
| 502 | // Extension is being dropped, clean up all tables and indexes |
| 503 | pg::pg_index::clear(); |
| 504 | pg::table_storage::instance().clear(); |
| 505 | } else if (stmt->removeType == OBJECT_INDEX) { |
| 506 | ListCell* lc = nullptr; |
| 507 | foreach (lc, stmt->objects) { |
| 508 | List* object = (List*)lfirst(lc); |
| 509 | const char* index_name = strVal(linitial(object)); |
| 510 | if (!pg::pg_index::has_indexes()) { |
| 511 | pg::load_index_metadata(); |
| 512 | } |
| 513 | pg::pg_index::erase_info(index_name); |
| 514 | pg::erase_indexer_data(std::string{}, std::string{}, index_name); |
| 515 | } |
| 516 | } else if (stmt->removeType == OBJECT_TABLE) { |
| 517 | ListCell* lc = nullptr; |
| 518 | foreach (lc, stmt->objects) { |
| 519 | List* table_name_list = (List*)lfirst(lc); |
| 520 | std::string table_name; |
| 521 | if (list_length(table_name_list) == 2) { |
| 522 | auto* sname = strVal(linitial(table_name_list)); |
| 523 | auto* tname = strVal(lsecond(table_name_list)); |
| 524 | table_name = std::string(sname) + "." + std::string(tname); |
| 525 | } else if (list_length(table_name_list) == 1) { |
| 526 | table_name = std::string("public.") + strVal(linitial(table_name_list)); |
| 527 | } |
| 528 | // Handle both index and table cleanup |
| 529 | if (pg::pg_index::has_index_created_on_table(table_name)) { |
| 530 | pg::pg_index::erase_table_info(table_name); |
| 531 | pg::erase_indexer_data(table_name, std::string{}, std::string{}); |
| 532 | } |
| 533 | pg::table_storage::instance().drop_table(table_name); |
| 534 | } |
| 535 | } else if (stmt->removeType == OBJECT_VIEW) { |
| 536 | ListCell* lc = nullptr; |
| 537 | foreach (lc, stmt->objects) { |
| 538 | List* view_name_list = (List*)lfirst(lc); |
| 539 | std::string view_name; |
| 540 | if (list_length(view_name_list) == 2) { |
| 541 | auto* sname = strVal(linitial(view_name_list)); |
| 542 | auto* vname = strVal(lsecond(view_name_list)); |
| 543 | view_name = std::string(sname) + "." + std::string(vname); |
| 544 | } else if (list_length(view_name_list) == 1) { |
| 545 | view_name = std::string(strVal(linitial(view_name_list))); |
nothing calls this directly
no test coverage detected