| 389 | } |
| 390 | |
| 391 | BlockIO InterpreterAlterQuery::executeToTable(const ASTAlterQuery & alter) |
| 392 | { |
| 393 | ASTSelectWithUnionQuery * modify_query = nullptr; |
| 394 | |
| 395 | for (auto & child : alter.command_list->children) |
| 396 | { |
| 397 | auto * command_ast = child->as<ASTAlterCommand>(); |
| 398 | if (command_ast->sql_security) |
| 399 | InterpreterCreateQuery::processSQLSecurityOption(getContext(), command_ast->sql_security->as<ASTSQLSecurity &>()); |
| 400 | else if (command_ast->type == ASTAlterCommand::MODIFY_QUERY) |
| 401 | modify_query = command_ast->select->as<ASTSelectWithUnionQuery>(); |
| 402 | } |
| 403 | |
| 404 | BlockIO res; |
| 405 | const auto & settings = getContext()->getSettingsRef(); |
| 406 | |
| 407 | if (!UserDefinedSQLFunctionFactory::instance().empty()) |
| 408 | UserDefinedSQLFunctionVisitor::visit(query_ptr, getContext()); |
| 409 | |
| 410 | auto table_id = getContext()->tryResolveStorageID(alter); |
| 411 | StoragePtr table; |
| 412 | |
| 413 | if (table_id) |
| 414 | { |
| 415 | query_ptr->as<ASTAlterQuery &>().setDatabase(table_id.database_name); |
| 416 | table = DatabaseCatalog::instance().tryGetTable(table_id, getContext()); |
| 417 | } |
| 418 | |
| 419 | if (!alter.cluster.empty() && !maybeRemoveOnCluster(query_ptr, getContext())) |
| 420 | { |
| 421 | if (table && table->as<StorageKeeperMap>()) |
| 422 | throw Exception(ErrorCodes::BAD_ARGUMENTS, "Mutations with ON CLUSTER are not allowed for KeeperMap tables"); |
| 423 | |
| 424 | DDLQueryOnClusterParams params; |
| 425 | params.access_to_check = getRequiredAccess(); |
| 426 | return executeDDLQueryOnCluster(query_ptr, getContext(), params); |
| 427 | } |
| 428 | |
| 429 | getContext()->checkAccess(getRequiredAccess()); |
| 430 | |
| 431 | if (!table_id) |
| 432 | throw Exception(ErrorCodes::UNKNOWN_DATABASE, "Database {} does not exist", backQuoteIfNeed(alter.getDatabase())); |
| 433 | |
| 434 | DatabasePtr database = DatabaseCatalog::instance().getDatabase(table_id.database_name); |
| 435 | if (database->shouldReplicateQuery(getContext(), query_ptr)) |
| 436 | { |
| 437 | auto guard = DatabaseCatalog::instance().getDDLGuard(table_id.database_name, table_id.table_name, database.get()); |
| 438 | guard->releaseTableLock(); |
| 439 | return database->tryEnqueueReplicatedDDL(query_ptr, getContext(), {}, std::move(guard)); |
| 440 | } |
| 441 | |
| 442 | #if CLICKHOUSE_CLOUD |
| 443 | if (SharedDatabaseCatalog::shouldReplicateQuery(getContext(), query_ptr)) |
| 444 | { |
| 445 | return SharedDatabaseCatalog::instance().tryExecuteDDLQuery(query_ptr, getContext()); |
| 446 | } |
| 447 | #endif |
| 448 |
nothing calls this directly
no test coverage detected