Thanks everyone for your remarks and comments!
Here is an improved version of a patch.
Main changes:
* Patch passes `make installcheck`
* Code is fully commented, also no more TODO's
I wish I sent this version of a patch last time. Now I realize it was
really hard to read and understand. Hope I managed to correct this
flaw. If you believe that some parts of the code are still poorly
commented or could be improved in any other way please let me know.
And as usual, any other comments, remarks or questions are highly
appreciated!
--
Best regards,
Aleksander Alekseev