postgresql/src/backend/optimizer/path
Tom Lane 689696c711 Fix bitmap AND/OR scans on the inside of a nestloop partition-wise join.
reparameterize_path_by_child() failed to reparameterize BitmapAnd
and BitmapOr paths.  This matters only if such a path is chosen as
the inside of a nestloop partition-wise join, where we have to pass
in parameters from the outside of the nestloop.  If that did happen,
we generated a bad plan that would likely lead to crashes at execution.

This is not entirely reparameterize_path_by_child()'s fault though;
it's the victim of an ancient decision (my ancient decision, I think)
to not bother filling in param_info in BitmapAnd/Or path nodes.  That
caused the function to believe that such nodes and their children
contain no parameter references and so need not be processed.

In hindsight that decision looks pretty penny-wise and pound-foolish:
while it saves a few cycles during path node setup, we do commonly
need the information later.  In particular, by reversing the decision
and requiring valid param_info data in all nodes of a bitmap path
tree, we can get rid of indxpath.c's get_bitmap_tree_required_outer()
function, which computed the data on-demand.  It's not unlikely that
that nets out as a savings of cycles in many scenarios.  A couple
of other things in indxpath.c can be simplified as well.

While here, get rid of some cases in reparameterize_path_by_child()
that are visibly dead or useless, given that we only care about
reparameterizing paths that can be on the inside of a parameterized
nestloop.  This case reminds one of the maxim that untested code
probably does not work, so I'm unwilling to leave unreachable code
in this function.  (I did leave the T_Gather case in place even
though it's not reached in the regression tests.  It's not very
clear to me when the planner might prefer to put Gather below
rather than above a nestloop, but at least in principle the case
might be interesting.)

Per bug #16536, originally from Arne Roland but with a test case
by Andrew Gierth.  Back-patch to v11 where this code came in.

Discussion: https://postgr.es/m/16536-2213ee0b3aad41fd@postgresql.org
2020-07-14 18:56:56 -04:00
..
allpaths.c Cope with lateral references in the quals of a subquery RTE. 2020-07-13 20:38:20 -04:00
clausesel.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
costsize.c code: replace 'master' with 'leader' where appropriate. 2020-07-08 12:58:32 -07:00
equivclass.c Consider Incremental Sort paths at additional places 2020-04-07 16:43:22 +02:00
indxpath.c Fix bitmap AND/OR scans on the inside of a nestloop partition-wise join. 2020-07-14 18:56:56 -04:00
joinpath.c Clean up newlines following left parentheses 2020-01-30 13:42:14 -03:00
joinrels.c Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04: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 Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
tidpath.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00