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

Method getTablesForBackup

src/Databases/DatabaseMemory.cpp:188–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188std::vector<std::pair<ASTPtr, StoragePtr>> DatabaseMemory::getTablesForBackup(const FilterByNameFunction & filter, const ContextPtr & local_context) const
189{
190 /// We need a special processing for the temporary database.
191 if (getDatabaseName() != DatabaseCatalog::TEMPORARY_DATABASE)
192 return DatabaseWithOwnTablesBase::getTablesForBackup(filter, local_context);
193
194 std::vector<std::pair<ASTPtr, StoragePtr>> res;
195
196 /// `this->tables` for the temporary database doesn't contain real names of tables.
197 /// That's why we need to call Context::getExternalTables() and then resolve those names using tryResolveStorageID() below.
198 auto external_tables = local_context->getExternalTables();
199
200 for (const auto & [table_name, storage] : external_tables)
201 {
202 if (!filter(table_name))
203 continue;
204
205 auto storage_id = local_context->tryResolveStorageID(StorageID{"", table_name}, Context::ResolveExternal);
206 if (!storage_id)
207 {
208 LOG_WARNING(log, "Couldn't resolve the name of temporary table {}", backQuoteIfNeed(table_name));
209 continue;
210 }
211
212 /// Here `storage_id.table_name` looks like looks like "_tmp_ab9b15a3-fb43-4670-abec-14a0e9eb70f1"
213 /// it's not the real name of the table.
214 auto create_table_query = tryGetCreateTableQuery(storage_id.table_name, local_context);
215 if (!create_table_query)
216 {
217 LOG_WARNING(log, "Couldn't get a create query for temporary table {}", backQuoteIfNeed(table_name));
218 continue;
219 }
220
221 auto * create = create_table_query->as<ASTCreateQuery>();
222 if (create->getTable() != table_name)
223 {
224 /// Probably the database has been just renamed. Use the older name for backup to keep the backup consistent.
225 LOG_WARNING(log, "Got a create query with unexpected name {} for temporary table {}",
226 backQuoteIfNeed(create->getTable()), backQuoteIfNeed(table_name));
227 create_table_query = create_table_query->clone();
228 create = create_table_query->as<ASTCreateQuery>();
229 create->setTable(table_name);
230 }
231
232 chassert(storage);
233 storage->applyMetadataChangesToCreateQueryForBackup(create_table_query);
234 res.emplace_back(create_table_query, storage);
235 }
236
237 return res;
238}
239
240void registerDatabaseMemory(DatabaseFactory & factory);
241void registerDatabaseMemory(DatabaseFactory & factory)

Callers

nothing calls this directly

Calls 8

backQuoteIfNeedFunction · 0.85
getExternalTablesMethod · 0.80
tryResolveStorageIDMethod · 0.80
getTableMethod · 0.45
cloneMethod · 0.45
setTableMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected