postgresql/src/include
Tom Lane ce0d165446 Account for optimized MinMax aggregates during SS_finalize_plan.
We are capable of optimizing MIN() and MAX() aggregates on indexed
columns into subqueries that exploit the index, rather than the normal
thing of scanning the whole table.  When we do this, we replace the
Aggref node(s) with Params referencing subquery outputs.  Such Params
really ought to be included in the per-plan-node extParam/allParam
sets computed by SS_finalize_plan.  However, we've never done so
up to now because of an ancient implementation choice to perform
that substitution during set_plan_references, which runs after
SS_finalize_plan, so that SS_finalize_plan never sees these Params.

The cleanest fix would be to perform a separate tree walk to do
these substitutions before SS_finalize_plan runs.  That seems
unattractive, first because a whole-tree mutation pass is expensive,
and second because we lack infrastructure for visiting expression
subtrees in a Plan tree, so that we'd need a new function knowing
as much as SS_finalize_plan knows about that.  I also considered
swapping the order of SS_finalize_plan and set_plan_references,
but that fell foul of various assumptions that seem tricky to fix.
So the approach adopted here is to teach SS_finalize_plan itself
to check for such Aggrefs.  I refactored things a bit in setrefs.c
to avoid having three copies of the code that does that.

Back-patch of v17 commits d0d44049d and 779ac2c74.  When d0d44049d
went in, there was no evidence that it was fixing a reachable bug,
so I refrained from back-patching.  Now we have such evidence.

Per bug #18465 from Hal Takahara.  Back-patch to all supported
branches.

Discussion: https://postgr.es/m/18465-2fae927718976b22@postgresql.org
Discussion: https://postgr.es/m/2391880.1689025003@sss.pgh.pa.us
2024-05-18 14:31:35 -04:00
..
access Fix the parameters order for TableAmRoutine.relation_copy_for_cluster() 2024-04-03 21:42:38 +03:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Fix some typos and some incorrectly duplicated words 2023-04-18 14:03:49 +12:00
bootstrap Update copyright for 2023 2023-01-02 15:00:37 -05:00
catalog Ensure we allocate NAMEDATALEN bytes for names in Index Only Scans 2024-05-01 13:21:50 +12:00
commands Revert MAINTAIN privilege and pg_maintain predefined role. 2023-07-07 11:25:23 -07:00
common Fix corner-case 64-bit integer subtraction bug on some platforms. 2023-11-09 09:53:05 +00:00
datatype Code review for commit 05a7be935. 2023-01-26 12:51:00 -05:00
executor Fix confusion about the return rowtype of SQL-language procedures. 2024-03-12 18:16:10 -04:00
fe_utils Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit llvmjit: Use explicit LLVMContextRef for inlining 2023-11-17 10:18:38 +01:00
lib simplehash: Free collisions array in SH_STAT 2024-04-07 19:09:02 -07:00
libpq Remove a few unused global variables and declarations. 2023-06-12 16:25:37 +03:00
mb Move is_valid_ascii() to ascii.h. 2024-01-29 12:09:03 -06:00
nodes Ensure we allocate NAMEDATALEN bytes for names in Index Only Scans 2024-05-01 13:21:50 +12:00
optimizer Account for optimized MinMax aggregates during SS_finalize_plan. 2024-05-18 14:31:35 -04:00
parser Avoid unnecessary plancache revalidation of utility statements. 2023-08-24 12:02:40 -04:00
partitioning Revert "Move PartitionPruneInfo out of plan nodes into PlannedStmt" 2023-05-04 12:09:59 +02:00
pch Update copyright for 2023 2023-01-02 15:00:37 -05:00
port Fix gai_strerror() thread-safety on Windows. 2024-02-12 11:14:42 +13:00
portability instr_time: Represent time as an int64 on all platforms 2023-01-20 21:16:47 -08:00
postmaster Fix wal_writer_flush_after initializer value. 2023-05-15 11:19:54 +12:00
regex Fix various typos 2023-04-18 13:23:23 +12:00
replication Rename logical_replication_mode to debug_logical_replication_streaming 2023-08-29 15:24:09 +02:00
rewrite Make Vars be outer-join-aware. 2023-01-30 13:16:20 -05:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Update copyright for 2023 2023-01-02 15:00:37 -05:00
storage Avoid deadlock during orphan temp table removal. 2024-04-02 14:59:04 -04:00
tcop Update copyright for 2023 2023-01-02 15:00:37 -05:00
tsearch Update tsearch regex memory management. 2023-04-08 22:09:17 +12:00
utils Use a hash table for catcache.c's CatCList objects. 2024-03-22 17:13:53 -04:00
.gitignore Refactor dlopen() support 2018-09-06 11:33:04 +02:00
Makefile Include headers of archive/ in installation 2023-03-10 20:08:10 +09:00
c.h Introduce PG_IO_ALIGN_SIZE and align all I/O buffers. 2023-04-08 16:34:50 +12:00
fmgr.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
funcapi.h Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
getopt_long.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
meson.build meson: Make some Meson style more consistent with surrounding code 2023-06-29 13:06:02 +02:00
miscadmin.h Add VACUUM/ANALYZE BUFFER_USAGE_LIMIT option 2023-04-07 11:40:31 +12:00
pg_config.h.in Use BIO_{get,set}_app_data instead of BIO_{get,set}_data. 2023-11-28 12:34:03 -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_ext.h.meson meson: Add initial version of meson based build system 2022-09-21 22:37:17 -07:00
pg_config_manual.h Fix typos in comments 2023-05-02 12:23:08 +09:00
pg_getopt.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_trace.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgstat.h Add writeback to pg_stat_io 2023-05-17 11:18:35 -07:00
pgtar.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pgtime.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
port.h Add SHELL_ERROR and SHELL_EXIT_CODE magic variables to psql. 2023-03-21 13:03:56 -04:00
postgres.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
postgres_ext.h Move RelFileNumber declarations to common/relpath.h. 2022-09-27 12:01:57 -04:00
postgres_fe.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
varatt.h New header varatt.h split off from postgres.h 2023-01-10 05:54:36 +01:00
windowapi.h Update copyright for 2023 2023-01-02 15:00:37 -05:00