Skip to content

[CALCITE-7422] Support large plan optimization mode for HepPlanner#4803

Draft
zhuwenzhuang wants to merge 1 commit intoapache:mainfrom
zhuwenzhuang:large_plan_mode
Draft

[CALCITE-7422] Support large plan optimization mode for HepPlanner#4803
zhuwenzhuang wants to merge 1 commit intoapache:mainfrom
zhuwenzhuang:large_plan_mode

Conversation

@zhuwenzhuang
Copy link
Contributor

@zhuwenzhuang zhuwenzhuang commented Feb 24, 2026

Motivation and details: https://issues.apache.org/jira/browse/CALCITE-7422
Before:
LargePlanBenchmark:100 : 1s
LargePlanBenchmark:1000 : 9s
LargePlanBenchmark:10000 : pretty slow, cannot measure.

CPU Profiler Result(enable fired rules cache and disable large plan mode):
fireRule(RelOptRuleCall ruleCall) takes 2% cpu time.
image
Mem Profiler Result(enable fired rules cache and disable large plan mode):
image

After (enable fired rules cache and large plan mode):
LargePlanBenchmark:100 : 1s
LargePlanBenchmark:1000 : 2s
LargePlanBenchmark:10000 : about 60s

Benchmark (unionNum) Mode Cnt Score Error Units LargePlanBenchmark.testLargeUnionPlan 100 avgt 256.561 ms/op LargePlanBenchmark.testLargeUnionPlan 1000 avgt 1616.421 ms/op LargePlanBenchmark.testLargeUnionPlan 10000 avgt 53393.727 ms/op
CPU Profiler Result:
fireRule(RelOptRuleCall ruleCall) takes 11% cpu time. There is still lots of room for CPU optimization.
image

Mem Profiler Result:
(avoid buildListRecurse/collectGarbage, smaller memory peak size)
image

@zhuwenzhuang zhuwenzhuang force-pushed the large_plan_mode branch 6 times, most recently from d87d57a to d4ae34e Compare February 24, 2026 15:35
@zhuwenzhuang zhuwenzhuang marked this pull request as draft February 24, 2026 15:38
@zhuwenzhuang zhuwenzhuang force-pushed the large_plan_mode branch 2 times, most recently from 6369ba1 to 6d9ab05 Compare February 25, 2026 06:12
@zhuwenzhuang
Copy link
Contributor Author

A better iterater implementation of DFS/BFS is needed. I will optimize this later (unavailable for the next two weeks).

@zhuwenzhuang zhuwenzhuang changed the title [CALCITE-7422] Support large plan optimizaion mode for HepPlanner [CALCITE-7422] Support large plan optimization mode for HepPlanner Mar 1, 2026
@zhuwenzhuang zhuwenzhuang force-pushed the large_plan_mode branch 3 times, most recently from b6b03fb to 4c6e984 Compare March 11, 2026 15:19
Key optimizations of large plan mode:

1. Reusable graph, avoid reinit.
2. Efficient traversal, skip stable subtree.
3. Fine-grained GC.

Usage: see comments of HepPlanner()

Perf result of LargePlanBenchmark:
- 10K unions (~40K nodes): ~8.8s
- 100K unions (~400K nodes): ~60.6s

Without this mode, such plans will OOM and take very long time(cannot
finish).
@sonarqubecloud
Copy link

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