| 524 | } |
| 525 | |
| 526 | void StorageMaterializedView::dropInnerTableIfAny(bool sync, ContextPtr local_context) |
| 527 | { |
| 528 | if (!has_inner_table) |
| 529 | return; |
| 530 | |
| 531 | std::vector<StorageID> to_drop = {getTargetTableId()}; |
| 532 | if (!fixed_uuid) |
| 533 | to_drop.push_back(StorageID(to_drop[0].getDatabaseName(), ".tmp" + to_drop[0].getTableName())); |
| 534 | |
| 535 | for (const StorageID & inner_table_id : to_drop) |
| 536 | { |
| 537 | /// We will use `sync` argument when this function is called from a DROP query |
| 538 | /// and will ignore database_atomic_wait_for_drop_and_detach_synchronously when it's called from drop task. |
| 539 | /// See the comment in StorageMaterializedView::drop. |
| 540 | /// |
| 541 | /// DDL queries with StorageMaterializedView are fundamentally broken: we can't lock DDLGuard |
| 542 | /// here because DDLGuards must be locked in order of increasing table name (to avoid deadlocks), |
| 543 | /// while the inner table name is almost always less than the MV name. |
| 544 | /// So we just don't lock it. It's mostly ok because DatabaseReplicatedDDLWorker doesn't |
| 545 | /// execute queries concurrently, but presumably there are other race conditions |
| 546 | /// (I'm not the author of this code and don't know for sure, just commenting). |
| 547 | /// (Why not reverse DDLGuard locking order everywhere? Because in another place we lock |
| 548 | /// DDLGuard for table "<name><suffix>" while holding DDLGuard for table "<name>".) |
| 549 | auto table_exists = DatabaseCatalog::instance().tryGetTable(inner_table_id, getContext()) != nullptr; |
| 550 | if (table_exists) |
| 551 | InterpreterDropQuery::executeDropQuery(ASTDropQuery::Kind::Drop, getContext(), local_context, inner_table_id, |
| 552 | sync, /* ignore_sync_setting */ true, /*need_ddl_guard*/ false); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | void StorageMaterializedView::truncate(const ASTPtr &, const StorageMetadataPtr &, ContextPtr local_context, TableExclusiveLockHolder &) |
| 557 | { |
nothing calls this directly
no test coverage detected