MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / removeDependency

Method removeDependency

src/Databases/TablesDependencyGraph.cpp:172–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170
171
172bool TablesDependencyGraph::removeDependency(const StorageID & table_id, const StorageID & dependency, bool remove_isolated_tables)
173{
174 auto * table_node = findNode(table_id);
175 if (!table_node)
176 return false;
177
178 auto * dependency_node = findNode(dependency);
179 if (!dependency_node)
180 return false;
181
182 auto dependency_it = table_node->dependencies.find(dependency_node);
183 if (dependency_it == table_node->dependencies.end())
184 return false; /// No such dependency, nothing to remove.
185
186 table_node->dependencies.erase(dependency_it);
187 bool table_node_removed = false;
188
189 /// `dependency_node` must be updated too.
190 [[maybe_unused]] bool removed_from_set = dependency_node->dependents.erase(table_node);
191 chassert(removed_from_set);
192
193 if (remove_isolated_tables && dependency_node->dependencies.empty() && dependency_node->dependents.empty())
194 {
195 /// The dependency table has no dependencies and no dependents now, so we will remove it from the graph.
196 removeNode(dependency_node);
197 if (table_node == dependency_node)
198 table_node_removed = true;
199 }
200
201 if (remove_isolated_tables && !table_node_removed && table_node->dependencies.empty() && table_node->dependents.empty())
202 {
203 /// The table `table_id` has no dependencies and no dependents now, so we will remove it from the graph.
204 removeNode(table_node);
205 }
206
207 setNeedRecalculateLevels();
208 return true;
209}
210
211
212std::vector<StorageID> TablesDependencyGraph::removeDependencies(const StorageID & table_id, bool remove_isolated_tables)

Callers 5

updateDatabaseNameMethod · 0.80
removeViewDependencyMethod · 0.80
removeDependenciesMethod · 0.80
updateDependenciesMethod · 0.80

Calls 4

findMethod · 0.45
endMethod · 0.45
eraseMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected