pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: "SELECT ... FROM DUAL" is not quite as silly as it appears
Date: Fri, 16 Mar 2018 10:29:04 -0400
Message-ID: <18487.1521210544@sss.pgh.pa.us> (raw)
In-Reply-To: <CAFjFpRdHJbM2EgDng2NgMLkXWD2bYrKhZPchsFj8r4PcVW2E5g@mail.gmail.com>
References: <15944.1521127664@sss.pgh.pa.us>
	<CAFjFpRdHJbM2EgDng2NgMLkXWD2bYrKhZPchsFj8r4PcVW2E5g@mail.gmail.com>

Ashutosh Bapat <ashutosh.bapat@enterprisedb.com> writes:
> On Thu, Mar 15, 2018 at 8:57 PM, Tom Lane <tgl@sss.pgh.pa.us> 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




view thread (33+ messages)  latest in thread

Message-ID: <18487.1521210544@sss.pgh.pa.us>
Permalink:  ../18487.1521210544@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/18487.1521210544@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ashutosh.bapat@enterprisedb.com, pgsql-hackers@lists.postgresql.org
  Subject: Re: "SELECT ... FROM DUAL" is not quite as silly as it appears
  In-Reply-To: <18487.1521210544@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox