Skip to content

refactor(planner): extract the Stage 2 physical-optimizer crate - #584

Draft
zzylol wants to merge 1 commit into
stack/572-b2-logical-optimizerfrom
stack/572-b3-physical-optimizer
Draft

zzylol wants to merge 1 commit into
stack/572-b2-logical-optimizerfrom
stack/572-b3-physical-optimizer

Conversation

@zzylol

@zzylol zzylol commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Why

#572 puts each #509 stage in its own crate so that Cargo enforces the one-way stage flow. This PR is step B3: Stage 2 (physical candidates) moves out of asap-aware-mapping into a new crate, asap-physical-optimizer. It is a pure move; behavior is unchanged.

What

Before this PR

frontends ──► asap-aware-mapping (Stage 2 + 3 + facade) ──► asap-logical-optimizer (Stage 1) ──► asap-types

asap-aware-mapping/src/
  physical_candidates  plan_selection/  cost_model recurrence analytical_cost …  pass/

After this PR

frontends ──► asap-aware-mapping (Stage 3 + facade) ──┬──► asap-physical-optimizer (Stage 2) ──► asap-types
                                                      └──► asap-logical-optimizer (Stage 1) ──► asap-types
asap-physical-optimizer ··dev··► asap-logical-optimizer, asap-frontend-promql   (tests only)

physical-optimizer/src/
  implementation/physical_candidates.rs
asap-aware-mapping/src/
  plan_selection/  cost_model recurrence analytical_cost … storage_io  pass/

cargo tree -p asap-physical-optimizer --depth 1 -e normal,dev:

asap-physical-optimizer
├── asap-types
└── thiserror
[dev-dependencies]
├── asap-frontend-promql
└── asap-logical-optimizer

How

  • git mv asap-aware-mapping/src/physical_candidates.rs to physical-optimizer/src/implementation/physical_candidates.rs. materialization/ does not exist yet, so no empty module is created.
  • Dependencies. Production code imports only asap-types: a Stage 1 candidate reaches Stage 2 as OperatorNode roots. asap-logical-optimizer is therefore a dev-dependency (the tests build candidates with enumerate_local_logical_candidates), not a normal one. The PromQL front end is also a dev-dependency.
  • test_support. The crate has its own copy with only lower_promql.
  • No compatibility re-exports. Callers now import asap_physical_optimizer::implementation::physical_candidates::…: plan_selection/mod.rs (two sites) and integration-tests/tests/planner_layering_example1.rs (two sites). asap-aware-mapping and integration-tests gain the dependency.
  • Manifest guards. A new test, tests/stage2_dependencies.rs, fails if the manifest names asap-plan-selection, asap-aware-mapping or asap-physical-operators. The Stage 1 guard also rejects asap-physical-optimizer now.

Moved files

From To
asap-aware-mapping/src/physical_candidates.rs physical-optimizer/src/implementation/physical_candidates.rs (unchanged, 281 lines)

New: Cargo.toml, lib.rs, implementation/mod.rs, test_support.rs and tests/stage2_dependencies.rs.

Volume

14 files changed, +143 / −15. One file moved, 5 new, 4 import sites rewritten.

Gate (at the tip)

  • cargo fmt --all --check: passes.
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: passes.
  • cargo test --workspace: 1,529 passed, 12 ignored. That is refactor: extract the Stage 1 logical-optimizer crate (#572 B2) #583's 1,528 plus the new manifest guard. No test is deleted.
  • python3 -m unittest discover -s tools/dag-viewer -p test_render.py: OK, 6 skipped.
  • stage_pipeline --example planner-layering-1 regenerates tools/dag-viewer/examples/planner-layering-example1.json byte for byte.

Part of #572 (B3) and #509. Follows #583. Related: #580. Next: B4 (asap-plan-selection).

🤖 Generated with Claude Code

Move asap-aware-mapping's physical_candidates into the new
asap-physical-optimizer crate (implementation/physical_candidates.rs), with
a trimmed test_support copy. Production code depends only on asap-types; a
new manifest guard rejects plan-selection, aware-mapping and
physical-operators. Imports are rewritten without compatibility
re-exports. Pure move (#572, B3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant