boostorg / mysql

MySQL C++ client based on Boost.Asio
https://www.boost.org/doc/libs/master/libs/mysql
Boost Software License 1.0
257 stars 33 forks source link

close_statement makes the immediately subsequent operation slow #181

Closed anarthal closed 9 months ago

anarthal commented 11 months ago
sheldonlyr commented 11 months ago

How can we avoid this performance issue on application level? Any suggestions?

anarthal commented 11 months ago

At this moment, you can use reset_connection/async_reset_connection, which doesn't suffer from this. This function will wipe any session state modifications from the connection, including prepared statements. This has the neat effect of batch-closing all statements you opened.

On the other hand, [async_]reset_connection wipes all session variables, too. This includes any time_zone or character settings you did. The character set/collation will get reset to the server's default, and not to whatever you specified in handshake_params (MySQL being MySQL). You can retrieve which charset will your server use by running SELECT @@global.character_set_client, @@global.character_set_connection, @@global.character_set_results;.

If you're using single-use connections (you're calling close, then connecting them again), you don't have to call [async_]close_statement at all.

If you can provide more information about your use case, I may be able to give you some extra ideas.

sheldonlyr commented 11 months ago

Hi! Thanks for so quick answer!

sheldonlyr commented 11 months ago

Oh, one more question😅 Does connection pool can be used in Boost 1.84? I'm really looking forward to the addition of this feature.

anarthal commented 11 months ago

I'm afraid it will be 1.85. I'm currently finishing docs and tests for the feature, so it can't make the times required by Boost for 1.84. I expect it to be in master in a few weeks though, and I'd be more than happy to have some early feedback.