2011-11-05 23:31:19 +00:00
|
|
|
#include <Poco/File.h>
|
|
|
|
|
2017-12-20 07:39:52 +00:00
|
|
|
#include <Databases/IDatabase.h>
|
2017-05-23 18:01:50 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-12-20 07:39:52 +00:00
|
|
|
#include <Interpreters/DDLWorker.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterpreterDropQuery.h>
|
2019-10-15 18:04:17 +00:00
|
|
|
#include <Interpreters/ExternalDictionariesLoader.h>
|
2020-01-26 09:49:53 +00:00
|
|
|
#include <Access/AccessRightsElement.h>
|
2017-12-20 07:39:52 +00:00
|
|
|
#include <Parsers/ASTDropQuery.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2017-12-20 07:39:52 +00:00
|
|
|
#include <Common/escapeForFileName.h>
|
2019-10-08 18:42:22 +00:00
|
|
|
#include <Common/quoteString.h>
|
2017-12-20 07:39:52 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2011-11-05 23:31:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2017-12-22 19:20:18 +00:00
|
|
|
|
2016-01-11 21:46:36 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
extern const int TABLE_WAS_NOT_DROPPED;
|
|
|
|
extern const int DATABASE_NOT_EMPTY;
|
|
|
|
extern const int UNKNOWN_DATABASE;
|
2017-12-20 07:39:52 +00:00
|
|
|
extern const int READONLY;
|
2018-04-21 00:35:20 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
2018-06-09 16:03:07 +00:00
|
|
|
extern const int SYNTAX_ERROR;
|
2018-04-21 00:35:20 +00:00
|
|
|
extern const int UNKNOWN_TABLE;
|
2018-09-11 18:37:19 +00:00
|
|
|
extern const int QUERY_IS_PROHIBITED;
|
2019-10-11 13:21:52 +00:00
|
|
|
extern const int UNKNOWN_DICTIONARY;
|
2016-01-11 21:46:36 +00:00
|
|
|
}
|
|
|
|
|
2011-11-05 23:31:19 +00:00
|
|
|
|
2017-12-20 07:39:52 +00:00
|
|
|
InterpreterDropQuery::InterpreterDropQuery(const ASTPtr & query_ptr_, Context & context_) : query_ptr(query_ptr_), context(context_) {}
|
2011-11-05 23:31:19 +00:00
|
|
|
|
|
|
|
|
2015-06-18 02:11:05 +00:00
|
|
|
BlockIO InterpreterDropQuery::execute()
|
2017-04-13 16:12:56 +00:00
|
|
|
{
|
2019-03-15 16:14:13 +00:00
|
|
|
auto & drop = query_ptr->as<ASTDropQuery &>();
|
|
|
|
if (!drop.cluster.empty())
|
2020-01-24 16:20:36 +00:00
|
|
|
return executeDDLQueryOnCluster(query_ptr, context, getRequiredAccessForDDLOnCluster());
|
2017-04-13 16:12:56 +00:00
|
|
|
|
2019-03-15 16:14:13 +00:00
|
|
|
if (!drop.table.empty())
|
2019-10-11 13:21:52 +00:00
|
|
|
{
|
|
|
|
if (!drop.is_dictionary)
|
|
|
|
return executeToTable(drop.database, drop.table, drop.kind, drop.if_exists, drop.temporary, drop.no_ddl_lock);
|
|
|
|
else
|
|
|
|
return executeToDictionary(drop.database, drop.table, drop.kind, drop.if_exists, drop.temporary, drop.no_ddl_lock);
|
|
|
|
}
|
2019-03-15 16:14:13 +00:00
|
|
|
else if (!drop.database.empty())
|
|
|
|
return executeToDatabase(drop.database, drop.kind, drop.if_exists);
|
2018-04-21 00:35:20 +00:00
|
|
|
else
|
2019-10-11 13:21:52 +00:00
|
|
|
throw Exception("Nothing to drop, both names are empty.", ErrorCodes::LOGICAL_ERROR);
|
2018-04-21 00:35:20 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
|
2019-10-11 13:21:52 +00:00
|
|
|
BlockIO InterpreterDropQuery::executeToTable(
|
2020-01-24 16:20:36 +00:00
|
|
|
const String & database_name_,
|
|
|
|
const String & table_name,
|
2019-10-11 13:21:52 +00:00
|
|
|
ASTDropQuery::Kind kind,
|
|
|
|
bool if_exists,
|
2020-01-29 19:54:40 +00:00
|
|
|
bool is_temporary,
|
2019-10-11 13:21:52 +00:00
|
|
|
bool no_ddl_lock)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2020-01-29 19:54:40 +00:00
|
|
|
if (is_temporary || database_name_.empty())
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-04-21 00:35:20 +00:00
|
|
|
auto & session_context = context.hasSessionContext() ? context.getSessionContext() : context;
|
|
|
|
if (session_context.isExternalTableExist(table_name))
|
|
|
|
return executeToTemporaryTable(table_name, kind);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
2020-01-29 19:54:40 +00:00
|
|
|
if (is_temporary)
|
|
|
|
{
|
|
|
|
if (if_exists)
|
2020-01-24 16:20:36 +00:00
|
|
|
return {};
|
2020-01-29 19:54:40 +00:00
|
|
|
throw Exception("Temporary table " + backQuoteIfNeed(table_name) + " doesn't exist.",
|
|
|
|
ErrorCodes::UNKNOWN_TABLE);
|
|
|
|
}
|
|
|
|
|
2020-02-10 13:10:17 +00:00
|
|
|
String database_name = context.resolveDatabase(database_name_);
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2020-02-10 18:31:52 +00:00
|
|
|
auto ddl_guard = (!no_ddl_lock ? DatabaseCatalog::instance().getDDLGuard(database_name, table_name) : nullptr);
|
2018-09-18 18:33:15 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
auto [database, table] = tryGetDatabaseAndTable(database_name, table_name, if_exists);
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
if (database && table)
|
2017-08-15 12:34:28 +00:00
|
|
|
{
|
2020-01-24 16:20:36 +00:00
|
|
|
auto table_id = table->getStorageID();
|
2018-04-21 00:35:20 +00:00
|
|
|
if (kind == ASTDropQuery::Kind::Detach)
|
2017-08-15 17:00:18 +00:00
|
|
|
{
|
2020-01-24 16:20:36 +00:00
|
|
|
context.checkAccess(table->isView() ? AccessType::DETACH_VIEW : AccessType::DETACH_TABLE,
|
|
|
|
database_name, table_name);
|
|
|
|
table->shutdown();
|
2018-04-21 00:35:20 +00:00
|
|
|
/// If table was already dropped by anyone, an exception will be thrown
|
2020-01-24 16:20:36 +00:00
|
|
|
auto table_lock = table->lockExclusively(context.getCurrentQueryId());
|
2018-04-21 00:35:20 +00:00
|
|
|
/// Drop table from memory, don't touch data and metadata
|
2020-01-24 16:20:36 +00:00
|
|
|
database->detachTable(table_name);
|
2018-04-21 00:35:20 +00:00
|
|
|
}
|
|
|
|
else if (kind == ASTDropQuery::Kind::Truncate)
|
|
|
|
{
|
2020-01-24 16:20:36 +00:00
|
|
|
context.checkAccess(table->isView() ? AccessType::TRUNCATE_VIEW : AccessType::TRUNCATE_TABLE,
|
|
|
|
database_name, table_name);
|
|
|
|
table->checkTableCanBeDropped();
|
2018-06-09 15:48:22 +00:00
|
|
|
|
2018-04-21 00:35:20 +00:00
|
|
|
/// If table was already dropped by anyone, an exception will be thrown
|
2020-01-24 16:20:36 +00:00
|
|
|
auto table_lock = table->lockExclusively(context.getCurrentQueryId());
|
2018-04-21 00:35:20 +00:00
|
|
|
/// Drop table data, don't touch metadata
|
2020-01-24 16:20:36 +00:00
|
|
|
table->truncate(query_ptr, context, table_lock);
|
2018-04-21 00:35:20 +00:00
|
|
|
}
|
|
|
|
else if (kind == ASTDropQuery::Kind::Drop)
|
|
|
|
{
|
2020-01-24 16:20:36 +00:00
|
|
|
context.checkAccess(table->isView() ? AccessType::DROP_VIEW : AccessType::DROP_TABLE,
|
|
|
|
database_name, table_name);
|
|
|
|
table->checkTableCanBeDropped();
|
2018-04-21 00:35:20 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
table->shutdown();
|
2018-04-21 00:35:20 +00:00
|
|
|
/// If table was already dropped by anyone, an exception will be thrown
|
2018-11-28 15:59:57 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
auto table_lock = table->lockExclusively(context.getCurrentQueryId());
|
2019-08-28 18:54:30 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
const std::string metadata_file_without_extension = database->getMetadataPath() + escapeForFileName(table_id.table_name);
|
2019-08-28 18:54:30 +00:00
|
|
|
const auto prev_metadata_name = metadata_file_without_extension + ".sql";
|
|
|
|
const auto drop_metadata_name = metadata_file_without_extension + ".sql.tmp_drop";
|
2019-08-09 11:17:33 +00:00
|
|
|
|
2019-08-28 18:34:42 +00:00
|
|
|
/// Try to rename metadata file and delete the data
|
2019-08-09 11:17:33 +00:00
|
|
|
try
|
|
|
|
{
|
2019-08-28 18:54:30 +00:00
|
|
|
/// There some kind of tables that have no metadata - ignore renaming
|
2019-08-13 08:03:31 +00:00
|
|
|
if (Poco::File(prev_metadata_name).exists())
|
2019-08-12 12:56:10 +00:00
|
|
|
Poco::File(prev_metadata_name).renameTo(drop_metadata_name);
|
2019-08-09 11:17:33 +00:00
|
|
|
/// Delete table data
|
2020-01-24 16:20:36 +00:00
|
|
|
table->drop(table_lock);
|
2019-08-09 11:17:33 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2019-08-13 08:03:31 +00:00
|
|
|
if (Poco::File(drop_metadata_name).exists())
|
2019-08-12 10:13:03 +00:00
|
|
|
Poco::File(drop_metadata_name).renameTo(prev_metadata_name);
|
2019-08-09 11:17:33 +00:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
String table_data_path_relative = database->getTableDataPath(table_name);
|
2019-12-25 16:13:48 +00:00
|
|
|
|
2019-08-09 11:17:33 +00:00
|
|
|
/// Delete table metadata and table itself from memory
|
2020-01-24 16:20:36 +00:00
|
|
|
database->removeTable(context, table_name);
|
|
|
|
table->is_dropped = true;
|
2018-04-21 00:35:20 +00:00
|
|
|
|
|
|
|
/// If it is not virtual database like Dictionary then drop remaining data dir
|
2019-12-25 16:13:48 +00:00
|
|
|
if (!table_data_path_relative.empty())
|
2018-02-02 13:17:45 +00:00
|
|
|
{
|
2019-12-25 16:13:48 +00:00
|
|
|
String table_data_path = context.getPath() + table_data_path_relative;
|
2018-04-21 00:35:20 +00:00
|
|
|
if (Poco::File(table_data_path).exists())
|
|
|
|
Poco::File(table_data_path).remove(true);
|
2018-02-02 13:17:45 +00:00
|
|
|
}
|
2018-04-21 00:35:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-10-11 13:21:52 +00:00
|
|
|
|
|
|
|
BlockIO InterpreterDropQuery::executeToDictionary(
|
2020-01-24 16:20:36 +00:00
|
|
|
const String & database_name_,
|
|
|
|
const String & dictionary_name,
|
2019-10-11 13:21:52 +00:00
|
|
|
ASTDropQuery::Kind kind,
|
|
|
|
bool if_exists,
|
|
|
|
bool is_temporary,
|
|
|
|
bool no_ddl_lock)
|
|
|
|
{
|
|
|
|
if (is_temporary)
|
|
|
|
throw Exception("Temporary dictionaries are not possible.", ErrorCodes::SYNTAX_ERROR);
|
|
|
|
|
2020-02-10 13:10:17 +00:00
|
|
|
String database_name = context.resolveDatabase(database_name_);
|
2019-10-11 13:21:52 +00:00
|
|
|
|
2020-02-10 18:31:52 +00:00
|
|
|
auto ddl_guard = (!no_ddl_lock ? DatabaseCatalog::instance().getDDLGuard(database_name, dictionary_name) : nullptr);
|
2019-10-11 13:21:52 +00:00
|
|
|
|
2019-12-12 16:50:20 +00:00
|
|
|
DatabasePtr database = tryGetDatabase(database_name, if_exists);
|
2019-10-11 13:21:52 +00:00
|
|
|
|
|
|
|
if (!database || !database->isDictionaryExist(context, dictionary_name))
|
|
|
|
{
|
|
|
|
if (!if_exists)
|
|
|
|
throw Exception(
|
|
|
|
"Dictionary " + backQuoteIfNeed(database_name) + "." + backQuoteIfNeed(dictionary_name) + " doesn't exist.",
|
|
|
|
ErrorCodes::UNKNOWN_DICTIONARY);
|
|
|
|
else
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kind == ASTDropQuery::Kind::Detach)
|
|
|
|
{
|
|
|
|
/// Drop dictionary from memory, don't touch data and metadata
|
2020-01-24 16:20:36 +00:00
|
|
|
context.checkAccess(AccessType::DETACH_DICTIONARY, database_name, dictionary_name);
|
2019-10-16 17:06:52 +00:00
|
|
|
database->detachDictionary(dictionary_name, context);
|
2019-10-11 13:21:52 +00:00
|
|
|
}
|
|
|
|
else if (kind == ASTDropQuery::Kind::Truncate)
|
|
|
|
{
|
|
|
|
throw Exception("Cannot TRUNCATE dictionary", ErrorCodes::SYNTAX_ERROR);
|
|
|
|
}
|
|
|
|
else if (kind == ASTDropQuery::Kind::Drop)
|
|
|
|
{
|
2020-01-24 16:20:36 +00:00
|
|
|
context.checkAccess(AccessType::DROP_DICTIONARY, database_name, dictionary_name);
|
2019-10-11 13:21:52 +00:00
|
|
|
database->removeDictionary(context, dictionary_name);
|
|
|
|
}
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
BlockIO InterpreterDropQuery::executeToTemporaryTable(const String & table_name, ASTDropQuery::Kind kind)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
|
|
|
if (kind == ASTDropQuery::Kind::Detach)
|
|
|
|
throw Exception("Unable to detach temporary table.", ErrorCodes::SYNTAX_ERROR);
|
2018-07-10 14:24:19 +00:00
|
|
|
else
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2018-07-10 14:24:19 +00:00
|
|
|
auto & context_handle = context.hasSessionContext() ? context.getSessionContext() : context;
|
2020-02-12 18:14:12 +00:00
|
|
|
auto resolved_id = context_handle.tryResolveStorageID(StorageID("", table_name), Context::ResolveExternal);
|
|
|
|
if (resolved_id)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2020-02-12 18:14:12 +00:00
|
|
|
StoragePtr table = DatabaseCatalog::instance().getTable(resolved_id, context);
|
2018-07-10 14:24:19 +00:00
|
|
|
if (kind == ASTDropQuery::Kind::Truncate)
|
|
|
|
{
|
|
|
|
/// If table was already dropped by anyone, an exception will be thrown
|
2019-03-05 10:12:20 +00:00
|
|
|
auto table_lock = table->lockExclusively(context.getCurrentQueryId());
|
2018-07-10 14:24:19 +00:00
|
|
|
/// Drop table data, don't touch metadata
|
2019-08-27 20:43:08 +00:00
|
|
|
table->truncate(query_ptr, context, table_lock);
|
2018-07-10 14:24:19 +00:00
|
|
|
}
|
|
|
|
else if (kind == ASTDropQuery::Kind::Drop)
|
|
|
|
{
|
2020-01-30 19:00:51 +00:00
|
|
|
context_handle.removeExternalTable(table_name);
|
2018-07-10 14:24:19 +00:00
|
|
|
table->shutdown();
|
|
|
|
/// If table was already dropped by anyone, an exception will be thrown
|
2019-03-05 10:12:20 +00:00
|
|
|
auto table_lock = table->lockExclusively(context.getCurrentQueryId());
|
2018-07-10 14:24:19 +00:00
|
|
|
/// Delete table data
|
2019-08-27 20:43:08 +00:00
|
|
|
table->drop(table_lock);
|
2018-07-10 14:24:19 +00:00
|
|
|
table->is_dropped = true;
|
|
|
|
}
|
2017-08-15 17:00:18 +00:00
|
|
|
}
|
2017-08-15 12:34:28 +00:00
|
|
|
}
|
|
|
|
|
2018-04-21 00:35:20 +00:00
|
|
|
return {};
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
BlockIO InterpreterDropQuery::executeToDatabase(const String & database_name, ASTDropQuery::Kind kind, bool if_exists)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2020-02-10 18:31:52 +00:00
|
|
|
auto ddl_guard = DatabaseCatalog::instance().getDDLGuard(database_name, "");
|
2018-09-18 18:33:15 +00:00
|
|
|
|
2018-04-21 00:35:20 +00:00
|
|
|
if (auto database = tryGetDatabase(database_name, if_exists))
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-04-21 00:35:20 +00:00
|
|
|
if (kind == ASTDropQuery::Kind::Truncate)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
2018-04-21 00:35:20 +00:00
|
|
|
throw Exception("Unable to truncate database.", ErrorCodes::SYNTAX_ERROR);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2020-02-13 21:00:03 +00:00
|
|
|
else if (kind == ASTDropQuery::Kind::Detach || kind == ASTDropQuery::Kind::Drop)
|
2017-06-13 16:36:15 +00:00
|
|
|
{
|
2020-02-13 21:00:03 +00:00
|
|
|
bool drop = kind == ASTDropQuery::Kind::Drop;
|
|
|
|
if (drop)
|
|
|
|
context.checkAccess(AccessType::DROP_DATABASE, database_name);
|
|
|
|
else
|
|
|
|
context.checkAccess(AccessType::DETACH_DATABASE, database_name);
|
2020-01-24 16:20:36 +00:00
|
|
|
|
2020-02-13 21:00:03 +00:00
|
|
|
/// DETACH or DROP all tables and dictionaries inside database
|
2019-10-10 17:33:01 +00:00
|
|
|
for (auto iterator = database->getTablesIterator(context); iterator->isValid(); iterator->next())
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2019-10-01 12:44:17 +00:00
|
|
|
String current_table_name = iterator->name();
|
2019-03-11 16:50:31 +00:00
|
|
|
executeToTable(database_name, current_table_name, kind, false, false, false);
|
2018-04-21 00:35:20 +00:00
|
|
|
}
|
2017-06-13 16:36:15 +00:00
|
|
|
|
2019-10-11 15:22:30 +00:00
|
|
|
for (auto iterator = database->getDictionariesIterator(context); iterator->isValid(); iterator->next())
|
|
|
|
{
|
|
|
|
String current_dictionary = iterator->name();
|
|
|
|
executeToDictionary(database_name, current_dictionary, kind, false, false, false);
|
|
|
|
}
|
|
|
|
|
2020-02-13 21:00:03 +00:00
|
|
|
/// DETACH or DROP database itself
|
|
|
|
DatabaseCatalog::instance().detachDatabase(database_name, drop);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-21 00:35:20 +00:00
|
|
|
return {};
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
DatabasePtr InterpreterDropQuery::tryGetDatabase(const String & database_name, bool if_exists)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
2020-02-10 13:10:17 +00:00
|
|
|
return if_exists ? DatabaseCatalog::instance().tryGetDatabase(database_name) : DatabaseCatalog::instance().getDatabase(database_name);
|
2018-04-21 00:35:20 +00:00
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
DatabaseAndTable InterpreterDropQuery::tryGetDatabaseAndTable(const String & database_name, const String & table_name, bool if_exists)
|
2018-04-21 00:35:20 +00:00
|
|
|
{
|
|
|
|
DatabasePtr database = tryGetDatabase(database_name, if_exists);
|
2018-02-08 14:14:08 +00:00
|
|
|
|
2018-04-21 00:35:20 +00:00
|
|
|
if (database)
|
|
|
|
{
|
|
|
|
StoragePtr table = database->tryGetTable(context, table_name);
|
|
|
|
if (!table && !if_exists)
|
|
|
|
throw Exception("Table " + backQuoteIfNeed(database_name) + "." + backQuoteIfNeed(table_name) + " doesn't exist.",
|
|
|
|
ErrorCodes::UNKNOWN_TABLE);
|
2018-01-25 19:01:11 +00:00
|
|
|
|
2018-09-07 01:39:48 +00:00
|
|
|
return {std::move(database), std::move(table)};
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
return {};
|
2014-03-20 10:59:45 +00:00
|
|
|
}
|
|
|
|
|
2015-12-13 12:02:10 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
AccessRightsElements InterpreterDropQuery::getRequiredAccessForDDLOnCluster() const
|
|
|
|
{
|
|
|
|
AccessRightsElements required_access;
|
|
|
|
const auto & drop = query_ptr->as<const ASTDropQuery &>();
|
2017-12-20 07:39:52 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
if (drop.table.empty())
|
|
|
|
{
|
|
|
|
if (drop.kind == ASTDropQuery::Kind::Detach)
|
|
|
|
required_access.emplace_back(AccessType::DETACH_DATABASE, drop.database);
|
|
|
|
else if (drop.kind == ASTDropQuery::Kind::Drop)
|
|
|
|
required_access.emplace_back(AccessType::DROP_DATABASE, drop.database);
|
|
|
|
}
|
|
|
|
else if (drop.is_dictionary)
|
|
|
|
{
|
|
|
|
if (drop.kind == ASTDropQuery::Kind::Detach)
|
|
|
|
required_access.emplace_back(AccessType::DETACH_DICTIONARY, drop.database, drop.table);
|
|
|
|
else if (drop.kind == ASTDropQuery::Kind::Drop)
|
|
|
|
required_access.emplace_back(AccessType::DROP_DICTIONARY, drop.database, drop.table);
|
|
|
|
}
|
|
|
|
else if (!drop.temporary)
|
|
|
|
{
|
|
|
|
/// It can be view or table.
|
|
|
|
if (drop.kind == ASTDropQuery::Kind::Drop)
|
|
|
|
required_access.emplace_back(AccessType::DROP_TABLE | AccessType::DROP_VIEW, drop.database, drop.table);
|
|
|
|
else if (drop.kind == ASTDropQuery::Kind::Truncate)
|
|
|
|
required_access.emplace_back(AccessType::TRUNCATE_TABLE | AccessType::TRUNCATE_VIEW, drop.database, drop.table);
|
|
|
|
else if (drop.kind == ASTDropQuery::Kind::Detach)
|
|
|
|
required_access.emplace_back(AccessType::DETACH_TABLE | AccessType::DETACH_VIEW, drop.database, drop.table);
|
|
|
|
}
|
2018-09-11 18:37:19 +00:00
|
|
|
|
2020-01-24 16:20:36 +00:00
|
|
|
return required_access;
|
2017-12-20 07:39:52 +00:00
|
|
|
}
|
2017-12-22 19:20:18 +00:00
|
|
|
|
2011-11-05 23:31:19 +00:00
|
|
|
}
|