• Luis Soares's avatar
    BUG#50620: Adding an index to a table prevents slave from logging · d0c74a61
    Luis Soares authored
    into slow log
          
    While processing a statement, down the mysql_parse execution
    stack, the thd->enable_slow_log can be assigned to
    opt_log_slow_admin_statements, depending whether one is executing
    administrative statements, such as ALTER TABLE, OPTIMIZE,
    ANALYZE, etc, or not. This can have an impact on slow logging for
    statements that are executed after an administrative statement
    execution is completed.
          
    When executing statements directly from the user this is fine
    because, the thd->enable_slow_log is reset right at the beginning
    of the dispatch_command function, ie, everytime a new statement
    is set is set to execute.
          
    On the other hand, for slave SQL thread (sql_thd) the story is a
    bit different. When in SBR the sql_thd applies statements by
    calling mysql_parse. Right after, it calls log_slow_statement
    function to log them if they take too long. Calling mysql_parse
    directly is fine, but also means that dispatch_command function
    is bypassed. As a consequence, thd->enable_slow_log does not get
    a chance to be reset before the next statement to be executed by
    the sql_thd. If the statement just executed by the sql_thd was an
    administrative statement and logging of admin statements was
    disabled, this means that sql_thd->enable_slow_log will be set to
    0 (disabled) from that moment on. End result: sql_thd stops
    logging slow statements.
          
    We fix this by resetting the value of sql_thd->enable_slow_log to
    the value of opt_log_slow_slave_statements right after
    log_slow_stement is called by the sql_thd.
    d0c74a61
rpl_slow_query_log.result 2.79 KB