Skip to content
Advertisement

Query using CASE in left outer join takes long time to run

I am running a Postgres query with a CASE expression in a join condition. The query takes a long time to run. Is there a better way to optimize this query?

Code snippet:

Advertisement

Answer

For proper answer attach full query, table structure (with indexes) and execution plan.

Original CASE is quite complicated, but hard to say if it’s responsible for query performance without information from execution plan.

This case can be transformed to

or even

This should give a optimizer (and everybody else) better understanding which column (in da table) is key for joining

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement