Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ewqM3-0001tN-8J for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Mar 2018 14:29:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ewqM1-0006L5-PL for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Mar 2018 14:29:09 +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.89) (envelope-from ) id 1ewqM1-0006Kw-Eu for pgsql-hackers@lists.postgresql.org; Fri, 16 Mar 2018 14:29:09 +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.89) (envelope-from ) id 1ewqLy-0005cb-NH for pgsql-hackers@lists.postgresql.org; Fri, 16 Mar 2018 14:29:08 +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 w2GET4mO018488; Fri, 16 Mar 2018 10:29:04 -0400 From: Tom Lane To: Ashutosh Bapat cc: pgsql-hackers@lists.postgresql.org Subject: Re: "SELECT ... FROM DUAL" is not quite as silly as it appears In-reply-to: References: <15944.1521127664@sss.pgh.pa.us> Comments: In-reply-to Ashutosh Bapat message dated "Fri, 16 Mar 2018 14:09:28 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <18486.1521210544.1@sss.pgh.pa.us> Date: Fri, 16 Mar 2018 10:29:04 -0400 Message-ID: <18487.1521210544@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ashutosh Bapat writes: > On Thu, Mar 15, 2018 at 8:57 PM, Tom Lane wrote: >> Suppose that, either in the rewriter or early in the planner, we were >> to replace such cases with nonempty FromExprs, by adding a dummy RTE >> representing a table with no columns and one row. This would in turn >> give rise to an ordinary Path that converts to a Result plan, so that >> the case is handled without any special contortions later. > Since table in the dummy FROM clause returns one row without any > column, I guess, there will be at least one row in the output. I am > curious how would we handle cases which do not return any row > like > create function set_ret_func() returns setof record as $$select * from > pg_class where oid = 0;$$ language sql; > select set_ret_func(); > set_ret_func > -------------- > (0 rows) It'd be the same as now, so far as the executor is concerned: regression=# explain select set_ret_func(); QUERY PLAN -------------------------------------------------- ProjectSet (cost=0.00..5.27 rows=1000 width=32) -> Result (cost=0.00..0.01 rows=1 width=0) (2 rows) The difference is that, within the planner, the ResultPath would be associated with a "real" base relation instead of needing its very own code path in query_planner(). regards, tom lane