Okay, I have pushed this patch now backpatched to all branches since
9.3, after staring at this code for way too long. I spent a lot of time
testing it to ensure things are correct, but please double-check.
Many thanks to Dan Wood for the initial diagnosys, and to Yi Wen and
Michael for the review and discussion.
--
Álvaro Herrera https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services