Re: bad selectivity estimates for CASE - Mailing list pgsql-performance

From Tom Lane
Subject Re: bad selectivity estimates for CASE
Date
Msg-id 7832.1231248120@sss.pgh.pa.us
Whole thread Raw
In response to Re: bad selectivity estimates for CASE  ("Robert Haas" <robertmhaas@gmail.com>)
List pgsql-performance
"Robert Haas" <robertmhaas@gmail.com> writes:
> Well, presumably CASE WHEN <expr1> THEN <constant1> WHEN <expr2> THEN
> <constant2> WHEN <expr3> THEN <constant3> ... END = <constantn> could
> be simplified to <exprn>.

Not without breaking the order-of-evaluation guarantees.  Consider

    case when x=0 then 0 when 1/x = 42 then 1 end = 1

This expression should not suffer a divide-by-zero failure but your
proposal would allow it to do so.

            regards, tom lane

pgsql-performance by date:

Previous
From: "Robert Haas"
Date:
Subject: Re: bad selectivity estimates for CASE
Next
From: Stefano Nichele
Date:
Subject: understanding postgres issues/bottlenecks