Expand table-returning functions into columns in a FROM clause - #3222
Expand table-returning functions into columns in a FROM clause#3222reltuk wants to merge 1 commit into
Conversation
A function called in a FROM clause is already rewritten into a vitess.TableFuncExpr and resolved through GMS's TableFunctionWrapper, which asks sql.ExtendedTableFunction for the function's result columns. CompiledFunction answered that question with the function's OUT parameters only, so a function declared RETURNS TABLE(...) or RETURNS SETOF <composite> - which stores its result columns as the fields of a composite return type rather than as OUT parameters - reported a single column, and `SELECT * FROM figures()` returned one record value per row instead of one column per field. OutParametersSchema now falls back to the fields of a composite return type, and Eval expands each record value back into separate columns, assignment casting each field to the result type the function declares. The SELECT-list shape is unchanged: EvalRowIter keeps returning one record value per row, so it now calls the underlying overload directly rather than going through Eval. Also fixes a PL/pgSQL function declared RETURNS SETOF <scalar>, whose RETURN QUERY results were buffered as one-field records and so failed to render in either a FROM clause or a SELECT list.
|
|
SummaryCoverage spans core database-function behavior, including scalar and multi-field results, field naming and types, filtering, joins, aliases, and query usage. It also exercises edge cases such as empty results, null values, declared type conversion, composite value preservation, and correlated table-function behavior. Safe to merge — the only failure is a medium-severity limitation in correlated table-function queries and is explicitly unrelated to this PR, with no regressions or newly introduced failures attributable to the change. It is a flag for later rather than a merge blocker. Tests run by ItoAdditional Findings DetailsThese findings are unrelated to the current changes but were observed during testing. 🟡 Correlated table function fails with outer-row input
Evidence PackageTip Reply with @itoqa to send us feedback on this test run. |
|
@reltuk DOLT
|

A function called in a FROM clause is already rewritten into a vitess.TableFuncExpr and resolved through GMS's TableFunctionWrapper, which asks sql.ExtendedTableFunction for the function's result columns. CompiledFunction answered that question with the function's OUT parameters only, so a function declared RETURNS TABLE(...) or RETURNS SETOF - which stores its result columns as the fields of a composite return type rather than as OUT parameters - reported a single column, and
SELECT * FROM figures()returned one record value per row instead of one column per field.OutParametersSchema now falls back to the fields of a composite return type, and Eval expands each record value back into separate columns, assignment casting each field to the result type the function declares. The SELECT-list shape is unchanged: EvalRowIter keeps returning one record value per row, so it now calls the underlying overload directly rather than going through Eval.
Also fixes a PL/pgSQL function declared RETURNS SETOF , whose RETURN QUERY results were buffered as one-field records and so failed to render in either a FROM clause or a SELECT list.