Re: "SELECT ... FROM DUAL" is not quite as silly as it appears
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2018-03-16T14:29:04Z
Lists: pgsql-hackers
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
Commits
-
In the planner, replace an empty FROM clause with a dummy RTE.
- 4be058fe9ec5 12.0 landed
-
Fix jit compilation bug on wide tables.
- b238527664ec 12.0 cited