Bug #60470 Asynchronous prepared statements
Submitted: 15 Mar 2011 8:36 Modified: 26 Feb 2012 16:33
Reporter: Vlad Paiu Email Updates:
Status: Verified Impact on me:
Category:MySQL Server: C API (client library) Severity:S4 (Feature request)
Version: OS:Any
Assigned to: CPU Architecture:Any
Tags: asynchronous, prepared, statements

[15 Mar 2011 8:36] Vlad Paiu

I saw that there is a workaround to run regular queries asynchronously, by using the mysql_send_query func, followed by read_query_result when there is an event on the socket. This mechanism works but I can't really see why it's not documented anywhere on the official website.

Still, I couldn't find such a mechanism for running prepared statements asynchronously by using the libmysql library. I took a look into the sources and saw that mysql_stmt_execute boils down to the following : 

cli_advanced_command(mysql, COM_STMT_EXECUTE, buff, sizeof(buff),
                                 (uchar*) packet, length, 1, stmt) ||

so, from what I understand, it could also be done asynchronously, but the API does not allow this for now. 

Is there any chance there could be some modifications to the prep statements API to allow developers to run asynchronous prepared statements ?

How to repeat:
No prepared statement query can be done async

Suggested fix:
It shouldn't be so hard to break  mysql_stmt_execute into two pieces, one that can be run without waiting, and the other that should be called when an event is triggered on the connection's file descriptor.
[24 Feb 2012 8:56] Georgi Kodinov
Thanks for the reasonable feature request.

The API functions that you mention above (and in some other publications like (http://jan.kneschke.de/2008/9/9/async-mysql-queries-with-c-api/) are undocumented internal functions for a very good reason. These functions are implementation of the C API hooks for the internal API to support the embedded mysql server. 
As such they're subject to change.
And using them will render your code unusable in the embedded server context.
[26 Feb 2012 16:33] Vlad Paiu

Thanks for your answer.
I consider that the lack of async queries support in MySQL is a very big drawback.

Since I did not find an official support for this, I had to use other databases ( like postgres ) that support asynchronous queries, which is a shame, since I liked MySQL a lot.

Any info of when/if this will be supported ?