A Greenplum report on a partitioned fact slowed down, and EXPLAIN now names the Postgres-based planner — why, and what to do?
GPORCA plans a query only when it supports every feature in it, otherwise Greenplum falls back to the Postgres-based planner and loses GPORCA's partition elimination and join choices. Find the feature with optimizer_trace_fallback, rewrite around it, and keep root statistics fresh.
- Tuning the Postgres planner's settings while GPORCA plans the query, though GPORCA ignores them
- Not checking the optimizer line of EXPLAIN after changing a report query or a table definition
- Analyzing only new leaf partitions and leaving GPORCA with stale or missing root partition statistics
- When can turning GPORCA off for a session be the right call, and what would you check first?
- Why can GPORCA eliminate partitions at run time in a join, when the partition values come from the other table?
Two optimizers in Greenplum and its forks Arenadata DB and Greengage DB. GPORCA is the main optimizer: it builds the plan when it supports everything in the query. When it does not, Greenplum quietly falls back to the Postgres-based planner; a NOTICE goes to the log, and the last line of EXPLAIN names the optimizer that built the plan. GPORCA is stronger where a warehouse needs it: queries on partitioned tables (including run-time partition elimination, when the key values arrive from another table through a join), subqueries and CTEs, join order and motion choice.
What may have happened.
- The report query gained a construct GPORCA does not support (mixed collations, certain functions or types — the list depends on the release), and it fell back.
- Someone turned GPORCA off:
SET optimizer = offin a session, for a role or a database. The parameter can be set at system, database, role, session and query level.
Diagnosis:
SET optimizer_trace_fallback = on; -- the fallback reason right in the client output
EXPLAIN SELECT ...; -- INFO/DETAIL names the unsupported feature
SHOW optimizer; -- is GPORCA switched off for this session or roleFix. Rewrite the query around the unsupported feature — move it into a separate step, replace the function or type — and compare EXPLAIN ANALYZE before and after: rows per segment, motions, eliminated partitions. GPORCA ignores the Postgres planner's settings (enable_*, random_page_cost, join_collapse_limit); tuning them helps only after a fallback.
Statistics. GPORCA plans a partitioned table from its root statistics. ANALYZE on the root table collects leaf statistics and builds the root's from them (when optimizer_analyze_root_partition is on); after adding a partition, analyze it so the root statistics include its rows. Without root statistics GPORCA still eliminates partitions, but the plan may be far from the best.