<@U0A71G31CDV> Hi Rocky! A question about the opti...
# questions-and-troubleshooting
i
@Rocky Hi Rocky! A question about the optimizer/planner on StarRocks 3.5.19. Symptom: one ad-hoc query (about 10 KB of SQL over several views on Iceberg tables) makes the FE plan the same large Iceberg table over and over. • That table is planned 826–832 times in one query. • There are 1,700–2,100 calls to
SnapshotScan.planFiles
per run. • One run had about 5,300 fragment instances. • During those runs the FE Java heap (10 GiB) fills up, with back-to-back full GCs. One follower FE crashed with
OutOfMemoryError: Java heap space
, with one stack in
org.apache.iceberg.TableMetadataParser.read
. • A slightly shorter version of the same query plans the table only 160–420 times and works. • The optimizer’s cost estimate is about 3 TB of memory for the failing version, but cost estimates aren’t reliable here: other queries with similar estimates ran fine. Questions: 1. Is this a known issue: the optimizer re-planning the same Iceberg table for every view or CTE reference, instead of reusing it? Which 3.5 settings control CTE reuse and inlining (for example
cbo_cte_reuse
,
cbo_cte_reuse_rate
,
cbo_cte_max_limit
)? 2. Has anything in 3.5.20–3.5.22 or 4.0.x reduced repeated Iceberg
planFiles
calls or metadata loading within one query, for example caching per snapshot during planning? 3. Is there a guard in 3.5 that rejects a query before or during planning when it has too many scan nodes or fragment instances, or uses too much planner memory, so one query can’t crash an FE? 4. What FE heap size do you recommend for Iceberg-heavy workloads like this (FE container 32 GiB, currently
-Xmx10g
)? Thanks!
r
Hi Rocky here! It sounds like you're hitting a "complexity wall" in the 3.5.x optimizer, specifically related to how CTEs and Views are expanded when they reference high-metadata tables like Iceberg. Here are the answers to your specific questions: 1. CTE Reuse and Settings The symptoms you describe (repeated
planFiles
and metadata loading) typically occur when the optimizer inlines CTEs or views. When inlined, each reference is treated as a separate subtree, causing the planner to re-verify metadata and re-run file pruning for every instance. Key settings in 3.5.x: *
cbo_cte_reuse
: (Default
true
) Enables the general CTE reuse logic. Note: This only works when
enable_pipeline_engine
is also
true
. *
cbo_cte_force_reuse_node_count
: (Introduced in v3.5.3) This is likely your most effective lever. If a CTE's plan tree has more nodes than this threshold, the planner forces reuse (materialization) instead of inlining. The default is
2000
. Try lowering this significantly (e.g., to
50
or
100
) to force your 10KB query to reuse the Iceberg scan. *
cbo_cte_reuse_rate
: A cost-based threshold. Setting this to
0
often helps the optimizer favor reuse over inlining, though
cbo_cte_force_reuse_node_count
is more direct. 2. Improvements in Newer Versions (3.5.20+ and 4.0) * 3.5.20 / 3.5.21: There were efforts to cache Iceberg metadata more aggressively. While some caching of credentials was reverted in 3.5.21 for the 3.5 branch, general metadata parsing and caching improvements have continued. * StarRocks 4.0: This version includes a significant overhaul of Iceberg metadata handling. It introduces faster metadata parsing and a more robust caching layer that can reduce cloud API calls for metadata by up to 90%. It also improves how the FE handles large numbers of files by offloading some manifest parsing. 3. Optimizer Guard Rails StarRocks has a few parameters to prevent a single complex query from crashing the FE: *
max_scalar_operator_flat_children
: (Default
10000
) Limits the number of child operators. Lowering this can reject queries that are too complex before they consume all FE memory. *
expr_children_limit
: Limits the number of child expressions. * Query Queues: You can use resource groups and query queues to limit the number of high-memory queries running concurrently on the FE. *
QueryFEAllocatedMemory
: Starting in 3.5.0+, StarRocks tracks FE memory per query. You can see this in the audit logs to identify which specific queries are "memory hogs." 4. Recommended FE Heap Size For Iceberg-heavy workloads with large metadata (hundreds of
planFiles
calls and thousands of fragments), your current
-Xmx10g
is quite tight. * Standard Recommendation: If your total tablet count (native + external metadata equivalent) is below 1 million, 16 GB is the minimum recommended heap. For 1–2 million tablets, 32 GB is recommended. * For your 32 GiB container: I strongly recommend increasing your heap to at least 24 GB (
-Xmx24g
). Since the FE runs on the JVM, if the heap is too close to the limit, the CPU will spend all its time on Full GCs (as you observed) before eventually failing with OOM. * Environment Variable: Ensure
MALLOC_ARENA_MAX=1
is set in your environment to prevent glibc from bloating off-heap memory, which can cause the container to be killed even if the JVM heap is fine. Recommendation Summary: 1. Increase FE heap to 24GB. 2. Set
cbo_cte_force_reuse_node_count = 100
at the session level for this query. 3. Consider upgrading to 4.0.x if possible, as it contains specific architectural fixes for Iceberg metadata overhead. References • faq/Others.md • data_source/catalog/iceberg/iceberg_catalog.md • knowledge/trouble_shooting/fe_memory_problems.md