postgresql/src/backend
Tom Lane 0dd33a6fca Fix edge case in plpgsql's make_callstmt_target().
If the plancache entry for the CALL statement is already stale,
it's possible for us to fetch an old procedure OID out of it,
and then fail with "cache lookup failed for function NNN".
In ordinary usage this never happens because make_callstmt_target
is called just once immediately after building the plancache
entry.  It can be forced however by setting up an erroneous CALL
(that causes make_callstmt_target itself to report an error),
then dropping/recreating the target procedure, then repeating
the erroneous CALL.

To fix, use SPI_plan_get_cached_plan() to fetch the plancache's
plan, rather than assuming we can use SPI_plan_get_plan_sources().
This shouldn't add any noticeable overhead in the normal case,
and in the stale-plan case we'd have had to replan anyway a little
further down.

The other callers of SPI_plan_get_plan_sources() seem OK, because
either they don't need up-to-date plans or they know that the
query was just (re) planned.  But add some commentary in hopes
of not falling into this trap again.

Per bug #18574 from Song Hongyu.  Back-patch to v14 where this coding
was introduced.  (Older branches have comparable code, but it's run
after any required replanning, so there's no issue.)

Discussion: https://postgr.es/m/18574-2ce7ba3249221389@postgresql.org
2024-08-07 12:54:39 -04:00
..
access Revert "Allow parallel workers to cope with a newly-created session user ID." 2024-07-31 20:54:31 -04:00
archive Fix memory leaks in error reporting with LOG level 2024-05-14 10:41:32 +02:00
backup Wait for WAL summarization to catch up before creating .partial file. 2024-07-26 14:51:10 -04:00
bootstrap Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
catalog Reset relhassubclass upon attaching table as a partition 2024-07-24 12:38:18 +02:00
commands Revert "Allow parallel workers to cope with a newly-created session user ID." 2024-07-31 20:54:31 -04:00
executor Fix edge case in plpgsql's make_callstmt_target(). 2024-08-07 12:54:39 -04:00
foreign Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:30 -07:00
jit Move resowner from common JitContext to LLVM specific 2024-07-19 10:27:54 +03:00
lib Revert: Implement pg_wal_replay_wait() stored procedure 2024-04-11 17:28:15 +03:00
libpq libpq: Use strerror_r instead of strerror 2024-07-28 10:19:57 +02:00
main Tighten check for --forkchild argument when spawning child process 2024-07-03 16:20:56 +03:00
nodes Adapt REL_17_STABLE to its new status as a stable branch 2024-07-01 08:05:35 +09:00
optimizer Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:30 -07:00
parser Refactor/reword some error messages to avoid duplicates 2024-08-07 11:30:36 -04:00
partitioning Fix creation of partition descriptor during concurrent detach 2024-06-11 11:38:45 +02:00
po Translation updates 2024-08-05 12:12:32 +02:00
port Revise GUC names quoting in messages again 2024-05-17 11:44:26 +02:00
postmaster Detach syslogger from shared memory 2024-07-29 22:42:15 +03:00
regex Support C.UTF-8 locale in the new builtin collation provider. 2024-03-19 15:24:41 -07:00
replication Use PqMsg_* macros in more places. 2024-07-17 10:51:00 -05:00
rewrite Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:30 -07:00
snowball Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
statistics Fix typos and duplicate words 2024-04-18 21:28:07 +02:00
storage Use more consistently int64 for page numbers in SLRU-related code 2024-07-23 17:59:20 +09:00
tcop Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:30 -07:00
tsearch Remove unused #include's from backend .c files 2024-03-04 12:02:20 +01:00
utils Restrict accesses to non-system views and foreign tables during pg_dump. 2024-08-05 06:05:30 -07:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Fix make build on MinGW 2024-06-21 08:17:23 +02:00
meson.build meson: Fix import library name in Windows 2024-06-20 09:08:36 +02:00
nls.mk Add missing gettext triggers 2024-05-14 12:57:22 +02:00