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 (dir_it.name().at(0) == '.')
            continue;
        
        if (endsWith(dir_it.name(), ".sql.bak"))
            continue;
        static const char * tmp_drop_ext = ".sql.tmp_drop";
        if (endsWith(dir_it.name(), tmp_drop_ext))
        {
            
            process_tmp_drop_metadata_file(dir_it.name());
        }
        else if (endsWith(dir_it.name(), ".sql.tmp"))
        {
            
            LOG_INFO(log, "Removing file {}", dir_it->path());
            Poco::File(dir_it->path()).remove();
        }
        else if (endsWith(dir_it.name(), ".sql"))
        {
            
            process_metadata_file(dir_it.name());
        }
        else
            throw Exception("Incorrect file extension: " + dir_it.name() + " in metadata directory " + getMetadataPath(),
                ErrorCodes::INCORRECT_FILE_NAME);
    }
}
ASTPtr DatabaseOnDisk::parseQueryFromMetadata(Poco::Logger * logger, const Context & context, const String & metadata_file_path, bool throw_on_error , bool remove_empty )