This seems very much related to my patch here:https://commitfest.postgresql.org/41/4081/ (yes, somehow the threadgot split. I blame outlook)
I'll try to review this one soonish.