On Thu, 22 Feb 2024 at 10:28, Vladimir Sitnikov <sitnikov.vladi...@gmail.com> wrote: > > >When splitting a multi insert statement you're going to duplicate some work > > I do not know how this could be made more efficient as I execute parse only > once, and then I send bind+exec+bind+exec > without intermediate sync messages, so the data should flow nicely in TCP > packets.
I agree you cannot change that flow to be more efficient, but I meant that your comparison was not fair: 1. Multi-insert vs multiple single inserts is actually executing different queries 2. Going from Query -> Parse+Bind+Exec for the same query, only changes protocol related things > Here are some measurements regarding savepoints for simple vs extended > Sure they are not very scientific, however, they show improvement for simple > protocol Alright, those improvements are not huge, but I agree it's clear that the extended protocol has some overhead. So probably you'd want to keep using the simple protocol to send the SAVEPOINT query. > Apparently, sending an extra message would increase the overhead of the > protocol, thus reducing the efficiency of the application. > What is the benefit of sending extra Sync? > > https://www.postgresql.org/docs/current/protocol-overview.html#PROTOCOL-MESSAGE-CONCEPTS > suggests that is is fine to mix both simple and extended messages > depending on the needs of the application. Yes, it's fine to mix and match extended and simple protocol. But the protocol docs quite clearly state that a sync is required before going back to the Simple protocol: "At completion of each series of extended-query messages, the frontend should issue a Sync message." https://www.postgresql.org/docs/current/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY Terminating a sequence of extended messages with a Query message instead of a Sync message is definitely undefined behaviour.