Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 32E4D63225B for ; Tue, 6 Jan 2009 09:22:08 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 54287-08 for ; Tue, 6 Jan 2009 09:22:03 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id B114863223D for ; Tue, 6 Jan 2009 09:22:03 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id n06DM0hL007833; Tue, 6 Jan 2009 08:22:00 -0500 (EST) To: "Robert Haas" cc: "pgsql-performance@postgresql.org" Subject: Re: bad selectivity estimates for CASE In-reply-to: <603c8f070901060425t485fb8d8nb79735ed72982d5a@mail.gmail.com> References: <603c8f070901051915p15b3d6a7jbe6f6fdd178143e@mail.gmail.com> <3032.1231216843@sss.pgh.pa.us> <603c8f070901060425t485fb8d8nb79735ed72982d5a@mail.gmail.com> Comments: In-reply-to "Robert Haas" message dated "Tue, 06 Jan 2009 07:25:29 -0500" Date: Tue, 06 Jan 2009 08:22:00 -0500 Message-ID: <7832.1231248120@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200901/11 X-Sequence-Number: 32290 "Robert Haas" writes: > Well, presumably CASE WHEN THEN WHEN THEN > WHEN THEN ... END = could > be simplified to . 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