postgresql/src/include
Tom Lane 4ace456776 Fix index-only scan plans when not all index columns can be returned.
If an index has both returnable and non-returnable columns, and one of
the non-returnable columns is an expression using a Var that is in a
returnable column, then a query returning that expression could result
in an index-only scan plan that attempts to read the non-returnable
column, instead of recomputing the expression from the returnable
column as intended.

To fix, redefine the "indextlist" list of an IndexOnlyScan plan node
as containing null Consts in place of any non-returnable columns.
This solves the problem by preventing setrefs.c from falsely matching
to such entries.  The executor is happy since it only cares about the
exposed types of the entries, and ruleutils.c doesn't care because a
correct plan won't reference those entries.  I considered some other
ways to prevent setrefs.c from doing the wrong thing, but this way
seems good since (a) it allows a very localized fix, (b) it makes
the indextlist structure more compact in many cases, and (c) the
indextlist is now a more faithful representation of what the index AM
will actually produce, viz. nulls for any non-returnable columns.

This is easier to hit since we introduced included columns, but it's
possible to construct failing examples without that, as per the
added regression test.  Hence, back-patch to all supported branches.

Per bug #17350 from Louis Jachiet.

Discussion: https://postgr.es/m/17350-b5bdcf476e5badbb@postgresql.org
2022-01-01 16:12:03 -05:00
..
access Move parallel vacuum code to vacuumparallel.c. 2021-12-23 11:42:52 +05:30
bootstrap process startup: Remove bootstrap / checker modes from AuxProcType. 2021-08-05 12:18:15 -07:00
catalog Correct comment and some documentation about REPLICA_IDENTITY_INDEX 2021-12-22 16:37:58 +09:00
commands Move parallel vacuum code to vacuumparallel.c. 2021-12-23 11:42:52 +05:30
common Simplify declaring variables exported from libpgcommon and libpgport. 2021-11-29 11:00:00 -05:00
datatype Update copyright for 2021 2021-01-02 13:06:25 -05:00
executor Fix checking of query type in plpgsql's RETURN QUERY command. 2021-10-03 13:21:20 -04:00
fe_utils Rethink pg_dump's handling of object ACLs. 2021-12-06 12:39:45 -05:00
foreign Initial pgindent and pgperltidy run for v14. 2021-05-12 13:14:10 -04:00
jit jit: Do not try to shut down LLVM state in case of LLVM triggered errors. 2021-09-13 18:26:15 -07:00
lib Fix frontend version of sh_error() in simplehash.h. 2021-10-22 16:43:38 -04:00
libpq Harden be-gssapi-common.h for headerscheck 2021-11-26 17:00:29 -03:00
mb Add fast path for validating UTF-8 text 2021-12-20 10:07:29 -04:00
nodes Fix index-only scan plans when not all index columns can be returned. 2022-01-01 16:12:03 -05:00
optimizer Replace random(), pg_erand48(), etc with a better PRNG API and algorithm. 2021-11-28 21:33:07 -05:00
parser Remove Value node struct 2021-09-09 08:36:53 +02:00
partitioning Ensure interleaved_parts field is always initialized 2021-10-01 15:09:49 +13:00
port Check for STATUS_DELETE_PENDING on Windows. 2021-12-10 16:19:43 +13:00
portability Fix another portability bug in recent pgbench commit. 2021-03-10 23:20:41 +13:00
postmaster Improve performance of pgarch_readyXlog() with many status files. 2021-11-11 15:20:26 -05:00
regex Avoid determining regexp subexpression matches, when possible. 2021-08-09 11:26:34 -04:00
replication Fix headerscheck failure in replication/worker_internal.h 2021-11-16 13:30:37 -03:00
rewrite Adjust locations which have an incorrect copyright year 2021-06-04 12:19:50 +12:00
snowball Update snowball 2021-12-07 07:04:05 +01:00
statistics Extended statistics on expressions 2021-03-27 00:01:11 +01:00
storage Change ProcSendSignal() to take pgprocno. 2021-12-16 15:56:03 +13:00
tcop process startup: Split single user code out of PostgresMain(). 2021-09-17 19:56:47 -07:00
tsearch Don't leak compiled regex(es) when an ispell cache entry is dropped. 2021-03-18 22:22:47 -04:00
utils Revert changes about warnings/errors for placeholders. 2021-12-27 16:01:10 -05:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
c.h Simplify the general-purpose 64-bit integer parsing APIs 2021-12-17 06:32:07 +01:00
fmgr.h Add ABI extra field to fmgr magic block 2021-11-22 08:00:14 +01:00
funcapi.h Reconsider the handling of procedure OUT parameters. 2021-06-10 17:11:36 -04:00
getaddrinfo.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
getopt_long.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
Makefile Build in some knowledge about foreign-key relationships in the catalogs. 2021-02-02 17:11:55 -05:00
miscadmin.h Doc: add glossary term for "auxiliary process" 2021-09-20 12:22:02 -03:00
pg_config.h.in Add configure probe for rl_variable_bind(). 2021-12-02 13:06:27 -05:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Replace random(), pg_erand48(), etc with a better PRNG API and algorithm. 2021-11-28 21:33:07 -05:00
pg_getopt.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pg_trace.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgstat.h Add a view to show the stats of subscription workers. 2021-11-30 08:54:30 +05:30
pgtar.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
pgtime.h Fix actively-misleading comments about the contents of struct pg_tm. 2021-09-06 11:43:44 -04:00
port.h Check for STATUS_DELETE_PENDING on Windows. 2021-12-10 16:19:43 +13:00
postgres.h Fix misleading comments about TOAST access macros. 2021-09-08 14:11:35 -04:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
rusagestub.h Update copyright for 2021 2021-01-02 13:06:25 -05:00
windowapi.h Update copyright for 2021 2021-01-02 13:06:25 -05:00