postgresql/src/backend/optimizer/path
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
..
allpaths.c Teach remove_unused_subquery_outputs about window run conditions 2022-05-27 10:37:58 +12:00
clausesel.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
costsize.c Avoid overflow hazard when clamping group counts to "long int". 2022-05-21 13:13:44 -04:00
equivclass.c Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
indxpath.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
joinpath.c Fix incorrect row estimates used for Memoize costing 2022-05-16 16:07:56 +12:00
joinrels.c Update copyright for 2022 2022-01-07 19:04:57 -05:00
Makefile Split all OBJS style lines in makefiles into one-line-per-entry style. 2019-11-05 14:41:07 -08:00
pathkeys.c Pre-beta mechanical code beautification. 2022-05-12 15:17:30 -04:00
tidpath.c Update copyright for 2022 2022-01-07 19:04:57 -05:00