Off-list Ashutosh Bapat has suggested using a flag instead of counting number of dummy rels and then manipulating on it. That will be simple and smoother.
I agree with his suggestion and updated my patch accordingly.
Thanks
--
Jeevan Chalke Technical Architect, Product Development EnterpriseDB Corporation The Enterprise PostgreSQL Company