Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dF2XR-00057b-QV for pgsql-hackers@arkaria.postgresql.org; Sun, 28 May 2017 18:03:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dF2XR-0001gk-BK for pgsql-hackers@arkaria.postgresql.org; Sun, 28 May 2017 18:03:37 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dF2XP-0001ef-CI for pgsql-hackers@postgresql.org; Sun, 28 May 2017 18:03:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dF2XI-0003N0-J8 for pgsql-hackers@postgresql.org; Sun, 28 May 2017 18:03:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v4SI3QAw021810; Sun, 28 May 2017 14:03:27 -0400 From: Tom Lane To: "Regina Obe" cc: "'PostgreSQL-development'" Subject: Re: PostgreSQL 10 changes in exclusion constraints - did something change? CASE WHEN behavior oddity In-reply-to: <000c01d2d654$518f2be0$f4ad83a0$@pcorp.us> References: <000001d2d5de$d8d66170$8a832450$@pcorp.us> <29994.1495809534@sss.pgh.pa.us> <000c01d2d654$518f2be0$f4ad83a0$@pcorp.us> Comments: In-reply-to "Regina Obe" message dated "Fri, 26 May 2017 15:14:37 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21808.1495994606.1@sss.pgh.pa.us> Date: Sun, 28 May 2017 14:03:26 -0400 Message-ID: <21809.1495994606@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org "Regina Obe" writes: > Is this behavior going to stay or change? > It seems inconsistent from a user perspective that > CASE constant .... == short-circuit skipping over SRFs that may otherwise > fail > While > CASE not_constant_table_dependent doesn't short-circuit. > I can understand the motive behind it, it just feels a little inconsistent > from an end-user POV. After thinking about this for awhile, I agree that what we've got now isn't too satisfactory. We can make an analogy between SRFs and aggregate functions: both of them look like simple function calls syntactically, but they have global effects on the semantics of the query, particularly on how many rows are returned. In the case of aggregates, there is long-standing precedent that we can optimize away individual aggregate calls but the query semantics do not change, ie you get one output row (or one per GROUP BY group) even if every last aggregate call disappears due to CASE simplification. The same was true for deletion of SRFs by CASE-simplification before v10, but now we've broken that, which seems like a clear bug. I think it would be possible to teach eval_const_expressions that it must not discard CASE/COALESCE subexpressions that contain SRFs, which would preserve the rule that expression simplification doesn't change the query semantics. Another possibility is to say that we've broken this situation irretrievably and we should start throwing errors for SRFs in places where they'd be conditionally evaluated. That's not real nice perhaps, but it's better than the way things are right now. Thoughts? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers