Ashutosh Bapat <ashutosh.ba...@enterprisedb.com> writes: > On Thu, Mar 15, 2018 at 8:57 PM, Tom Lane <t...@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