| 1 | //===----------------------------------------------------------------------===// |
| 2 | // DuckDB |
| 3 | // |
| 4 | // duckdb/catalog/dependency_manager.hpp |
| 5 | // |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include "duckdb/catalog/catalog_entry.hpp" |
| 12 | #include "duckdb/catalog/catalog_set.hpp" |
| 13 | |
| 14 | #include <mutex> |
| 15 | |
| 16 | namespace duckdb { |
| 17 | class Catalog; |
| 18 | class Transaction; |
| 19 | |
| 20 | //! The DependencyManager is in charge of managing dependencies between catalog entries |
| 21 | class DependencyManager { |
| 22 | friend class CatalogSet; |
| 23 | |
| 24 | public: |
| 25 | DependencyManager(Catalog &catalog); |
| 26 | |
| 27 | //! Erase the object from the DependencyManager; this should only happen when the object itself is destroyed |
| 28 | void EraseObject(CatalogEntry *object); |
| 29 | // //! Clear all the dependencies of all entries in the catalog set |
| 30 | void ClearDependencies(CatalogSet &set); |
| 31 | |
| 32 | private: |
| 33 | Catalog &catalog; |
| 34 | //! Map of objects that DEPEND on [object], i.e. [object] can only be deleted when all entries in the dependency map |
| 35 | //! are deleted. |
| 36 | unordered_map<CatalogEntry *, unordered_set<CatalogEntry *>> dependents_map; |
| 37 | //! Map of objects that the source object DEPENDS on, i.e. when any of the entries in the vector perform a CASCADE |
| 38 | //! drop then [object] is deleted as wel |
| 39 | unordered_map<CatalogEntry *, unordered_set<CatalogEntry *>> dependencies_map; |
| 40 | |
| 41 | private: |
| 42 | void AddObject(Transaction &transaction, CatalogEntry *object, unordered_set<CatalogEntry *> &dependencies); |
| 43 | void DropObject(Transaction &transaction, CatalogEntry *object, bool cascade, set_lock_map_t &lock_set); |
| 44 | void AlterObject(Transaction &transaction, CatalogEntry *old_obj, CatalogEntry *new_obj); |
| 45 | void EraseObjectInternal(CatalogEntry *object); |
| 46 | }; |
| 47 | } // namespace duckdb |
| 48 | |