calculate_cond_selectivity_for_table has the code to compute table->cond_selectivity from selectivities of potential range accesses.
Selectivities of range accesses are multiplied, but there is code to handle the situation where range accesses use restrictions on the same column. In that case, the code has additional multiplier to account for this fact (and avoid counting the same selectivity twice).
This bug is about that code not working for a fairly basic example where I think it should work.
The testcase (not necessarily minimal):
Checking the optimizer trace, I can see that this will create potential range accesses:
Both range accesses use column col2, both have selectivity around 0.5
But when I step through calculate_cond_selectivity_for_table() function, I can see that
- table->cond_selectivity is assigned the value of 1
- table->cond_selectivity is multiplied by first range access selectivity
- table->cond_selectivity is multiplied by second range access selectivity
I don't see any adjustments to the selectivity that are due to the fact that both potential range acccesses use the same column. I think this is not what was intended.