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

{
    ColumnSizeByName column_sizes;
    forEachTable([&](const auto & table)
    {
        for (const auto & [name, size] : table->getColumnSizes())
            column_sizes[name].add(size);
    });
    return column_sizes;
}
std::tuple<bool , ASTPtr> StorageMerge::evaluateDatabaseName(const ASTPtr & node, ContextPtr context_)
{
    if (const auto * func = node->as<ASTFunction>(); func && func->name == "REGEXP")
    {
        if (func->arguments->children.size() != 1)
            throw Exception("REGEXP in Merge ENGINE takes only one argument", ErrorCodes::BAD_ARGUMENTS);
        auto * literal = func->arguments->children[0]->as<ASTLiteral>();
        if (!literal || literal->value.getType() != Field::Types::Which::String || literal->value.safeGet<String>().empty())
            throw Exception("Argument for REGEXP in Merge ENGINE should be a non empty String Literal", ErrorCodes::BAD_ARGUMENTS);
        return {true, func->arguments->children[0]};
    }
    auto ast = evaluateConstantExpressionForDatabaseName(node, context_);
    return {false, ast};
}
void registerStorageMerge(StorageFactory & factory)