I can reproduce the high memory consumption with your queries.
Looking at the patch, I see that you changed the lifetime of the
temporary context from per-tuple to per-index-scan. It is not obvious
that this change is correct. Could you explain, what memory context are
involved in the scan, and what their lifetimes are, before and after
your changes? What are these memory allocations that are causing the
high consumption, and what code makes them? This will make it easier to
understand your changes.
Also, this link doesn't open for me.
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company