Here is a new version of the patch, rebased to 749c7c41 and with some cosmetic changes.
-- Alexander KuzmenkovPostgres Professional: http://www.postgrespro.comThe Russian Postgres Company