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

{
    auto database_table_iterators = getDatabaseIterators(getContext());
    for (auto & iterator : database_table_iterators)
    {
        while (iterator->isValid())
        {
            const auto & table = iterator->table();
            if (table.get() != this && predicate(table))
                return table;
            iterator->next();
        }
    }
    return {};
}
template <typename F>
void StorageMerge::forEachTable(F && func) const
{
    getFirstTable([&func](const auto & table)
    {
        func(table);
        return false;
    });
}
bool StorageMerge::isRemote() const
{
    auto first_remote_table = getFirstTable([](const StoragePtr & table) { return table && table->isRemote(); });
    return first_remote_table != nullptr;
}
bool StorageMerge::canMoveConditionsToPrewhere() const