hi.
I don't want to disrupt this thread too much.so I created a separate thread ([1]) for my attached patch.
[1] https://www.postgresql.org/message-id/CACJufxF8_VzCFRHRt4OHHF74QtB8tj5Z%3Ddjsy7Y31OHKG5s1-w%40mail.gmail.com