Yeah, I was aiming for a way to have it so the planner didn't vandalise WindowClause.
I've attached a patch which fixes the bug and does not require any further modifications to WindowClause.
The patch looks sane to me, expect that line 122 in the patch introduces a whitespace-only line.
Another review comment:
- * extra_used_attrs can passed as non-NULL to mark any columns that we should + * extra_used_attrs can be passed as non-NULL to mark any columns that we should