Skip to content

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

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.

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