postgresql/src/backend
Tom Lane 7f90a5dc36 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 Promote assertion about !ReindexIsProcessingIndex to runtime error. 2024-02-25 16:15:07 -05:00
bootstrap Skip WAL for new relfilenodes, under wal_level=minimal. 2020-04-04 12:25:34 -07:00
catalog Fix confusion about the return rowtype of SQL-language procedures. 2024-03-12 18:16:10 -04:00
commands Fix handling of polymorphic output arguments for procedures. 2024-05-14 20:19:20 -04:00
executor Ensure we allocate NAMEDATALEN bytes for names in Index Only Scans 2024-05-01 13:23:05 +12:00
foreign Update copyrights for 2020 2020-01-01 12:21:45 -05:00
jit Fix illegal attribute propagation in LLVM JIT. 2024-04-10 12:15:41 +12:00
lib Fix lock assertions in dshash.c. 2022-07-11 15:48:54 +12:00
libpq Disconnect if socket cannot be put into non-blocking mode 2024-03-12 10:18:53 +02:00
main Fix outdated --help message for postgres -f 2022-08-15 13:37:40 +09:00
nodes Further fixes for MULTIEXPR_SUBLINK fix. 2022-09-06 16:38:18 -04:00
optimizer Account for optimized MinMax aggregates during SS_finalize_plan. 2024-05-18 14:31:35 -04:00
parser Fix type-checking of RECORD-returning functions in FROM, redux. 2024-04-15 12:56:56 -04:00
partitioning Fix incorrect pruning of NULL partition for boolean IS NOT clauses 2024-02-20 12:51:17 +13:00
po Translation updates 2024-05-06 12:13:39 +02:00
port Close socket in case of errors in setting non-blocking 2024-01-17 11:24:11 +01:00
postmaster Avoid deadlock during orphan temp table removal. 2024-04-02 14:59:04 -04:00
regex Avoid character classification in regex escape parsing. 2023-04-21 08:20:47 -07:00
replication Revert "Skip .DS_Store files in server side utils" 2024-02-13 14:09:24 +01:00
rewrite Disallow converting a table to a view within an outer SQL command. 2024-04-30 15:22:55 -04:00
snowball In the Snowball dictionary, don't try to stem excessively-long words. 2022-08-31 10:42:05 -04:00
statistics Fix incorrectly reported stats kind in "can't happen" ERROR 2024-03-05 16:19:05 +13:00
storage Fix documentation about DROP DATABASE FORCE process termination rights. 2024-05-16 14:11:14 -07:00
tcop Be more rigorous about local variables in PostgresMain(). 2023-07-10 12:14:34 -04:00
tsearch Limit to_tsvector_byid's initial array allocation to something sane. 2023-09-25 11:50:28 -04:00
utils Detect more overflows in timestamp[tz]_pl_interval. 2024-04-28 13:42:13 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
Makefile Update copyrights for 2020 2020-01-01 12:21:45 -05:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
nls.mk Translation updates 2020-09-14 13:14:53 +02:00