The problem is that someone moved in MySQL 5.1 mysql_unlock_tables() from mysql_insert to close_thread_tables().
There is two solutions how to fix this:
a) Move that we call close_thread_tables() before sending the result to the client (as you suggested)
b) Move out the mysql_unlock_tables() + thd->binlog_flush_pending_rows_event from close_threaded_tables() to it's own function (unlock_thread_tables() ?) and call this before we call net_end_statement() in sql_parse.cc
I would suggest we do b) because this enables the client to get some work done while the server is doing end-of-statement cleanup, which results in higher throughput in many cases.
The problem is that someone moved in MySQL 5.1 mysql_unlock_ tables( ) from mysql_insert to close_thread_ tables( ).
There is two solutions how to fix this: tables( ) before sending the result to the client (as you suggested) tables( ) + thd->binlog_ flush_pending_ rows_event from close_threaded_ tables( ) to it's own function (unlock_ thread_ tables( ) ?) and call this before we call net_end_statement() in sql_parse.cc
a) Move that we call close_thread_
b) Move out the mysql_unlock_
I would suggest we do b) because this enables the client to get some work done while the server is doing end-of-statement cleanup, which results in higher throughput in many cases.