Re: Possible improvement

2020-06-05 Thread Paul van der Linden
Ok, as always there's a lot more to take into account then when just superficially looking at it. And indeed your counterexample shows that you'd have to include all the previous when-conditions too as false WHERE x=0 IS DISTINCT FROM true AND 1/x > 100, which could become quite messy (especially w

Re: Possible improvement

2020-06-05 Thread Paul van der Linden
Thanks for your thoughts. For the case where it isn't known if the case expression itself is indexed, technically that should be added as a decision-node in the query planner. After all there are 2 possibilities to handle that so it should be up to the planner to choose the cheapest. Having said

Re: Possible improvement

2020-06-05 Thread Tom Lane
Paul van der Linden writes: > For the case where it isn't known if the case expression itself is indexed, > technically that should be added as a decision-node in the query planner. That'd be fairly hard to do, if we're regarding this as an expression simplification step, since expression simplif

Re: Possible improvement

2020-06-05 Thread Tom Lane
David Rowley writes: > On Fri, 5 Jun 2020 at 14:41, Paul van der Linden > wrote: >> If I have a query like: >> >> SELECT * FROM ( >> SELECT >> CASE >> WHEN field='value1' THEN 1 >> WHEN field='value2' THEN 2 >> END AS category >> FROM table1 >> ) AS foo >> WHERE category=1 >> >> doesn't use the

Re: Possible improvement

2020-06-05 Thread David Rowley
On Fri, 5 Jun 2020 at 14:41, Paul van der Linden wrote: > If I have a query like: > > SELECT * FROM ( > SELECT > CASE > WHEN field='value1' THEN 1 > WHEN field='value2' THEN 2 > END AS category > FROM table1 > ) AS foo > WHERE category=1 > > doesn't use the index on field, while te