Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHd9v-0003TO-UH for pgsql-hackers@arkaria.postgresql.org; Sun, 04 Jun 2017 21:34:04 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dHd9v-0000x7-Gp for pgsql-hackers@arkaria.postgresql.org; Sun, 04 Jun 2017 21:34:03 +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 1dHd8Q-0006iw-Nz for pgsql-hackers@postgresql.org; Sun, 04 Jun 2017 21:32:30 +0000 Received: from mail-it0-x233.google.com ([2607:f8b0:4001:c0b::233]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dHd8N-00032U-QB for pgsql-hackers@postgresql.org; Sun, 04 Jun 2017 21:32:29 +0000 Received: by mail-it0-x233.google.com with SMTP id m62so46280124itc.0 for ; Sun, 04 Jun 2017 14:32:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=WqROtpuilbPD64BwK5L9/2FuvGkgqbtay1eiJVSPD10=; b=Hm9N12UQfknkykruAq69h3vpO3BBtwmw4zS0JWXj7X0qgjt4/ZIfRk5c2Bp0om/s1t RN4B04QPvUUdNIHlUdCvV3OHTUroZxx7PUyYqnTYyhTf2xaj0XwBvJLd8MZtCFckF9wS IWCc+rxwR3bVm7WRR6aGZ1NgIpb+sd4hKJtT/klMUbuHf16nMryLm3k/X2pYMwhdbVpY WAe6CZ0SzJCBIyLLMhRTdMgWmbzWP8M5mNI313quyAnhSthBFsMN4TLv+gYUGgmrccdl dECY+fq9SFlDZzFNwRm6CXfneO28O5ce9QfcamaOAN3WicHqVsgYAEJDYGPqt6gARnf3 dOPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=WqROtpuilbPD64BwK5L9/2FuvGkgqbtay1eiJVSPD10=; b=m2JgYoOMYihHGEPl0uehIFS308/flh3CUKP7rIqZ34LzsJHjb+vvWEfBc3PIeNDJTs MJSXx7HA7R5HgBIC0HsBXub0IQD2bFRNiWvCqLFrRCPFFBIqpd5XqkZODvSkzYzo8M1R n6ayk69Tt1h7kpCBbhoiDnLW3XqfarqYf/eqGDEwfW2vZJjc/P3DwGoSbzqZW+vkxvyB b1M5z4+N5xDuxkwk9JM/7/JBVk95jXXCsE1kaGYxAl5qn2XEsEDywzQSc4rZ7cIc6ckw DdgMxN69CHcB25+PmEdFB+2OXJ5LB6GdMa0jynvpIrcsAT4gHFes7pwWuEKpmPPJGHBW b4Yw== X-Gm-Message-State: AODbwcClGr3shlWXQHkg5PLzFJAVuYoEZMPojTFQBnXmTgK/dkGKPTzm nrcotP7J0hVHMw== X-Received: by 10.107.128.84 with SMTP id b81mr3305454iod.26.1496611946892; Sun, 04 Jun 2017 14:32:26 -0700 (PDT) Received: from [192.168.2.121] (24-113-198-113.wavecable.com. [24.113.198.113]) by smtp.gmail.com with ESMTPSA id q92sm6098727ioi.57.2017.06.04.14.32.25 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 04 Jun 2017 14:32:26 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\)) Subject: Re: PostgreSQL 10 changes in exclusion constraints - did something change? CASE WHEN behavior oddity From: Mark Dilger In-Reply-To: <20170604211942.aiavcbagsho5owcz@alap3.anarazel.de> Date: Sun, 4 Jun 2017 14:32:24 -0700 Cc: Tom Lane , Regina Obe , PostgreSQL-development Content-Transfer-Encoding: quoted-printable Message-Id: References: <000001d2d5de$d8d66170$8a832450$@pcorp.us> <29994.1495809534@sss.pgh.pa.us> <000c01d2d654$518f2be0$f4ad83a0$@pcorp.us> <21809.1495994606@sss.pgh.pa.us> <20170603024503.yv6gxvkyx6mtc63m@alap3.anarazel.de> <7181.1496458380@sss.pgh.pa.us> <20170603031127.fqg7zjhfgbcbcank@alap3.anarazel.de> <4125B63A-886A-442D-9932-34F0D4F76D41@gmail.com> <20170604193521.ha6d5kpkdswmissm@alap3.anarazel.de> <63850C96-9570-4969-8074-7033DA4C334F@gmail.com> <20170604211942.aiavcbagsho5owcz@alap3.anarazel.de> To: Andres Freund X-Mailer: Apple Mail (2.3124) X-Pg-Spam-Score: -2.7 (--) 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 > On Jun 4, 2017, at 2:19 PM, Andres Freund wrote: >=20 > On 2017-06-04 14:16:14 -0700, Mark Dilger wrote: >> Sorry, I was not clear. What I meant to get at was that if you remove f= rom the >> executor all support for SRFs inside case statements, you might foreclos= e the option >> of extending the syntax at some later date to allow aggregates over >> SRFs. >=20 > Seems very unlikely that we'd ever want to do that. The right way to do > this is to simply move the SRF into the from list. Having the executor > support arbitrary sources of tuples would just complicate and slow down > already complicated and slow code... >=20 >=20 >> I'm >> not saying that this works currently, but in principle if you allowed th= at SUM() that >> I put up there, you'd get back exactly one row from it, same as you get = from the >> ELSE clause. That would seem to solve the problem without going so far = as >> completely disallowing the SRF altogether. >=20 > But what would the benefit be? In my example, the aggregate function is taking a column from the table as an argument, so the output of the aggregate function needs to be computed p= er row, not just once. And if the function is expensive, or has side-effects, you = might only want it to execute for those rows where the CASE statement is true, ra= ther than for all of them. You may get that same behavior using lateral or some= such, I'm uncertain, but in a complicated CASE statement, it be more straightforw= ard to write something like: SELECT CASE WHEN t.x =3D 'foo' THEN expensive_aggfunc1(srf1(t.y,t.z)) WHEN t.x =3D 'bar' THEN expensive_aggfunc2(srf2(t.y,t.z)) WHEN t.x =3D 'baz' THEN expensive_aggfunc3(srf3(t.y,t.z)) .... WHEN t.x =3D 'zzz' THEN expensive_aggfuncN(srfN(t.y,t.z)) ELSE 5 END FROM mytable t; Than to try to write it any other way. I'm not advocating anything here, even though it may sound that way to you. I'm just thinking this thing through, given that you may be committing a re= moval of functionality that we want back at some later time. Out of curiosity, how would you rewrite what I have above such that the aggregate function is not inside the case statement, and the expensive_aggf= uncs are only called for those (t.y,t.z) that are actually appropriate? Mark Dilger --=20 Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers