Skip to content

Thread PhysicalOptimizerContext through join_selection stats helpers (CBO extension pattern) #23671

Closed

Description

@asolimando

Is your feature request related to a problem or challenge?

JoinSelection's internal stats helpers (get_stats, should_swap_join_order,
supports_collect_by_thresholds) take Option<&StatisticsRegistry> and
&ConfigOptions pre-extracted from the PhysicalOptimizerContext. Every new
session-scoped input added to the context for cost-based estimation forces a
signature change across all three helpers and their call sites.

Describe the solution you'd like

Pass &dyn PhysicalOptimizerContext to these helpers instead; they read
statistics_registry() / config_options() off it. New context inputs then need
no helper-signature changes.

This is also the pattern any future physical optimizer rule implementing CBO
should follow: take the PhysicalOptimizerContext and read what it needs off it,
rather than threading individual extracted inputs.

Describe alternatives you've considered

  • Keep threading individual params — every new input churns all three signatures.
  • Pass SessionState directly — not possible; datafusion-physical-optimizer
    can't depend on datafusion-core, which is why PhysicalOptimizerContext
    exists.

Additional context

Non-breaking, mechanical: the helpers are crate-internal (get_stats /
supports_collect_by_thresholds private, should_swap_join_order pub(crate)),
no cross-crate callers, public PhysicalOptimizerRule methods unchanged.

Activity

  1. asolimando commented on Jul 17, 2026

    @asolimando
    MemberAuthor

    take

  2. asolimando commented on Jul 29, 2026

    @asolimando
    MemberAuthor

    This actually depends on #23651, so waiting for that contribution to land before we can create a PR

  3. added a commit that references this issue on Sep 1, 2026
    19d31c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions