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 (!where_expression)
        return;
    if (processed_stage > QueryProcessingStage::FetchColumns)
    {
        for (size_t column_index : collections::range(0, header.columns()))
        {
            ColumnWithTypeAndName header_column = header.getByPosition(column_index);
            ColumnWithTypeAndName before_column = before_block_header.getByName(header_column.name);
            
            
            
            if (!header_column.type->equals(*before_column.type.get()))
            {
                NamesAndTypesList source_columns = metadata_snapshot->getSampleBlock().getNamesAndTypesList();
                auto virtual_column = *storage_merge->getVirtuals().tryGetByName("_table");
                source_columns.emplace_back(NameAndTypePair{virtual_column.name, virtual_column.type});
                auto syntax_result = TreeRewriter(local_context).analyze(where_expression, source_columns);
                ExpressionActionsPtr actions = ExpressionAnalyzer{where_expression, syntax_result, local_context}.getActions(false, false);
                Names required_columns = actions->getRequiredColumns();
                for (const auto & required_column : required_columns)
                {
                    if (required_column == header_column.name)
                        throw Exception("Block structure mismatch in Merge Storage: different types:\n" + before_block_header.dumpStructure()
                                        + "\n" + header.dumpStructure(), ErrorCodes::LOGICAL_ERROR);
                }
            }
        }
    }
}
IStorage::ColumnSizeByName StorageMerge::getColumnSizes() const