<@U0A71G31CDV> getting this error with a complex 3...
# questions-and-troubleshooting
j
@Rocky getting this error with a complex 300 line sql query, what does it mean exactly? and how should be approach solving it?
Copy code
(1064, 'StarRocks planner use long time 3020 ms in logical phase, This probably because 1. FE Full GC, current query allocated=967.0 MiB, optimizerContextInUse=76.2 MiB2. Hive external table fetch metadata took a long time, 3. The SQL is very complex. You could 1. adjust FE JVM config, 2. try query again, 3. enlarge new_planner_optimize_timeout session variable')
r
This error means that the StarRocks Cost-Based Optimizer (CBO) was unable to finish generating an execution plan for your query within the default timeout (usually 3000ms). For a 300-line SQL query, the optimizer is likely struggling to evaluate all possible join orders and execution paths within that window, or the Frontend (FE) process is slowed down by Java memory management issues. What the error components mean: * Logical Phase: The stage where the optimizer transforms the SQL into a logical plan and tries to find the most efficient way to execute it (e.g., Join Reordering). * FE Full GC: The Java process (Frontend) is spending significant time on "Garbage Collection." The fact that your query allocated 967 MiB just for planning suggests it is extremely memory-intensive for the FE. * optimizerContextInUse=76.2 MiB: This is the current memory being used by the optimizer's internal structures for this specific query. ────────── How to solve it (Step-by-step) 1. Immediate Workaround: Increase the Timeout The quickest fix is to give the optimizer more time. You can set this at the session level for your current window or globally.
Copy code
sql
-- Increase timeout to 10 seconds (10000ms)
SET new_planner_optimize_timeout = 10000;

-- Then run your query again.
2. Address FE Memory (JVM Config) Since your error specifically mentions FE Full GC, your Frontend likely needs more heap memory to handle such complex planning. * Check: Look at
fe/log/fe.gc.log
. If you see frequent "Full GC" entries, you need more memory. * Action: In your
fe/conf/fe.conf
file, increase the
-Xmx
value. * Example: Change
-Xmx8192m
to
-Xmx16384m
(16GB) or higher, depending on your server's available RAM. _ _Note: Restart the FE for this to take effect.* 3. Optimize the SQL Structure If the query is 300 lines, it likely contains many joins or deeply nested subqueries. You can help the optimizer by: * Using CTEs (WITH clause): While CTEs are great for readability, sometimes breaking a massive query into multiple temporary tables can help the optimizer focus on smaller "chunks" one at a time. * Reviewing Join Counts: If you have more than 10-15 tables joining together, the search space for the optimizer becomes exponential. Check if any joins can be simplified. * Check External Tables: If you are querying Hive or other external catalogs, ensure your metadata cache is fresh. Slow metadata fetching from remote metastores often triggers this timeout. 4. Analyze the Planning Process To see where the time is being spent, you can run:
Copy code
sql
explain costs <your_query>;
This won't execute the query but will show you the plan. If this also times out, it confirms the optimizer is the bottleneck. If it succeeds, look for areas with extremely high "Cost" or "Estimates" which might indicate where the planner is getting stuck. Rocky's Tip: If you frequently run queries of this complexity, I recommend setting
-Xmx
to at least 16GB on your FE nodes to prevent the "Full GC" issue from killing your performance! Referencesknowledge/trouble_shooting/fe_memory_problems.mdfaq/Sql_faq.mdfaq/fe_mem_faq.mdknowledge/trouble_shooting/fe_deadlock_problems.md
r
@Rocky Does this persist across session - i.e is this setting global? sql -- Increase timeout to 10 seconds (10000ms) SET new_planner_optimize_timeout = 10000; -- Then run your query again. If this is per session - how to increase this timeout globally so as to persist across sessions
r
The setting
SET new_planner_optimize_timeout = 10000;
is session-specific. It will only apply to your current connection and will not persist once that session ends. How to set it globally To make this setting persist across sessions for all future connections, you should use the
GLOBAL
keyword:
Copy code
sql
SET GLOBAL new_planner_optimize_timeout = 10000;
Important Notes: 1. Scope:
SET GLOBAL
affects all new sessions created after the command is executed. It does not change the value for the session you are currently in. 2. Current Session: If you want it to apply to both your current session and all future sessions, run both:
Copy code
sql
   SET GLOBAL new_planner_optimize_timeout = 10000;
   SET new_planner_optimize_timeout = 10000;
3. Persisting for a Specific User: If you are on StarRocks v3.3.3 or later, you can also set this as a property for a specific user so it persists whenever that user logs in:
Copy code
sql
   ALTER USER 'username' SET PROPERTIES ('session.new_planner_optimize_timeout' = '10000');
Verification You can verify the current value in your session vs. the global value using:
Copy code
sql
SHOW VARIABLES LIKE 'new_planner_optimize_timeout';        -- Current session
SHOW GLOBAL VARIABLES LIKE 'new_planner_optimize_timeout'; -- Global setting
Referencessql-reference/System_variable.mdadministration/management/FE_configuration.mdfaq/loading/Loading_faq.mdfaq/Sql_faq.mdsql-reference/sql-functions/Window_function.md