Repository: ClickHouse/ClickHouse
File: src/Interpreters/ClusterProxy/executeQuery.cpp (C++)

Code before:
    auto scalars = new_context->hasQueryContext() ? new_context->getQueryContext()->getScalars() : Scalars{};
    const auto & shard = cluster->getShardsInfo().at(0);

    const auto & settings = new_context->getSettingsRef();
    /// do not build local plan for distributed queries for now (address it later)
    if (settings[Setting::allow_experimental_analyzer] && settings[Setting::parallel_replicas_local_plan] && !shard_num)
    {
        auto local_replica_index = findLocalReplicaIndexAndUpdatePools(connection_pools, max_replicas_to_use, cluster);

        auto [local_plan, with_parallel_replicas] = createLocalPlanForParallelReplicas(
            query_ast,
            *header,
            new_context,
            processed_stage,
            coordinator,
            std::move(analyzed_read_from_merge_tree),
            local_replica_index.value());

        if (!with_parallel_replicas || connection_pools.size() == 1)
        {
            query_plan = std::move(*local_plan);
            return;
        }

        std::shared_ptr<const QueryPlan> remote_query_plan;
        WriteBufferFromOwnString serialized_query_plan_buf;
        if (new_context->getSettingsRef()[Setting::serialize_query_plan])
        {
            remote_query_plan = createRemotePlanForParallelReplicas(query_ast, * header, new_context, processed_stage);
            remote_query_plan->ensureSerialized(DBMS_QUERY_PLAN_SERIALIZATION_VERSION);
        }

        auto read_from_local = std::make_unique<ReadFromLocalParallelReplicaStep>(std::move(local_plan));
        auto stub_local_plan = std::make_unique<QueryPlan>();
        stub_local_plan->addStep(std::move(read_from_local));

        LOG_DEBUG(logger, "Local replica got replica number {}", local_replica_index.value());

        auto read_from_remote = std::make_unique<ReadFromParallelRemoteReplicasStep>(
            query_ast,
            query_tree,
            planner_context,
            cluster,
            storage_id,
            coordinator,
            header,
            processed_stage,
            new_context,
            getThrottler(new_context),
            std::move(scalars),
            std::move(external_tables),

Review comment (performance):
`serialized_query_plan_buf` is declared but never used. In ClickHouse builds this typically triggers `-Wunused-variable` (often treated as an error), and even if not, it’s dead code. Remove the variable, or use it for serialization if that was the intent (but note `QueryPlan::ensureSerialized()` already caches internally).
```suggestion

```

Code after:
    auto scalars = new_context->hasQueryContext() ? new_context->getQueryContext()->getScalars() : Scalars{};
    const auto & shard = cluster->getShardsInfo().at(0);

    const auto & settings = new_context->getSettingsRef();
    /// do not build local plan for distributed queries for now (address it later)
    if (settings[Setting::allow_experimental_analyzer] && settings[Setting::parallel_replicas_local_plan] && !shard_num)
    {
        auto local_replica_index = findLocalReplicaIndexAndUpdatePools(connection_pools, max_replicas_to_use, cluster);

        auto [local_plan, with_parallel_replicas] = createLocalPlanForParallelReplicas(
            query_ast,
            *header,
            new_context,
            processed_stage,
            coordinator,
            std::move(analyzed_read_from_merge_tree),
            local_replica_index.value());

        if (!with_parallel_replicas || connection_pools.size() == 1)
        {
            query_plan = std::move(*local_plan);
            return;
        }

        std::shared_ptr<const QueryPlan> remote_query_plan;
        if (new_context->getSettingsRef()[Setting::serialize_query_plan])
        {
            remote_query_plan = createRemotePlanForParallelReplicas(query_ast, * header, new_context, processed_stage);
            remote_query_plan->ensureSerialized(DBMS_QUERY_PLAN_SERIALIZATION_VERSION);
        }

        auto read_from_local = std::make_unique<ReadFromLocalParallelReplicaStep>(std::move(local_plan));
        auto stub_local_plan = std::make_unique<QueryPlan>();
        stub_local_plan->addStep(std::move(read_from_local));

        LOG_DEBUG(logger, "Local replica got replica number {}", local_replica_index.value());

        auto read_from_remote = std::make_unique<ReadFromParallelRemoteReplicasStep>(
            query_ast,
            query_tree,
            planner_context,
            cluster,
            storage_id,
            coordinator,
            header,
            processed_stage,
            new_context,
            getThrottler(new_context),
            std::move(scalars),
            std::move(external_tables),
            getLogger("ReadFromParallelRemoteReplicasStep"),