Jeff Janes <jeff.janes@gmail.com> writes:
> For some queries PostgreSQL can spend most of its time creating the exact
> same bitmap over and over. For example, in the below case: (also attached
> as a file because line-wrapping is going to make a mess of it)
Uh .... it's not the "exact same bitmap each time", because the selected
rows vary depending on the value of g.i.
If the output of the subplan was indeed constant, I'd expect the planner
to stick a Materialize node atop it. That would almost certainly win
more than re-using the index output to scan the heap additional times.
regards, tom lane