MCPcopy Create free account
hub / github.com/ByConity/ByConity / execute

Method execute

src/Interpreters/InterpreterRenameQuery.cpp:52–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51
52BlockIO InterpreterRenameQuery::execute()
53{
54 const auto & rename = query_ptr->as<const ASTRenameQuery &>();
55 auto access_type = rename.database ? RenameType::RenameDatabase : RenameType::RenameTable;
56
57 if (!rename.cluster.empty())
58 return executeDDLQueryOnCluster(query_ptr, getContext(), getRequiredAccess(access_type));
59
60 getContext()->checkAccess(getRequiredAccess(access_type));
61
62 String path = getContext()->getPath();
63 String current_database = getContext()->getCurrentDatabase();
64
65 /** In case of error while renaming, it is possible that only part of tables was renamed
66 * or we will be in inconsistent state. (It is worth to be fixed.)
67 */
68
69 RenameDescriptions descriptions;
70 descriptions.reserve(rename.elements.size());
71
72 /// Don't allow to drop tables (that we are renaming); don't allow to create tables in places where tables will be renamed.
73 TableGuards table_guards;
74
75 for (const auto & elem : rename.elements)
76 {
77 descriptions.emplace_back(elem, current_database);
78 const auto & description = descriptions.back();
79
80 UniqueTableName from(description.from_database_name, description.from_table_name);
81 UniqueTableName to(description.to_database_name, description.to_table_name);
82
83 table_guards[from];
84 table_guards[to];
85 }
86
87 auto & database_catalog = DatabaseCatalog::instance();
88
89 /// Must do it in consistent order.
90 for (auto & table_guard : table_guards)
91 table_guard.second = database_catalog.getDDLGuard(table_guard.first.database_name, table_guard.first.table_name);
92
93 if (rename.database)
94 return executeToDatabase(rename, descriptions);
95 else
96 return executeToTables(rename, descriptions, table_guards);
97}
98
99BlockIO InterpreterRenameQuery::executeToTables(const ASTRenameQuery & rename, const RenameDescriptions & descriptions, TableGuards & ddl_guards)
100{

Callers

nothing calls this directly

Calls 9

executeDDLQueryOnClusterFunction · 0.85
getCurrentDatabaseMethod · 0.80
getDDLGuardMethod · 0.80
emptyMethod · 0.45
checkAccessMethod · 0.45
getPathMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
emplace_backMethod · 0.45

Tested by

no test coverage detected