I’ve got C# code that accesses MySQL through ODBC.
It creates a transaction, does a few thousand insert commands, and then commits. Now my question is how many ’round trips’, so to speak, happen against the DB server? I mean, does it simply transmit every insert command to the DB server, or does it cache/buffer them and send them in batches? And is this configurable in any way?
MySQL has an extended SQL style that can be used, where mass inserts are put in several at a time:
I will usually collect a few hundred insert-parts into a string before running the SQL query itself. This will reduce the overhead of parsing and communication by batching them yourself.