Joel Jacobson <joel@gluefinance.com> writes:
> I fully agree it must obtain a sharelock on the FK, but I cannot understand
> why it is granted it the first time, but not the second time?
It *isn't* granted it the first time, because it doesn't try to acquire
it the first time. That FK check gets optimized away, while the second
one doesn't. Please reread what I said before.
regards, tom lane