pgsql: Fix type-checking of RECORD-returning functions in FROM.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix type-checking of RECORD-returning functions in FROM.
Дата
Msg-id E1rhx8t-002RYt-At@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix type-checking of RECORD-returning functions in FROM.

In the corner case where a function returning RECORD has been
simplified to a RECORD constant or an inlined ROW() expression,
ExecInitFunctionScan failed to cross-check the function's result
rowtype against the coldeflist provided by the calling query.
That happened because get_expr_result_type is able to extract a
tupdesc from such expressions, which led ExecInitFunctionScan to
ignore the coldeflist.  (Instead, it used the extracted tupdesc
to check the function's output, which of course always succeeds.)

I have not been able to demonstrate any really serious consequences
from this, because if some column of the result is of the wrong
type and is directly referenced by a Var of the calling query,
CheckVarSlotCompatibility will catch it.  However, we definitely do
fail to report the case where the function returns more columns than
the coldeflist expects, and in the converse case where it returns
fewer columns, we get an assert failure (but, seemingly, no worse
results in non-assert builds).

To fix, always build the expected tupdesc from the coldeflist if there
is one, and consult get_expr_result_type only when there isn't one.

Also remove the failing Assert, even though it is no longer reached
after this fix.  It doesn't seem to be adding anything useful, since
later checking will deal with cases with the wrong number of columns.

The only other place I could find that is doing something similar
is inline_set_returning_function.  There's no live bug there because
we cannot be looking at a Const or RowExpr, but for consistency
change that code to agree with ExecInitFunctionScan.

Per report from PetSerAl.  After some debate I've concluded that
this should be back-patched.  There is a small risk that somebody
has been relying on such a case not throwing an error, but I judge
this outweighed by the risk that I've missed some way in which the
failure to cross-check has worse consequences than sketched above.

Discussion: https://postgr.es/m/CAKygsHSerA1eXsJHR9wft3Gn3wfHQ5RfP8XHBzF70_qcrrRvEg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2ed8f9a01e74bfc63a56b2108f44237bc5eab9f5

Modified Files
--------------
src/backend/executor/nodeFunctionscan.c  | 81 ++++++++++++++++++--------------
src/backend/optimizer/util/clauses.c     | 14 ++++--
src/test/regress/expected/rangefuncs.out | 13 +++++
src/test/regress/sql/rangefuncs.sql      |  9 ++++
4 files changed, 76 insertions(+), 41 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: John Naylor
Дата:
Сообщение: pgsql: Fix signedness error in 9f225e992 for gcc
Следующее
От: Jeff Davis
Дата:
Сообщение: pgsql: Add Unicode property tables.