> So you would suggest changing my message chain to send Bind right after > Execute, right? This would yield the following messages:
> P1/P2/D1/B1/E1/D2/B2/E2/S (rather than the current > P1/D1/B1/P2/D2/B2/E1/C1/E2/C2/S)
> This would mean that I would switch to using named statements and the > unnamed portal, rather than the current unnamed statement > and named portals. If I recall correctly, I was under the impression that > there are some PostgreSQL performance benefits to using the > unnamed statement over named statements, although I admit I can't find any > documentation backing that. Can you confirm that the two > are equivalent performance-wise?
Hmm. I do not recall exactly what performance optimizations apply to those two cases; they're probably not "equivalent", though I do not think the difference is major in either case. TBH I was a bit surprised on reading your message to hear that the system would take that sequence at all; it's not obvious that it should be allowed to replace a statement, named or not, while there's an open portal that depends on it.
Unfortunately, the alternative I proposed above, P1/P2/D1/B1/E1/D2/B2/E2/S, suffers from the same issue: any sequence in which a Bind is sent after a previous Execute is deadlock-prone - Execute causes PostgreSQL to start writing a potentially large dataset, while Bind means the client may be writing a potentially large parameter value.
In other words, unless I'm mistaken it seems there's no alternative but to implement non-blocking I/O at the client side - write until writing would block, switching to reading when that happens. This adds some substantial complexity, especially with .NET's SSL/TLS implementation layer.
Or does anyone see some sort of alternative which I've missed?