Re: bad selectivity estimates for CASE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Robert Haas" <robertmhaas(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: bad selectivity estimates for CASE
Date: 2009-01-06 13:22:00
Message-ID: 7832.1231248120@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"Robert Haas" <robertmhaas(at)gmail(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Stefano Nichele 2009-01-06 16:50:49 understanding postgres issues/bottlenecks
Previous Message Robert Haas 2009-01-06 12:25:29 Re: bad selectivity estimates for CASE