postgresql/src/backend
David Rowley 3e9abd2eb1 Teach remove_unused_subquery_outputs about window run conditions
9d9c02ccd added code to allow the executor to take shortcuts when quals
on monotonic window functions guaranteed that once the qual became false
it could never become true again.  When possible, baserestrictinfo quals
are converted to become these quals, which we call run conditions.

Unfortunately, in 9d9c02ccd, I forgot to update
remove_unused_subquery_outputs to teach it about these run conditions.
This could cause a WindowFunc column which was unused in the target list
but referenced by an upper-level WHERE clause to be removed from the
subquery when the qual in the WHERE clause was converted into a window run
condition.  Because of this, the entire WindowClause would be removed from
the query resulting in additional rows making it into the resultset when
they should have been filtered out by the WHERE clause.

Here we fix this by recording which target list items in the subquery have
run conditions. That gets passed along to remove_unused_subquery_outputs
to tell it not to remove these items from the target list.

Bug: #17495
Reported-by: Jeremy Evans
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/17495-7ffe2fa0b261b9fa@postgresql.org
2022-05-27 10:37:58 +12:00
..
access Add 'static' to file-local variables missing it. 2022-05-12 12:39:33 -07:00
bootstrap Indent C code in flex and bison files 2022-05-13 07:17:29 +02:00
catalog Extend pg_publication_tables to display column list and row filter. 2022-05-19 08:20:55 +05:30
commands Fix DDL deparse of CREATE OPERATOR CLASS 2022-05-20 18:52:55 +02:00
executor Avoid overflow hazard when clamping group counts to "long int". 2022-05-21 13:13:44 -04:00
foreign Create routine able to set single-call SRFs for Materialize mode 2022-03-07 10:26:29 +09:00
jit Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
lib Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
libpq Remove misguided SSL key file ownership check in libpq. 2022-05-26 14:14:05 -04:00
main Fix collection of typos in the code and the documentation 2022-03-15 11:29:35 +09:00
nodes Rename JsonIsPredicate.value_type, fix JSON backend/nodes/ infrastructure. 2022-05-13 11:40:08 -04:00
optimizer Teach remove_unused_subquery_outputs about window run conditions 2022-05-27 10:37:58 +12:00
parser Teach remove_unused_subquery_outputs about window run conditions 2022-05-27 10:37:58 +12:00
partitioning Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
po Translation updates 2022-05-16 11:12:42 +02:00
port Ensure that the argument of shmdt(2) is declared "void *". 2022-02-15 17:17:28 -05:00
postmaster Add a new shmem_request_hook hook. 2022-05-13 09:31:06 -04:00
regex Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
replication Extend pg_publication_tables to display column list and row filter. 2022-05-19 08:20:55 +05:30
rewrite Fix incautious CTE matching in rewriteSearchAndCycle(). 2022-04-23 12:16:12 -04:00
snowball Update copyright for 2022 2022-01-07 19:04:57 -05:00
statistics Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
storage Repurpose PROC_COPYABLE_FLAGS as PROC_XMIN_FLAGS 2022-05-19 16:20:32 +02:00
tcop Fix DDL deparse of CREATE OPERATOR CLASS 2022-05-20 18:52:55 +02:00
tsearch Remove extraneous blank lines before block-closing braces 2022-04-13 19:16:02 +02:00
utils Avoid ERRCODE_INTERNAL_ERROR in oracle_compat.c functions. 2022-05-26 12:25:10 -04:00
.gitignore Add .gitignore entries for AIX-specific intermediate build artifacts. 2015-07-08 20:44:22 -04:00
common.mk Remove PARTIAL_LINKING build mode. 2018-03-30 17:33:04 -07:00
Makefile Server-side gzip compression. 2022-01-24 15:13:18 -05:00
nls.mk Report progress of startup operations that take a long time. 2021-10-25 11:51:57 -04:00