Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UkN9p-0003i4-DG for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Jun 2013 23:30:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UkN9o-0006Tu-6z for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Jun 2013 23:30:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UkN9n-0006To-BH for pgsql-bugs@postgresql.org; Wed, 05 Jun 2013 23:30:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UkN9j-0005EQ-JF for pgsql-bugs@postgresql.org; Wed, 05 Jun 2013 23:30:19 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id r55NUEPK003282; Wed, 5 Jun 2013 19:30:14 -0400 (EDT) From: Tom Lane To: eric-postgresql@soroos.net cc: pgsql-bugs@postgresql.org Subject: Re: BUG #8213: Set-valued function error in union In-reply-to: References: Comments: In-reply-to eric-postgresql@soroos.net message dated "Wed, 05 Jun 2013 17:45:45 -0000" Date: Wed, 05 Jun 2013 19:30:14 -0400 Message-ID: <3281.1370475014@sss.pgh.pa.us> X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org eric-postgresql@soroos.net writes: > -- this fails. I'd expect it to succeed. > select id, dt from > (select 1 as id, generate_series(now()::date, now()::date + '1 > month'::interval, '1 day')::date as dt > union > select 2, now()::date > ) as foo > where dt < now()+'15 days'::interval; > psql:pg_bug_report.sql:13: ERROR: 0A000: set-valued function called in > context that cannot accept a set Fascinating. This has been broken at least since 7.4 --- surprising nobody noticed before. We need to fix allpaths.c so it realizes it's unsafe to push down a WHERE condition into a set operation when there are set-returning functions in the tlist of any arm of the set operation. Right now, you're getting this plan: HashAggregate (cost=20.09..30.10 rows=1001 width=0) -> Append (cost=0.03..15.09 rows=1001 width=0) -> Result (cost=0.03..5.05 rows=1000 width=0) One-Time Filter: ((generate_series(((now())::date)::timestamp without time zone, ((now())::date + '1 mon'::interval), '1 day'::interval))::date < (now() + '15 days'::interval)) -> Result (cost=0.01..0.03 rows=1 width=0) One-Time Filter: ((now())::date < (now() + '15 days'::interval)) and of course trying to evaluate a filter that contains a SRF is pretty nonsensical (or even if you think it could be well-defined, it's not implemented). Shouldn't be too hard to fix though. I'm thinking of moving most of the detection logic for this into subquery_is_pushdown_safe, and having it return an additional flag array that says "this output column is unsafe to reference in quals at all". regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs