A complex query may fail to generate an ORCA execution plan, instead falling back to the legacy Postgres Planner or failing with an Out of Memory (OOM) error.
This behavior typically occurs when the query utilizes a DISTINCT operation on a subset of target list columns, which may exceed the optimizer's ability to process the operation efficiently.
The root cause is a limitation in how the ORCA optimizer handles DISTINCT operations when applied to specific subsets of columns in the target list of highly complex queries.
In these scenarios, the optimizer may fail to find a valid plan within memory constraints or may determine the query is too complex for ORCA's current logic, triggering a fallback to the Postgres Planner to ensure the query can still execute, albeit potentially with sub-optimal performance.
To resolve this issue, modify the query structure and adjust optimizer parameters:
SET optimizer_enable_query_parameter = on;