| 2540 | */ |
| 2541 | |
| 2542 | void log_slow_statement(THD *thd) |
| 2543 | { |
| 2544 | DBUG_ENTER("log_slow_statement"); |
| 2545 | |
| 2546 | /* |
| 2547 | The following should never be true with our current code base, |
| 2548 | but better to keep this here so we don't accidently try to log a |
| 2549 | statement in a trigger or stored function |
| 2550 | */ |
| 2551 | if (unlikely(thd->in_sub_stmt)) |
| 2552 | goto end; // Don't set time for sub stmt |
| 2553 | /* |
| 2554 | Skip both long_query_count increment and logging if the current |
| 2555 | statement forces slow log suppression (e.g. an SP statement). |
| 2556 | |
| 2557 | Note, we don't check for global_system_variables.sql_log_slow here. |
| 2558 | According to the manual, the "Slow_queries" status variable does not require |
| 2559 | sql_log_slow to be ON. So even if sql_log_slow is OFF, we still need to |
| 2560 | continue and increment long_query_count (and skip only logging, see below): |
| 2561 | */ |
| 2562 | if (!thd->enable_slow_log) |
| 2563 | goto end; // E.g. SP statement |
| 2564 | |
| 2565 | DBUG_EXECUTE_IF("simulate_slow_query", { |
| 2566 | if (thd->get_command() == COM_QUERY || |
| 2567 | thd->get_command() == COM_STMT_EXECUTE) |
| 2568 | thd->server_status|= SERVER_QUERY_WAS_SLOW; |
| 2569 | }); |
| 2570 | |
| 2571 | if ((thd->server_status & |
| 2572 | (SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED)) && |
| 2573 | !(thd->query_plan_flags & QPLAN_STATUS) && |
| 2574 | (thd->variables.log_slow_filter & QPLAN_NOT_USING_INDEX)) |
| 2575 | { |
| 2576 | thd->query_plan_flags|= QPLAN_NOT_USING_INDEX; |
| 2577 | /* We are always logging no index queries if enabled in filter */ |
| 2578 | thd->server_status|= SERVER_QUERY_WAS_SLOW; |
| 2579 | } |
| 2580 | |
| 2581 | if ((thd->server_status & SERVER_QUERY_WAS_SLOW) && |
| 2582 | (thd->get_examined_row_count() >= thd->variables.min_examined_row_limit || |
| 2583 | thd->log_slow_always_query_time())) |
| 2584 | { |
| 2585 | thd->status_var.long_query_count++; |
| 2586 | |
| 2587 | /* |
| 2588 | until log_slow_disabled_statements=admin is removed, it |
| 2589 | duplicates slow_log_filter=admin |
| 2590 | */ |
| 2591 | if ((thd->query_plan_flags & QPLAN_ADMIN) && |
| 2592 | (thd->variables.log_slow_disabled_statements & LOG_SLOW_DISABLE_ADMIN)) |
| 2593 | goto end; |
| 2594 | |
| 2595 | if (!global_system_variables.sql_log_slow || !thd->variables.sql_log_slow) |
| 2596 | goto end; |
| 2597 | |
| 2598 | /* |
| 2599 | If rate limiting of slow log writes is enabled, decide whether to log |
no test coverage detected