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

{
    
    
    
    
    
    return getFirstTable([](const auto & table) { return !table->canMoveConditionsToPrewhere(); }) == nullptr;
}
bool StorageMerge::mayBenefitFromIndexForIn(const ASTPtr & left_in_operand, ContextPtr query_context, const StorageMetadataPtr & ) const
{
    
    StorageListWithLocks selected_tables = getSelectedTables(query_context);
    size_t i = 0;
    for (const auto & table : selected_tables)
    {
        const auto & storage_ptr = std::get<1>(table);
        auto metadata_snapshot = storage_ptr->getInMemoryMetadataPtr();
        if (storage_ptr->mayBenefitFromIndexForIn(left_in_operand, query_context, metadata_snapshot))
            return true;
        ++i;
        
        if (i > 10)
            break;
    }
    return false;
}
QueryProcessingStage::Enum StorageMerge::getQueryProcessingStage(