Flipping the removal around has the effect I expected on the plan shape, but some of the regression test queries now give the wrong answer, so there's something faulty about that analysis.
I think we may have a minor mistake when constructing the qpqual list in create_bitmap_scan_plan. The qpqual list is supposed to be scan_clauses minus indexquals. So we check each scan clause to see if it is redundant with any indexqual, by using equal, checking EC or using predicate_implied_by.
Note that the indexqual here may not be the form that has been going through constant folding. Such as in this case with a boolean index, the indexqual would be converted to 'indexkey expression = TRUE' by match_boolean_index_clause. And that may make us fail to tell the scan clause is redundant.
The comment of predicate_implied_by() says
* The top-level List structure of each list corresponds to an AND list. * We assume that eval_const_expressions() has been applied and so there * are no un-flattened ANDs or ORs (e.g., no AND immediately within an AND, * including AND just below the top-level List structure).
So I think we need to run eval_const_expressions on indexquals before we check for duplicate clauses, something like attached.