Adam Brusselback <adambrusselback@gmail.com> writes:
> Alright with that off I get:
> ...
> Way better.
OK, that confirms the suspicion that beta1's FK-join-estimation logic
is the culprit here. We had already decided that that logic is broken,
and there's a rewrite in progress:
https://www.postgresql.org/message-id/15245.1466031608%40sss.pgh.pa.us
I wonder though whether the rewrite will fix your example. Could you
either make some test data available, or try HEAD + aforesaid patch
to see if it behaves sanely on your data?
regards, tom lane