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.
return statement_stream.str();
}
DatabaseOnDisk::DatabaseOnDisk(
    const String & name,
    const String & metadata_path_,
    const String & data_path_,
    const String & logger,
    const Context & context)
    : DatabaseWithOwnTablesBase(name, logger, context)
    , metadata_path(metadata_path_)
    , data_path(data_path_)
{
    Poco::File(context.getPath() + data_path).createDirectories();
    Poco::File(metadata_path).createDirectories();
}
void DatabaseOnDisk::createTable(
    const Context & context,
    const String & table_name,
    const StoragePtr & table,
    const ASTPtr & query)
{
    const auto & settings = context.getSettingsRef();
    const auto & create = query->as<ASTCreateQuery &>();
    assert(getDatabaseName() == create.database && table_name == create.table);
    
    
    /** The code is based on the assumption that all threads share the same order of operations
      * - creating the .sql.tmp file;
      * - adding a table to `tables`;
      * - rename .sql.tmp to .sql.