#PostgreSQL has failed me for the first time. Being unable to optimize seemingly simple SELECT ... WHERE TRUE OR field IN (SELECT ...) and eliminate the join, it leaves me no choice but to shove template engine into my database handling code...
@AMDmi3 not sure I understand what you are doing. Why is join bad?
@AMDmi3 Maybe the planner can be told something. I presume you have checked everything as you have the actual query at hand :)
How can planner figure out this is really "TRUE" ?
@saper because it's constant expression which evaluates to TRUE. Well the problem is explained in https://www.postgresql.org/message-id/2374.1366296417%40sss.pgh.pa.us
And between fiddling with the planner and introducing SQL query template engine I think I'll pick the latter, as it's at least straightforward and predictable.
@saper the extra table scan is bad, while that table is not really used in the request. Planner is not able to deduce that and avoid the scan, and there's no way to make join or subrequest conditional, so I have to reside to dynamicaly generating SQL queries, which I've hoped to avoid