It hurts if server has millions of tables.

See https://github.com/ClickHouse/ClickHouse/pull/3398
Please add some tests to ensure it won't be broken in future.
if (metadata.select.select_query)
    {
        ast->replace(ast_create_query.select, metadata.select.select_query);
    }
    
    if (ast_create_query.storage)
    {
        ASTStorage & storage_ast = *ast_create_query.storage;
        
        if (metadata.sorting_key.definition_ast && storage_ast.order_by)
            storage_ast.set(storage_ast.order_by, metadata.sorting_key.definition_ast);
        if (metadata.primary_key.definition_ast)
            storage_ast.set(storage_ast.primary_key, metadata.primary_key.definition_ast);
        if (metadata.table_ttl.definition_ast)
            storage_ast.set(storage_ast.ttl_table, metadata.table_ttl.definition_ast);
        if (metadata.settings_changes)
            storage_ast.set(storage_ast.settings, metadata.settings_changes);
    }
    statement = getObjectDefinitionFromCreateQuery(ast);
    {
        WriteBufferFromFile out(table_metadata_tmp_path, statement.size(), O_WRONLY | O_CREAT | O_EXCL);
        writeString(statement, out);
        out.next();
        if (context.getSettingsRef().fsync_metadata)
            out.sync();
        out.close();
    }
    commitAlterTable(table_id, table_metadata_tmp_path, table_metadata_path);
}
void DatabaseOrdinary::commitAlterTable(const StorageID &, const String & table_metadata_tmp_path, const String & table_metadata_path)