Comment 7 for bug 871722

Revision history for this message
Lixun Peng (P.Linux) (plx) wrote :

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;
        }
    }