I've applied the patch you sent in for this, with some editorializations
--- you were being too aggressive about substituting constants, with the
net effect that the plan was not still parameterized as it was supposed
to be.
I realized along the way that what we're really doing here is inventing
a notion of constant-folding expressions "for estimation purposes only".
As such, we don't have to be as rigid about making only provably safe
transformations as eval_const_expressions normally has to be. I didn't
do anything with the idea yet, but I'd like to look into having this
mode do more than just substitute Param values. An example that's been
causing us trouble for a long while is that the planner can't make any
nondefault selectivity estimate forSELECT ... WHERE timestampcol > now() - '1 day';
because eval_const_expressions dare not reduce now() to current time.
But I think it would be entirely reasonable to do so "for estimation
purposes".
regards, tom lane