From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
Subject: | pgsql: Fix type-checking of RECORD-returning functions in FROM, redux. |
Date: | 2024-04-15 16:57:09 |
Message-ID: | E1rwPdk-002BaN-Te@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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_15_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/09989ba84734c07d045ec379c9424508a52ac604
Modified Files
--------------
src/backend/catalog/dependency.c | 6 +++++-
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 +
7 files changed, 41 insertions(+), 13 deletions(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Nathan Bossart | 2024-04-15 19:06:13 | pgsql: doc: Note exceptions for SET ROLE's effect on privilege checks. |
Previous Message | Alvaro Herrera | 2024-04-15 13:08:44 | pgsql: ATTACH PARTITION: Don't match a PK with a UNIQUE constraint |