postgresql/src/backend
Tom Lane e0df80828a 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
2024-04-15 12:56:56 -04:00
..
access Use the correct PG_DETOAST_DATUM macro in BRIN 2024-04-14 18:19:58 +02:00
archive Add built-in ERROR handling for archive callbacks. 2024-04-02 22:28:11 -05:00
backup Fix unnecessary padding in incremental backups 2024-04-14 20:37:49 +02:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog Fix type-checking of RECORD-returning functions in FROM, redux. 2024-04-15 12:56:56 -04:00
commands ATTACH PARTITION: Don't match a PK with a UNIQUE constraint 2024-04-15 15:07:47 +02:00
executor Revert: Allow table AM tuple_insert() method to return the different slot 2024-04-11 16:02:45 +03:00
foreign Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
jit Fix illegal attribute propagation in LLVM JIT. 2024-04-10 12:13:46 +12:00
lib Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
libpq Fix check for 'outlen' return from SSL_select_next_proto() 2024-04-08 05:03:17 +03:00
main Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
nodes revert: Transform OR clauses to ANY expression 2024-04-10 02:28:09 +03:00
optimizer Fix type-checking of RECORD-returning functions in FROM, redux. 2024-04-15 12:56:56 -04:00
parser Fix type-checking of RECORD-returning functions in FROM, redux. 2024-04-15 12:56:56 -04:00
partitioning Grammar fixes for split/merge partitions code 2024-04-15 16:00:02 +03:00
po Update copyright for 2024 2024-01-03 20:49:05 -05:00
port Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
postmaster Revert: Custom reloptions for table AM 2024-04-11 15:46:35 +03:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Fix the review comments and a bug in the slot sync code. 2024-04-12 15:10:41 +05:30
rewrite Add RETURNING support to MERGE. 2024-03-17 13:58:59 +00:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Make stxstattarget nullable 2024-03-17 12:26:26 +01:00
storage freespace: Don't return blocks past the end of the main fork. 2024-04-13 08:34:20 -07:00
tcop Revert: Custom reloptions for table AM 2024-04-11 15:46:35 +03:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Fix type-checking of RECORD-returning functions in FROM, redux. 2024-04-15 12:56:56 -04:00
.gitignore
Makefile Rework lwlocknames.txt to become lwlocklist.h 2024-03-20 11:55:20 +01:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build Remove AIX support 2024-02-28 15:17:23 +04:00
nls.mk Remove distprep 2023-11-06 15:18:04 +01:00