Re: execute multiple queries with mysql c++ connector

From: Axel Schwenke <axel.schwenke_at_gmx.de>
Date: Tue, 7 Mar 2017 23:31:35 +0100
Message-ID: <o9nc6v$t13$1_at_dont-email.me>


On 07.03.2017 18:19, The Natural Philosopher wrote:
> On 07/03/17 16:46, Axel Schwenke wrote:

>> 3. whenever you think you have to run two (or more) statements
>> simultaneously to achieve a certain result, you're doing it wrong.

>
> How can you therefore create an atomic unit of two or more queries?

Maybe you should check your dictionary at "atomic" vs. "simultaneous" first

> I.e. lest suppose you want to read a number, like a bank balance, and
> subtract something from it and write it back, but you dont want some other
> asynchronous process to be doing the same?

It's called transaction. MySQL supports this for more than 10 years now.

> how does it know that they COMMIT is coming from the same person who sent
the TRANSACTION

Because transaction boundaries are tied to the context of a connection (sometimes and IMHO better called "session"). And unlike HTTP, the MySQL protocol does not require cookies or such. A session and the (TCP) connection between client and server are essentially the same. There is no need for additional tokens to recognize a certain communication partner as the one who had been calling earlier.

[Quoted] Even more: if the connection should break, i.e. due to a crash of the client machine or a network split, MySQL will close the session and roll back any open connection.

There are a lot of things that are tied to the session: session variables, temporary tables, prepared statements, the LAST_INSERT_ID() etc. pp. Actually MySQL would be pretty useless without all that.

Now, /if/ you want to run statements concurrently from your application, you can of course do that. Just open multiple connections. The reason for doing that is however never a functional one. But you might leverage multiple worker threads inside the MySQL server that way. I.e. you could dump or load multiple tables in parallel to speedup the overall performance.

Oh, look - this already exists: https://github.com/maxbube/mydumper Received on Tue Mar 07 2017 - 23:31:35 CET

Original text of this message