@@ -1594,6 +1594,7 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
15941594 NET *net= &thd->net ;
15951595 bool error= 0 ;
15961596 bool do_end_of_statement= true ;
1597+ bool log_slow_done= false ;
15971598 DBUG_ENTER (" dispatch_command" );
15981599 DBUG_PRINT (" info" , (" command: %d %s" , command,
15991600 (command_name[command].str != 0 ?
@@ -1820,6 +1821,7 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
18201821 case COM_STMT_BULK_EXECUTE:
18211822 {
18221823 mysqld_stmt_bulk_execute (thd, packet, packet_length);
1824+ log_slow_done= true ;
18231825#ifdef WITH_WSREP
18241826 if (WSREP (thd))
18251827 {
@@ -1831,6 +1833,7 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
18311833 case COM_STMT_EXECUTE:
18321834 {
18331835 mysqld_stmt_execute (thd, packet, packet_length);
1836+ log_slow_done= true ;
18341837#ifdef WITH_WSREP
18351838 if (WSREP (thd))
18361839 {
@@ -2007,6 +2010,7 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
20072010 mysql_parse (thd, beginning_of_next_stmt, length, &parser_state);
20082011
20092012 }
2013+ log_slow_done= thd->lex ->sql_command == SQLCOM_EXECUTE;
20102014
20112015 DBUG_PRINT (" info" ,(" query ready" ));
20122016 break ;
@@ -2460,22 +2464,19 @@ dispatch_command_return dispatch_command(enum enum_server_command command, THD *
24602464 if (likely (!thd->is_error () && !thd->killed_errno ()))
24612465 mysql_audit_general (thd, MYSQL_AUDIT_GENERAL_RESULT, 0 , 0 );
24622466
2463- mysql_audit_general (thd, MYSQL_AUDIT_GENERAL_STATUS,
2464- thd->get_stmt_da ()->is_error () ?
2465- thd->get_stmt_da ()->sql_errno () : 0 ,
2466- command_name[command].str );
2467+ if (!log_slow_done)
2468+ mysql_audit_general (thd, MYSQL_AUDIT_GENERAL_STATUS,
2469+ thd->get_stmt_da ()->is_error () ?
2470+ thd->get_stmt_da ()->sql_errno () : 0 ,
2471+ command_name[command].str );
24672472
24682473 thd->update_all_stats ();
24692474
24702475 /*
2471- Write to slow query log only those statements that received via the text
2472- protocol except the EXECUTE statement. The reason we do that way is
2473- that for statements received via binary protocol and for the EXECUTE
2474- statement, the slow statements have been already written to slow query log
2475- inside the method Prepared_statement::execute().
2476+ for backward compatibility we only log COM_QUERY here,
2477+ as if COM_STMT_PREPARE or COM_FIELD_LIST couldn't be slow.
24762478 */
2477- if (command == COM_QUERY &&
2478- thd->lex ->sql_command != SQLCOM_EXECUTE)
2479+ if (command == COM_QUERY && !log_slow_done)
24792480 log_slow_statement (thd);
24802481 else
24812482 delete_explain_query (thd->lex );
0 commit comments