So I think we need to run eval_const_expressions on indexquals before we check for duplicate clauses, something like attached.
BTW, (revise to the v1 patch), if this is the right way to go, we should do that before the foreach loop, so that we need to run eval_const_expressions on indexquals only once rather than for each scan clause.