Here is a new version of the patch, which:
1. Fixes some minor stylistic issues.
2. Uses binaryheap (instead of a custom ugly stack) for merging.
Regards,
Constantin S. Pan
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company