Here is an updated patch with comments and test case. I also change thecode to store 'group_clause_relids' directly in RestrictInfo.
pgsql-hackers by date:
Соглашаюсь с условиями обработки персональных данных