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

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

Commit 2ed8f9a01 intended to institute a policy that if a
RangeTblFunction has a coldeflist, then the function return type is
certainly RECORD, and we should use the coldeflist as the source of
truth about what the columns of the record type are.  When the
original function has been folded to a constant, inspection of the
constant might give a different answer.  This situation will lead to
a tuple-type-mismatch error at execution, but up until that point we
need to consistently believe the coldeflist, or we'll have problems
from different bits of code reaching different conclusions.

expandRTE didn't get that memo though, and would try to produce a
tupdesc based on the constant in this situation, leading to an
assertion failure.  (Desultory testing suggests that non-assert
builds often manage to give the expected error, although I also
saw a "cache lookup failed for type 0" error, and it seems at
least possible that a crash could happen.)

Some other callers of get_expr_result_type and get_expr_result_tupdesc
were also being incautious about this.  While none of them seem to
have actual bugs, they're working harder than necessary in this case,
besides which it seems safest to have an explicit policy of not using
those functions on an RTE with a coldeflist.  Adjust the code
accordingly, and add commentary to funcapi.c about this policy.

Also fix an obsolete comment that claimed "get_expr_result_type()
doesn't know how to extract type info from a RECORD constant".
That hasn't been true since commit d57534740.

Per bug #18422 from Alexander Lakhin.
As with the previous commit, back-patch to all supported branches.

Discussion: https://postgr.es/m/18422-89ca86c8eac5246d@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b6e21cef72f1f93b0ec4d6da4d9c2e8bb3fca98a

Modified Files
--------------
src/backend/optimizer/prep/prepjointree.c |  4 ++++
src/backend/optimizer/util/clauses.c      | 11 +++++------
src/backend/parser/parse_relation.c       | 19 ++++++++++++++-----
src/backend/utils/fmgr/funcapi.c          | 10 +++++++++-
src/test/regress/expected/rangefuncs.out  |  3 +++
src/test/regress/sql/rangefuncs.sql       |  1 +
6 files changed, 36 insertions(+), 12 deletions(-)


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

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: ATTACH PARTITION: Don't match a PK with a UNIQUE constraint
Следующее
От: Nathan Bossart
Дата:
Сообщение: pgsql: doc: Note exceptions for SET ROLE's effect on privilege checks.