I think this function will not kill transaction that only have query "SELECT", because "SELECT" command needn't lock.
Only if the transaction contain "UPDATE/DELTE/INSERT" and not type "COMMT" a long time, it must be killed.
I modified source code on our system.
I add "enum enum_sql_command last_sql_command;" on class THD, it record the last Query's command type, default value is "SQLCOM_SELECT". I init it on THD::THD, add "last_sql_command = SQLCOM_SELECT;".
And I update this value on function mysql_execute_command, only if the query is "UPDATE/DELTE/INSERT", I update the last_sql_command. Then if the last_sql_command is not select, I can consider the thread is contain MODIFY query.
if (lex->sql_command == SQLCOM_UPDATE
|| thd->last_sql_command == SQLCOM_INSERT
|| thd->last_sql_command == SQLCOM_DELETE
|| thd->last_sql_command == SQLCOM_INSERT_SELECT ) {
thd->last_sql_command = lex->sql_command;
} else if (lex->sql_command == SQLCOM_COMMIT) {
thd->last_sql_command = SQLCOM_SELECT;
}
And in function thd_kill, if found the transaction only contain SELECT, it will not be killed.
while ((tmp=it++))
{
if (tmp->command == COM_DAEMON || tmp->last_sql_command == SQLCOM_SELECT ) continue;
if (tmp->thread_id == id)
{ pthread_mutex_lock(&tmp->LOCK_thd_data);
break;
}
}
I think this function will not kill transaction that only have query "SELECT", because "SELECT" command needn't lock. DELTE/INSERT" and not type "COMMT" a long time, it must be killed.
Only if the transaction contain "UPDATE/
I modified source code on our system.
I add "enum enum_sql_command last_sql_command;" on class THD, it record the last Query's command type, default value is "SQLCOM_SELECT". I init it on THD::THD, add "last_sql_command = SQLCOM_SELECT;".
And I update this value on function mysql_execute_ command, only if the query is "UPDATE/ DELTE/INSERT" , I update the last_sql_command. Then if the last_sql_command is not select, I can consider the thread is contain MODIFY query. sql_command == SQLCOM_INSERT sql_command == SQLCOM_DELETE sql_command == SQLCOM_ INSERT_ SELECT ) { >last_sql_ command = lex->sql_command; >last_sql_ command = SQLCOM_SELECT;
if (lex->sql_command == SQLCOM_UPDATE
|| thd->last_
|| thd->last_
|| thd->last_
thd-
} else if (lex->sql_command == SQLCOM_COMMIT) {
thd-
}
And in function thd_kill, if found the transaction only contain SELECT, it will not be killed.
while ((tmp=it++)) sql_command == SQLCOM_SELECT )
continue;
pthread_ mutex_lock( &tmp->LOCK_ thd_data) ;
{
if (tmp->command == COM_DAEMON || tmp->last_
if (tmp->thread_id == id)
{
break;
}
}