Re: BUG #5240: Stable Functions that return a table type with a dropped column fail - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #5240: Stable Functions that return a table type with a dropped column fail
Date
Msg-id 26408.1260727594@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #5240: Stable Functions that return a table type with a dropped column fail  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
[ just a note for the archives ]

I wrote:
> Andrew Gierth <andrew@tao11.riddles.org.uk> writes:
>> I don't think it's particularly closely related to #4907.

> Yeah.  I think the real problem is that set_subqueryscan_references
> is overly optimistic about how much work it has to do:

On further review it doesn't seem that fixing it there is very
practical.  Currently, the Vars in the SubqueryScan's tlist and quals
have varno referencing the subquery RTE and attno matching the column
numbers of the function's declared result type.  We can't just renumber
the attnos to match the actual subquery outputs without confusing the
heck out of EXPLAIN.  It would be okay to change the attnos to match
if we also changed the varno to be OUTER --- then EXPLAIN would
understand the Vars as being references to the subplan's tlist.  However
that would break the executor, in particular it would mean that
nodeSubqueryScan couldn't use the execScan.c facilities, since execScan
expects the expressions it's dealing with to reference the scan tuple
slot not the outer tuple slot.

I'm currently thinking that the best fix is to make inline expansion of
a SRF insert NULL columns into the expanded function tlist so that the
column numbering still matches up.  This probably means that we'd not be
able to inline in certain cases, like if the SRF contains a UNION or
other operation where modifying the tlist changes the semantics.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #5238: frequent signal 11 segfaults
Next
From: "Gerhard Lutz"
Date:
Subject: BUG #5242: ODBC driver v8.4.1 crashed