We use Merge Table Engine to merge a ReplicatedMergeTree Engine table and a normal view without Distributed Table Engine based on another ReplicatedMergeTree Engine table.

And we found that the Merge Table Engine does not use the indexes of view.

But if we use Distributed Table Engine to make these tables and views distributed, the Merge Table Engine will use their indexes.

So what is the difference between these two modes?


ClickHouse version: 21.9.2.17

}
    if (filter_by_table_virtual_column)
    {
        
        Block virtual_columns_block = Block{ColumnWithTypeAndName(std::move(table_name_virtual_column), std::make_shared<DataTypeString>(), "_table")};
        VirtualColumnUtils::filterBlockWithQuery(query, virtual_columns_block, query_context);
        auto values = VirtualColumnUtils::extractSingleValueFromBlock<String>(virtual_columns_block, "_table");
        
        selected_tables.remove_if([&](const auto & elem) { return values.find(std::get<3>(elem)) == values.end(); });
    }
    return selected_tables;
}
DatabaseTablesIteratorPtr StorageMerge::getDatabaseIterator(const String & database_name, ContextPtr local_context) const
{
    auto database = DatabaseCatalog::instance().getDatabase(database_name);
    auto table_name_match = [this, database_name](const String & table_name_) -> bool
    {
        if (source_databases_and_tables)
        {
            if (auto it = source_databases_and_tables->find(database_name); it != source_databases_and_tables->end())
                return it->second.contains(table_name_);
            else
                return false;
        }
        else
            return source_table_regexp->match(table_name_);
    };
    return database->getTablesIterator(local_context, table_name_match);
}
StorageMerge::DatabaseTablesIterators StorageMerge::getDatabaseIterators(ContextPtr local_context) const