postgresql/src
Tom Lane c1d1e8469c Fix ruleutils issues with dropped cols in functions-returning-composite.
Due to lack of concern for the case in the dependency code, it's
possible to drop a column of a composite type even though stored
queries have references to the dropped column via functions-in-FROM
that return the composite type.  There are "soft" references,
namely FROM-clause aliases for such columns, and "hard" references,
that is actual Vars referring to them.  The right fix for hard
references is to add dependencies preventing the drop; something
we've known for many years and not done (and this commit still doesn't
address it).  A "soft" reference shouldn't prevent a drop though.
We've been around on this before (cf. 9b35ddce9, 2c4debbd0), but
nobody had noticed that the current behavior can result in dump/reload
failures, because ruleutils.c can print more column aliases than the
underlying composite type now has.  So we need to rejigger the
column-alias-handling code to treat such columns as dropped and not
print aliases for them.

Rather than writing new code for this, I used expandRTE() which already
knows how to figure out which function result columns are dropped.
I'd initially thought maybe we could use expandRTE() in all cases, but
that fails for EXPLAIN's purposes, because the planner strips a lot of
RTE infrastructure that expandRTE() needs.  So this patch just uses it
for unplanned function RTEs and otherwise does things the old way.

If there is a hard reference (Var), then removing the column alias
causes us to fail to print the Var, since there's no longer a name
to print.  Failing seems less desirable than printing a made-up
name, so I made it print "?dropped?column?" instead.

Per report from Timo Stolz.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/5c91267e-3b6d-5795-189c-d15a55d61dbb@nullachtvierzehn.de
2022-07-21 13:56:05 -04:00
..
backend Fix ruleutils issues with dropped cols in functions-returning-composite. 2022-07-21 13:56:05 -04:00
bin Correct some uses of e.g. and i.e. in message strings and documentation 2022-07-21 12:22:51 +07:00
common logging: Also add the command prefix to detail and hint messages 2022-05-30 07:26:06 +02:00
fe_utils Allow db.schema.table patterns, but complain about random garbage. 2022-04-20 11:37:29 -04:00
include Fix missed corner cases for grantable permissions on GUCs. 2022-07-19 17:22:31 -04:00
interfaces Plug memory leak 2022-07-13 12:10:03 +02:00
makefiles Refactor DLSUFFIX handling 2022-03-25 08:56:02 +01:00
pl Fix missed corner cases for grantable permissions on GUCs. 2022-07-19 17:22:31 -04:00
port Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
template Refactor DLSUFFIX handling 2022-03-25 08:56:02 +01:00
test Fix ruleutils issues with dropped cols in functions-returning-composite. 2022-07-21 13:56:05 -04:00
timezone Update time zone data files to tzdata release 2022a. 2022-05-05 14:54:53 -04:00
tools expression eval: Fix EEOP_JSON_CONSTRUCTOR and EEOP_JSONEXPR size. 2022-07-05 11:26:27 -07:00
tutorial Update copyright for 2022 2022-01-07 19:04:57 -05:00
.gitignore
DEVELOPERS
Makefile Remove the option to build thread_test.c outside configure. 2020-10-21 12:08:48 -04:00
Makefile.global.in Update Unicode data to CLDR 41 2022-04-06 08:17:33 +02:00
Makefile.shlib AIX: Fix missing libpq symbols by respecting SHLIB_EXPORTS. 2021-09-06 11:27:59 -07:00
nls-global.mk Improve frontend error logging style. 2022-04-08 14:55:14 -04:00