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#include "duckdb/catalog/dependency.hpp"
14#include "duckdb/catalog/catalog_entry_map.hpp"
15#include "duckdb/catalog/catalog_transaction.hpp"
16
17#include <functional>
18
19namespace duckdb {
20class DuckCatalog;
21class ClientContext;
22class DependencyList;
23
24//! The DependencyManager is in charge of managing dependencies between catalog entries
25class DependencyManager {
26 friend class CatalogSet;
27
28public:
29 explicit DependencyManager(DuckCatalog &catalog);
30
31 //! Erase the object from the DependencyManager; this should only happen when the object itself is destroyed
32 void EraseObject(CatalogEntry &object);
33
34 //! Scans all dependencies, returning pairs of (object, dependent)
35 void Scan(const std::function<void(CatalogEntry &, CatalogEntry &, DependencyType)> &callback);
36
37 void AddOwnership(CatalogTransaction transaction, CatalogEntry &owner, CatalogEntry &entry);
38
39private:
40 DuckCatalog &catalog;
41 //! Map of objects that DEPEND on [object], i.e. [object] can only be deleted when all entries in the dependency map
42 //! are deleted.
43 catalog_entry_map_t<dependency_set_t> dependents_map;
44 //! Map of objects that the source object DEPENDS on, i.e. when any of the entries in the vector perform a CASCADE
45 //! drop then [object] is deleted as well
46 catalog_entry_map_t<catalog_entry_set_t> dependencies_map;
47
48private:
49 void AddObject(CatalogTransaction transaction, CatalogEntry &object, DependencyList &dependencies);
50 void DropObject(CatalogTransaction transaction, CatalogEntry &object, bool cascade);
51 void AlterObject(CatalogTransaction transaction, CatalogEntry &old_obj, CatalogEntry &new_obj);
52 void EraseObjectInternal(CatalogEntry &object);
53};
54} // namespace duckdb
55